fabianzarncke commited on
Commit
1e97878
·
verified ·
1 Parent(s): 5ac69fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -114,7 +114,7 @@ def insideRespond(
114
 
115
  def respond(
116
  message,
117
- history: list[tuple[str, str]],
118
  system_message,
119
  max_tokens,
120
  temperature,
@@ -123,14 +123,14 @@ def respond(
123
  # Preprocess the user input
124
  message = preprocess_user_input(message)
125
 
 
126
  messages = [{"role": "system", "content": system_message}]
127
 
128
- for val in history:
129
- if val[0]:
130
- messages.append({"role": "user", "content": val[0]})
131
- if val[1]:
132
- messages.append({"role": "assistant", "content": val[1]})
133
 
 
134
  messages.append({"role": "user", "content": message})
135
 
136
  response = ""
@@ -143,16 +143,17 @@ def respond(
143
  top_p=top_p,
144
  ):
145
  token = message.choices[0].delta.content
146
-
147
  response += token
148
  yield response
149
 
150
 
 
151
  """
152
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
153
  """
154
  demo = gr.ChatInterface(
155
  respond,
 
156
  additional_inputs=[
157
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
158
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
 
114
 
115
  def respond(
116
  message,
117
+ history: list[dict[str, str]],
118
  system_message,
119
  max_tokens,
120
  temperature,
 
123
  # Preprocess the user input
124
  message = preprocess_user_input(message)
125
 
126
+ # Start the conversation with a system message
127
  messages = [{"role": "system", "content": system_message}]
128
 
129
+ # Add conversation history
130
+ if history:
131
+ messages.extend(history)
 
 
132
 
133
+ # Add the new user message
134
  messages.append({"role": "user", "content": message})
135
 
136
  response = ""
 
143
  top_p=top_p,
144
  ):
145
  token = message.choices[0].delta.content
 
146
  response += token
147
  yield response
148
 
149
 
150
+
151
  """
152
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
153
  """
154
  demo = gr.ChatInterface(
155
  respond,
156
+ type="messages", # Specify the new message format
157
  additional_inputs=[
158
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
159
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),