ambrosfitz commited on
Commit
4723a07
·
verified ·
1 Parent(s): 23c61db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -12,6 +12,9 @@ client = OpenAI(
12
  def runpod_chat(question, history=None):
13
  if history is None:
14
  history = [] # Ensure history starts as an empty list if none is provided
 
 
 
15
  history.append({"role": "user", "content": question})
16
 
17
  response_stream = client.chat.completions.create(
@@ -23,7 +26,7 @@ def runpod_chat(question, history=None):
23
  )
24
 
25
  # Stream the response and accumulate full response before displaying
26
- full_response = "RunPod: "
27
  for message in response_stream:
28
  part = message.choices[0].delta.content if message.choices[0].delta.content is not None else ""
29
  full_response += part
@@ -36,16 +39,10 @@ def runpod_chat(question, history=None):
36
  # Set up the Gradio interface
37
  iface = gr.Interface(
38
  fn=runpod_chat,
39
- inputs=[
40
- gr.Textbox(label="Enter your question:"),
41
- gr.State() # Remove default parameter
42
- ],
43
- outputs=[
44
- gr.Textbox(label="Responses"),
45
- gr.State()
46
- ],
47
- title="RunPod Chat",
48
- description="This app interfaces with RunPod's API to provide responses to your queries."
49
  )
50
 
51
  iface.launch()
 
12
  def runpod_chat(question, history=None):
13
  if history is None:
14
  history = [] # Ensure history starts as an empty list if none is provided
15
+ # Add the role description at the beginning of the session
16
+ if not history:
17
+ history.append({"role": "system", "content": "You are a history assistant, that provides the best possible answers to any historical questions asked about American History. Be helpful and specific, providing any detailed nuance needed to have a full understanding of the question."})
18
  history.append({"role": "user", "content": question})
19
 
20
  response_stream = client.chat.completions.create(
 
26
  )
27
 
28
  # Stream the response and accumulate full response before displaying
29
+ full_response = "HistoryBot: "
30
  for message in response_stream:
31
  part = message.choices[0].delta.content if message.choices[0].delta.content is not None else ""
32
  full_response += part
 
39
  # Set up the Gradio interface
40
  iface = gr.Interface(
41
  fn=runpod_chat,
42
+ inputs=[gr.State(), gr.Textbox(label="Enter your question:")],
43
+ outputs=[gr.Textbox(label="Responses"), gr.State()],
44
+ title="HistoryBot Chat",
45
+ description="Interact with HistoryBot, a specialized assistant for American History. Ask any historical questions to get detailed and nuanced answers."
 
 
 
 
 
 
46
  )
47
 
48
  iface.launch()