Turbiling commited on
Commit
c3f1a57
·
verified ·
1 Parent(s): 9f8e5a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
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
- prompt = f"Use the following PDF content to answer the question:\n\n{pdf_context}\n\nQuestion: {prompt}"
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": prompt}
52
  ]
53
  )
54
 
55
- # Safely extract response
56
- answer = response.choices[0].message.content if response.choices else "🤔 No response from model."
 
 
 
 
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: