Eric Michael Martinez commited on
Commit
21a7ced
1 Parent(s): 7483975

remove history_state, add gpt-3.5-turbo-16k, add temperature

Browse files
Files changed (1) hide show
  1. app/app.py +24 -19
app/app.py CHANGED
@@ -118,10 +118,14 @@ def generate_image(prompt):
118
 
119
 
120
  # Define a function to handle the chat interaction with the AI model
121
- def chat(model, system_message, message, chatbot_messages, history_state):
122
- # Initialize chatbot_messages and history_state if they are not provided
123
  chatbot_messages = chatbot_messages or []
124
- history_state = history_state or []
 
 
 
 
125
 
126
  # Try to get the AI's reply using the get_ai_reply function
127
  try:
@@ -129,7 +133,8 @@ def chat(model, system_message, message, chatbot_messages, history_state):
129
  message,
130
  model=model,
131
  system_message=system_message,
132
- message_history=history_state,
 
133
  )
134
  except Exception as e:
135
  # If an error occurs, raise a Gradio error
@@ -138,12 +143,8 @@ def chat(model, system_message, message, chatbot_messages, history_state):
138
  # Append the user's message and the AI's reply to the chatbot_messages list
139
  chatbot_messages.append((message, ai_reply))
140
 
141
- # Append the user's message and the AI's reply to the history_state list
142
- history_state.append({"role": "user", "content": message})
143
- history_state.append({"role": "assistant", "content": ai_reply})
144
-
145
- # Return None (empty out the user's message textbox), the updated chatbot_messages, and the updated history_state
146
- return None, chatbot_messages, history_state
147
 
148
 
149
  # Define a function to launch the chatbot interface using Gradio
@@ -183,16 +184,20 @@ def get_chatbot_app(additional_examples=[]):
183
  max_lines=400,
184
  )
185
  with gr.Column():
186
- # Create a dropdown to select the AI model
187
- model_selector = gr.Dropdown(
188
- ["gpt-3.5-turbo"], label="Model", value="gpt-3.5-turbo"
189
- )
 
 
 
 
 
 
190
  # Create a chatbot interface for the conversation
191
  chatbot = gr.Chatbot(label="Conversation")
192
  # Create a textbox for the user's message
193
  message = gr.Textbox(label="Message")
194
- # Create a state object to store the conversation history
195
- history_state = gr.State()
196
  # Create a button to send the user's message
197
  btn = gr.Button(value="Send")
198
 
@@ -200,19 +205,19 @@ def get_chatbot_app(additional_examples=[]):
200
  example_load_btn.click(
201
  choose_example,
202
  inputs=[example_dropdown],
203
- outputs=[system_message, message, chatbot, history_state],
204
  )
205
  # Connect the send button to the chat function
206
  btn.click(
207
  chat,
208
  inputs=[
209
  model_selector,
 
210
  system_message,
211
  message,
212
  chatbot,
213
- history_state,
214
  ],
215
- outputs=[message, chatbot, history_state],
216
  )
217
  with gr.Tab("Image Generation"):
218
  image_prompt = gr.Textbox(
 
118
 
119
 
120
  # Define a function to handle the chat interaction with the AI model
121
+ def chat(model, temperature, system_message, message, chatbot_messages):
122
+ # Initialize chatbot_messages
123
  chatbot_messages = chatbot_messages or []
124
+
125
+ history_openai_format = []
126
+ for human, assistant in chatbot_messages:
127
+ history_openai_format.append({"role": "user", "content": human})
128
+ history_openai_format.append({"role": "assistant", "content": assistant})
129
 
130
  # Try to get the AI's reply using the get_ai_reply function
131
  try:
 
133
  message,
134
  model=model,
135
  system_message=system_message,
136
+ message_history=history_openai_format,
137
+ temperature=temperature,
138
  )
139
  except Exception as e:
140
  # If an error occurs, raise a Gradio error
 
143
  # Append the user's message and the AI's reply to the chatbot_messages list
144
  chatbot_messages.append((message, ai_reply))
145
 
146
+ # Return None (empty out the user's message textbox), the updated chatbot_messages
147
+ return None, chatbot_messages
 
 
 
 
148
 
149
 
150
  # Define a function to launch the chatbot interface using Gradio
 
184
  max_lines=400,
185
  )
186
  with gr.Column():
187
+ with gr.Row():
188
+ # Create a dropdown to select the AI model
189
+ model_selector = gr.Dropdown(
190
+ ["gpt-3.5-turbo", "gpt-3.5-turbo-16k"],
191
+ label="Model",
192
+ value="gpt-3.5-turbo",
193
+ )
194
+ temperature_slider = gr.Slider(
195
+ minimum=0, maximum=2, step=0.1, value=0
196
+ )
197
  # Create a chatbot interface for the conversation
198
  chatbot = gr.Chatbot(label="Conversation")
199
  # Create a textbox for the user's message
200
  message = gr.Textbox(label="Message")
 
 
201
  # Create a button to send the user's message
202
  btn = gr.Button(value="Send")
203
 
 
205
  example_load_btn.click(
206
  choose_example,
207
  inputs=[example_dropdown],
208
+ outputs=[system_message, message, chatbot],
209
  )
210
  # Connect the send button to the chat function
211
  btn.click(
212
  chat,
213
  inputs=[
214
  model_selector,
215
+ temperature_slider,
216
  system_message,
217
  message,
218
  chatbot,
 
219
  ],
220
+ outputs=[message, chatbot],
221
  )
222
  with gr.Tab("Image Generation"):
223
  image_prompt = gr.Textbox(