Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -1032,6 +1032,53 @@ def respond(url, history, system_message, max_tokens, temperature, top_p):
|
|
1032 |
|
1033 |
return history
|
1034 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1035 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น์ค") as iface:
|
1036 |
with gr.Tabs():
|
1037 |
# ๊ตญ๊ฐ๋ณ ํญ
|
|
|
1032 |
|
1033 |
return history
|
1034 |
|
1035 |
+
|
1036 |
+
def continue_writing(history, system_message, max_tokens, temperature, top_p):
|
1037 |
+
if not history:
|
1038 |
+
return history
|
1039 |
+
|
1040 |
+
last_response = history[-1][1] if history else ""
|
1041 |
+
continue_prompt = f"""์ด์ ๋ด์ฉ์ ์ด์ด์ ๊ณ์ ์์ฑํด์ฃผ์ธ์.
|
1042 |
+
๋ง์ง๋ง ์๋ต: {last_response}
|
1043 |
+
|
1044 |
+
์ถ๊ฐ ์ง์นจ:
|
1045 |
+
1. ์ด์ ๋ด์ฉ์ ๋งฅ๋ฝ์ ์ ์งํ๋ฉฐ ์์ฐ์ค๋ฝ๊ฒ ์ด์ด์ ์์ฑ
|
1046 |
+
2. ์๋ก์ด ์ ๋ณด๋ ์์ธ ์ค๋ช
์ ์ถ๊ฐ
|
1047 |
+
3. ํ์ํ ๊ฒฝ์ฐ ๋ณด์ถฉ ์ค๋ช
์ด๋ ๋ถ์ ์ ๊ณต
|
1048 |
+
4. ๊ธฐ์ฌ ํ์๊ณผ ์คํ์ผ ์ ์ง
|
1049 |
+
5. ํ์ํ ๊ฒฝ์ฐ ์ถ๊ฐ์ ์ธ ์ด๋ฏธ์ง ํ๋กฌํํธ ์์ฑ
|
1050 |
+
"""
|
1051 |
+
|
1052 |
+
messages = [
|
1053 |
+
{"role": "system", "content": system_message},
|
1054 |
+
{"role": "assistant", "content": last_response},
|
1055 |
+
{"role": "user", "content": continue_prompt}
|
1056 |
+
]
|
1057 |
+
|
1058 |
+
try:
|
1059 |
+
full_response = ""
|
1060 |
+
for message in client.chat.completions.create(
|
1061 |
+
model="CohereForAI/c4ai-command-r-plus-08-2024",
|
1062 |
+
max_tokens=max_tokens,
|
1063 |
+
stream=True,
|
1064 |
+
temperature=temperature,
|
1065 |
+
top_p=top_p,
|
1066 |
+
messages=messages,
|
1067 |
+
):
|
1068 |
+
if hasattr(message.choices[0].delta, 'content'):
|
1069 |
+
token = message.choices[0].delta.content
|
1070 |
+
if token:
|
1071 |
+
full_response += token
|
1072 |
+
history.append(("๊ณ์ ์์ฑ", full_response))
|
1073 |
+
yield history
|
1074 |
+
|
1075 |
+
except Exception as e:
|
1076 |
+
error_message = f"๊ณ์ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
1077 |
+
history.append(("์ค๋ฅ", error_message))
|
1078 |
+
yield history
|
1079 |
+
|
1080 |
+
return history
|
1081 |
+
|
1082 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น์ค") as iface:
|
1083 |
with gr.Tabs():
|
1084 |
# ๊ตญ๊ฐ๋ณ ํญ
|