Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,7 +29,7 @@ def respond(
|
|
29 |
try:
|
30 |
client = get_client(model_name)
|
31 |
except ValueError as e:
|
32 |
-
return str(e)
|
33 |
|
34 |
messages = [{"role": "system", "content": system_message}]
|
35 |
|
@@ -39,21 +39,22 @@ def respond(
|
|
39 |
|
40 |
messages.append({"role": "user", "content": message})
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
max_tokens=max_tokens,
|
47 |
-
stream=True,
|
48 |
-
temperature=temperature,
|
49 |
-
top_p=top_p,
|
50 |
-
):
|
51 |
-
token = message.choices[0].delta.content
|
52 |
-
response += token
|
53 |
-
yield response
|
54 |
|
55 |
def clear_conversation():
|
56 |
-
return
|
57 |
|
58 |
with gr.Blocks() as demo:
|
59 |
gr.Markdown("# Advanced AI Chatbot")
|
|
|
29 |
try:
|
30 |
client = get_client(model_name)
|
31 |
except ValueError as e:
|
32 |
+
return chat_history + [[message, str(e)]]
|
33 |
|
34 |
messages = [{"role": "system", "content": system_message}]
|
35 |
|
|
|
39 |
|
40 |
messages.append({"role": "user", "content": message})
|
41 |
|
42 |
+
try:
|
43 |
+
response = client.chat_completion(
|
44 |
+
messages,
|
45 |
+
max_tokens=max_tokens,
|
46 |
+
temperature=temperature,
|
47 |
+
top_p=top_p,
|
48 |
+
)
|
49 |
+
assistant_message = response.choices[0].message.content
|
50 |
+
except Exception as e:
|
51 |
+
assistant_message = f"An error occurred: {str(e)}"
|
52 |
|
53 |
+
chat_history.append((message, assistant_message))
|
54 |
+
return chat_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
def clear_conversation():
|
57 |
+
return []
|
58 |
|
59 |
with gr.Blocks() as demo:
|
60 |
gr.Markdown("# Advanced AI Chatbot")
|