Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,20 +40,25 @@ async def main(message: cl.Message):
|
|
| 40 |
return
|
| 41 |
|
| 42 |
# Merge PDF context if exists
|
|
|
|
| 43 |
if pdf_context:
|
| 44 |
-
|
| 45 |
|
| 46 |
try:
|
| 47 |
response = groq_client.chat.completions.create(
|
| 48 |
model="llama3-8b-8192",
|
| 49 |
messages=[
|
| 50 |
{"role": "system", "content": "You are a helpful assistant."},
|
| 51 |
-
{"role": "user", "content":
|
| 52 |
]
|
| 53 |
)
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
await cl.Message(content=answer).send()
|
| 58 |
|
| 59 |
except Exception as e:
|
|
|
|
| 40 |
return
|
| 41 |
|
| 42 |
# Merge PDF context if exists
|
| 43 |
+
full_prompt = prompt
|
| 44 |
if pdf_context:
|
| 45 |
+
full_prompt = f"Use the following PDF content to answer the question:\n\n{pdf_context}\n\nQuestion: {prompt}"
|
| 46 |
|
| 47 |
try:
|
| 48 |
response = groq_client.chat.completions.create(
|
| 49 |
model="llama3-8b-8192",
|
| 50 |
messages=[
|
| 51 |
{"role": "system", "content": "You are a helpful assistant."},
|
| 52 |
+
{"role": "user", "content": full_prompt}
|
| 53 |
]
|
| 54 |
)
|
| 55 |
|
| 56 |
+
# Check if response has content
|
| 57 |
+
if response.choices and hasattr(response.choices[0], "message"):
|
| 58 |
+
answer = response.choices[0].message.get("content", "🤔 No content in response.")
|
| 59 |
+
else:
|
| 60 |
+
answer = "🤔 No response received from model."
|
| 61 |
+
|
| 62 |
await cl.Message(content=answer).send()
|
| 63 |
|
| 64 |
except Exception as e:
|