Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,6 +84,48 @@ def respond(
|
|
| 84 |
chat_history.append((message, error_message))
|
| 85 |
yield chat_history
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
def clear_conversation():
|
| 88 |
return []
|
| 89 |
|
|
@@ -149,13 +191,13 @@ with gr.Blocks() as demo:
|
|
| 149 |
cohere_clear_button = gr.Button("대화 내역 지우기")
|
| 150 |
|
| 151 |
cohere_msg.submit(
|
| 152 |
-
|
| 153 |
-
[cohere_msg, cohere_chatbot,
|
| 154 |
cohere_chatbot
|
| 155 |
)
|
| 156 |
cohere_submit_button.click(
|
| 157 |
-
|
| 158 |
-
[cohere_msg, cohere_chatbot,
|
| 159 |
cohere_chatbot
|
| 160 |
)
|
| 161 |
cohere_clear_button.click(clear_conversation, outputs=cohere_chatbot, queue=False)
|
|
|
|
| 84 |
chat_history.append((message, error_message))
|
| 85 |
yield chat_history
|
| 86 |
|
| 87 |
+
def cohere_respond(
|
| 88 |
+
message,
|
| 89 |
+
chat_history,
|
| 90 |
+
system_message,
|
| 91 |
+
max_tokens,
|
| 92 |
+
temperature,
|
| 93 |
+
top_p,
|
| 94 |
+
):
|
| 95 |
+
model_name = "Cohere Command R+"
|
| 96 |
+
try:
|
| 97 |
+
client = get_client(model_name)
|
| 98 |
+
except ValueError as e:
|
| 99 |
+
chat_history.append((message, str(e)))
|
| 100 |
+
return chat_history
|
| 101 |
+
|
| 102 |
+
messages = [{"role": "system", "content": system_message}]
|
| 103 |
+
for human, assistant in chat_history:
|
| 104 |
+
if human:
|
| 105 |
+
messages.append({"role": "user", "content": human})
|
| 106 |
+
if assistant:
|
| 107 |
+
messages.append({"role": "assistant", "content": assistant})
|
| 108 |
+
|
| 109 |
+
messages.append({"role": "user", "content": message})
|
| 110 |
+
|
| 111 |
+
response = ""
|
| 112 |
+
|
| 113 |
+
try:
|
| 114 |
+
# Cohere Command R+ 모델을 위한 비스트리밍 처리
|
| 115 |
+
response_full = client.chat_completion(
|
| 116 |
+
messages,
|
| 117 |
+
max_tokens=max_tokens,
|
| 118 |
+
temperature=temperature,
|
| 119 |
+
top_p=top_p,
|
| 120 |
+
)
|
| 121 |
+
assistant_message = response_full.choices[0].message.content
|
| 122 |
+
chat_history.append((message, assistant_message))
|
| 123 |
+
return chat_history
|
| 124 |
+
except Exception as e:
|
| 125 |
+
error_message = f"오류가 발생했습니다: {str(e)}"
|
| 126 |
+
chat_history.append((message, error_message))
|
| 127 |
+
return chat_history
|
| 128 |
+
|
| 129 |
def clear_conversation():
|
| 130 |
return []
|
| 131 |
|
|
|
|
| 191 |
cohere_clear_button = gr.Button("대화 내역 지우기")
|
| 192 |
|
| 193 |
cohere_msg.submit(
|
| 194 |
+
cohere_respond,
|
| 195 |
+
[cohere_msg, cohere_chatbot, cohere_system_message, cohere_max_tokens, cohere_temperature, cohere_top_p],
|
| 196 |
cohere_chatbot
|
| 197 |
)
|
| 198 |
cohere_submit_button.click(
|
| 199 |
+
cohere_respond,
|
| 200 |
+
[cohere_msg, cohere_chatbot, cohere_system_message, cohere_max_tokens, cohere_temperature, cohere_top_p],
|
| 201 |
cohere_chatbot
|
| 202 |
)
|
| 203 |
cohere_clear_button.click(clear_conversation, outputs=cohere_chatbot, queue=False)
|