Technocoloredgeek commited on
Commit
4a4fa74
·
verified ·
1 Parent(s): eb36c0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
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
- # Set up API key
15
- os.environ["OPENAI_API_KEY"] = "your-api-key-here" # You'll need to handle this securely
 
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
- async for chunk in pipeline.arun_pipeline(message.content):
89
- await msg.stream_token(chunk)
 
 
 
 
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()