Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ from openai import OpenAI, OpenAIError
|
|
4 |
|
5 |
|
6 |
|
7 |
-
def respond(message, history, system_message
|
8 |
messages = [{"role": "system", "content": system_message}]
|
9 |
|
10 |
for val in history:
|
@@ -19,23 +19,25 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
19 |
base_url="https://api.moonshot.cn/v1",
|
20 |
)
|
21 |
try:
|
22 |
-
response = client.
|
23 |
model="moonshot-v1-128k",
|
24 |
messages=messages,
|
25 |
-
|
26 |
-
|
27 |
-
top_p=top_p,
|
28 |
-
stream=True
|
29 |
)
|
30 |
-
|
31 |
final_response = ""
|
32 |
-
for
|
33 |
-
|
|
|
|
|
|
|
34 |
|
35 |
return final_response
|
36 |
except OpenAIError as e:
|
37 |
print(f"An error occurred while communicating with OpenAI: {e}")
|
38 |
-
return None
|
|
|
39 |
|
40 |
demo = gr.ChatInterface(
|
41 |
respond,
|
|
|
4 |
|
5 |
|
6 |
|
7 |
+
def respond(message, history, system_message):
|
8 |
messages = [{"role": "system", "content": system_message}]
|
9 |
|
10 |
for val in history:
|
|
|
19 |
base_url="https://api.moonshot.cn/v1",
|
20 |
)
|
21 |
try:
|
22 |
+
response = client.chat.completions.create(
|
23 |
model="moonshot-v1-128k",
|
24 |
messages=messages,
|
25 |
+
temperature=0.3
|
26 |
+
|
|
|
|
|
27 |
)
|
28 |
+
|
29 |
final_response = ""
|
30 |
+
for part in response.choices[0].message:
|
31 |
+
#print(part[0])
|
32 |
+
if part[0] == 'content':
|
33 |
+
final_response += part[1]
|
34 |
+
#final_response += message.content
|
35 |
|
36 |
return final_response
|
37 |
except OpenAIError as e:
|
38 |
print(f"An error occurred while communicating with OpenAI: {e}")
|
39 |
+
return None
|
40 |
+
|
41 |
|
42 |
demo = gr.ChatInterface(
|
43 |
respond,
|