ZENLLC commited on
Commit
af14ecd
·
verified ·
1 Parent(s): 03ff466

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -2,6 +2,10 @@ import gradio as gr
2
  from openai import OpenAI
3
 
4
  def respond(message, chat_history, api_key):
 
 
 
 
5
  # Gatekeeper: Halt execution if no compute resource is provided
6
  if not api_key:
7
  chat_history.append({"role": "user", "content": message})
@@ -19,7 +23,7 @@ def respond(message, chat_history, api_key):
19
  }
20
  ]
21
 
22
- # Because Gradio 6.0 uses the exact same format as OpenAI, we can just extend the list
23
  openai_messages.extend(chat_history)
24
  openai_messages.append({"role": "user", "content": message})
25
 
@@ -32,7 +36,7 @@ def respond(message, chat_history, api_key):
32
 
33
  bot_reply = response.choices[0].message.content
34
 
35
- # Append the new interaction using the correct dictionary format
36
  chat_history.append({"role": "user", "content": message})
37
  chat_history.append({"role": "assistant", "content": bot_reply})
38
 
@@ -71,8 +75,8 @@ with gr.Blocks() as demo:
71
  info="Injected dynamically at runtime. Keys are not stored or logged."
72
  )
73
 
74
- # 2. Main Chat Display - Explicitly set to 'messages' format to prevent errors
75
- chatbot = gr.Chatbot(height=450, label="Intelligence Feed", type="messages")
76
 
77
  # 3. User Input Area
78
  with gr.Row():
 
2
  from openai import OpenAI
3
 
4
  def respond(message, chat_history, api_key):
5
+ # Failsafe to ensure history initializes as an empty list
6
+ if chat_history is None:
7
+ chat_history = []
8
+
9
  # Gatekeeper: Halt execution if no compute resource is provided
10
  if not api_key:
11
  chat_history.append({"role": "user", "content": message})
 
23
  }
24
  ]
25
 
26
+ # Pass the direct Gradio history into the OpenAI pipeline
27
  openai_messages.extend(chat_history)
28
  openai_messages.append({"role": "user", "content": message})
29
 
 
36
 
37
  bot_reply = response.choices[0].message.content
38
 
39
+ # Append the new interaction using the native dictionary format
40
  chat_history.append({"role": "user", "content": message})
41
  chat_history.append({"role": "assistant", "content": bot_reply})
42
 
 
75
  info="Injected dynamically at runtime. Keys are not stored or logged."
76
  )
77
 
78
+ # 2. Main Chat Display - Removed the 'type' parameter as it is now strictly implicit
79
+ chatbot = gr.Chatbot(height=450, label="Intelligence Feed")
80
 
81
  # 3. User Input Area
82
  with gr.Row():