Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,8 +11,9 @@ from langchain.schema import SystemMessage, HumanMessage
|
|
| 11 |
from PyPDF2 import PdfReader
|
| 12 |
import chainlit as cl
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
os.
|
|
|
|
| 16 |
|
| 17 |
# Set up prompts
|
| 18 |
system_template = "Use the following context to answer a user's question. If you cannot find the answer in the context, say you don't know the answer."
|
|
@@ -85,7 +86,11 @@ async def main(message: cl.Message):
|
|
| 85 |
return
|
| 86 |
|
| 87 |
msg = cl.Message(content="")
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
await msg.send()
|
|
|
|
| 11 |
from PyPDF2 import PdfReader
|
| 12 |
import chainlit as cl
|
| 13 |
|
| 14 |
+
# Check if the API key is set
|
| 15 |
+
if not os.getenv("OPENAI_API_KEY"):
|
| 16 |
+
raise ValueError("OPENAI_API_KEY environment variable is not set")
|
| 17 |
|
| 18 |
# Set up prompts
|
| 19 |
system_template = "Use the following context to answer a user's question. If you cannot find the answer in the context, say you don't know the answer."
|
|
|
|
| 86 |
return
|
| 87 |
|
| 88 |
msg = cl.Message(content="")
|
| 89 |
+
try:
|
| 90 |
+
async for chunk in pipeline.arun_pipeline(message.content):
|
| 91 |
+
await msg.stream_token(chunk)
|
| 92 |
+
except Exception as e:
|
| 93 |
+
await cl.Message(content=f"An error occurred: {str(e)}").send()
|
| 94 |
+
return
|
| 95 |
|
| 96 |
await msg.send()
|