Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ def respond(
|
|
27 |
system_message,
|
28 |
):
|
29 |
try:
|
30 |
-
client = get_client(model_name)
|
31 |
except ValueError as e:
|
32 |
chat_history.append((message, str(e)))
|
33 |
return chat_history
|
@@ -39,22 +39,35 @@ def respond(
|
|
39 |
messages.append({"role": "user", "content": message})
|
40 |
|
41 |
try:
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
except Exception as e:
|
59 |
error_message = f"An error occurred: {str(e)}"
|
60 |
chat_history.append((message, error_message))
|
|
|
27 |
system_message,
|
28 |
):
|
29 |
try:
|
30 |
+
client = get_client(model_name)
|
31 |
except ValueError as e:
|
32 |
chat_history.append((message, str(e)))
|
33 |
return chat_history
|
|
|
39 |
messages.append({"role": "user", "content": message})
|
40 |
|
41 |
try:
|
42 |
+
if "Cohere" in model_name:
|
43 |
+
# Cohere 모델을 위한 비스트리밍 처리
|
44 |
+
response = client.chat_completion(
|
45 |
+
messages,
|
46 |
+
max_tokens=max_tokens,
|
47 |
+
temperature=temperature,
|
48 |
+
top_p=top_p,
|
49 |
+
)
|
50 |
+
assistant_message = response.choices[0].message.content
|
51 |
+
chat_history.append((message, assistant_message))
|
52 |
+
yield chat_history
|
53 |
+
else:
|
54 |
+
# 다른 모델들을 위한 스트리밍 처리
|
55 |
+
stream = client.chat_completion(
|
56 |
+
messages,
|
57 |
+
max_tokens=max_tokens,
|
58 |
+
temperature=temperature,
|
59 |
+
top_p=top_p,
|
60 |
+
stream=True,
|
61 |
+
)
|
62 |
+
partial_message = ""
|
63 |
+
for response in stream:
|
64 |
+
if response.choices[0].delta.content is not None:
|
65 |
+
partial_message += response.choices[0].delta.content
|
66 |
+
if len(chat_history) > 0 and chat_history[-1][0] == message:
|
67 |
+
chat_history[-1] = (message, partial_message)
|
68 |
+
else:
|
69 |
+
chat_history.append((message, partial_message))
|
70 |
+
yield chat_history
|
71 |
except Exception as e:
|
72 |
error_message = f"An error occurred: {str(e)}"
|
73 |
chat_history.append((message, error_message))
|