Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,12 +30,12 @@ def chat_with_groq(user_message):
|
|
| 30 |
temperature=1,
|
| 31 |
max_tokens=1024,
|
| 32 |
top_p=1,
|
| 33 |
-
stream=
|
| 34 |
)
|
| 35 |
|
| 36 |
response = ""
|
| 37 |
for chunk in completion:
|
| 38 |
-
response += chunk.choices[0].delta.content
|
| 39 |
return response
|
| 40 |
|
| 41 |
except Exception as e:
|
|
@@ -47,14 +47,14 @@ def gradio_chatbot():
|
|
| 47 |
|
| 48 |
def respond(message, history):
|
| 49 |
response = chat_with_groq(message)
|
|
|
|
| 50 |
history.append((message, response))
|
| 51 |
return history, history
|
| 52 |
|
| 53 |
with gr.Blocks() as demo:
|
| 54 |
with gr.Row():
|
| 55 |
gr.Markdown("### 成語遊戲 Chatbot")
|
| 56 |
-
|
| 57 |
-
chatbot = gr.Chatbot()
|
| 58 |
with gr.Row():
|
| 59 |
user_input = gr.Textbox(placeholder="輸入你的訊息...")
|
| 60 |
submit_button = gr.Button("送出")
|
|
|
|
| 30 |
temperature=1,
|
| 31 |
max_tokens=1024,
|
| 32 |
top_p=1,
|
| 33 |
+
stream=True
|
| 34 |
)
|
| 35 |
|
| 36 |
response = ""
|
| 37 |
for chunk in completion:
|
| 38 |
+
response += chunk.get('choices', [{}])[0].get('delta', {}).get('content', "")
|
| 39 |
return response
|
| 40 |
|
| 41 |
except Exception as e:
|
|
|
|
| 47 |
|
| 48 |
def respond(message, history):
|
| 49 |
response = chat_with_groq(message)
|
| 50 |
+
history = history or []
|
| 51 |
history.append((message, response))
|
| 52 |
return history, history
|
| 53 |
|
| 54 |
with gr.Blocks() as demo:
|
| 55 |
with gr.Row():
|
| 56 |
gr.Markdown("### 成語遊戲 Chatbot")
|
| 57 |
+
chatbot = gr.Chatbot()
|
|
|
|
| 58 |
with gr.Row():
|
| 59 |
user_input = gr.Textbox(placeholder="輸入你的訊息...")
|
| 60 |
submit_button = gr.Button("送出")
|