Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
from groq import Groq
|
| 4 |
|
| 5 |
-
# ✅ Get API key from Hugging Face Secrets
|
| 6 |
client = Groq(api_key=os.environ["Groq_api"])
|
| 7 |
|
| 8 |
def chatbot(user_input, history):
|
|
@@ -11,19 +10,22 @@ def chatbot(user_input, history):
|
|
| 11 |
|
| 12 |
messages = []
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
for
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
messages.append({"role": "user", "content": user_input})
|
| 21 |
|
| 22 |
try:
|
| 23 |
response = client.chat.completions.create(
|
| 24 |
-
model="llama3-8b-8192",
|
| 25 |
messages=messages
|
| 26 |
)
|
|
|
|
| 27 |
bot_reply = response.choices[0].message.content
|
| 28 |
|
| 29 |
except Exception as e:
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from groq import Groq
|
| 4 |
|
|
|
|
| 5 |
client = Groq(api_key=os.environ["Groq_api"])
|
| 6 |
|
| 7 |
def chatbot(user_input, history):
|
|
|
|
| 10 |
|
| 11 |
messages = []
|
| 12 |
|
| 13 |
+
# ✅ FIX: Ensure proper unpacking
|
| 14 |
+
for chat in history:
|
| 15 |
+
if len(chat) == 2:
|
| 16 |
+
human, bot = chat
|
| 17 |
+
messages.append({"role": "user", "content": str(human)})
|
| 18 |
+
messages.append({"role": "assistant", "content": str(bot)})
|
| 19 |
|
| 20 |
+
# current message
|
| 21 |
+
messages.append({"role": "user", "content": str(user_input)})
|
| 22 |
|
| 23 |
try:
|
| 24 |
response = client.chat.completions.create(
|
| 25 |
+
model="llama3-8b-8192",
|
| 26 |
messages=messages
|
| 27 |
)
|
| 28 |
+
|
| 29 |
bot_reply = response.choices[0].message.content
|
| 30 |
|
| 31 |
except Exception as e:
|