akhaliq HF staff commited on
Commit
a54087d
·
verified ·
1 Parent(s): 092a2ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -11,9 +11,9 @@ def respond(user_message, history, chat_state):
11
  if chat_state is None:
12
  # Start a new chat with an initial greeting
13
  chat_state = model.start_chat(
14
- history=[
15
- {"author": "user", "parts": ["Hello"]},
16
- {"author": "assistant", "parts": ["Great to meet you. What would you like to know?"]},
17
  ]
18
  )
19
  # Initialize history if it's empty
@@ -21,11 +21,12 @@ def respond(user_message, history, chat_state):
21
  history = [["Hello", "Great to meet you. What would you like to know?"]]
22
  else:
23
  # Continue the conversation
24
- chat_state.messages.append({"author": "user", "parts": [user_message]})
25
- # Generate a response
26
- response = chat_state.generate_message()
27
- # Append the user's message and model's response to the history
28
- history.append([user_message, response.text])
 
29
  return history, chat_state, ''
30
 
31
  with gr.Blocks() as demo:
 
11
  if chat_state is None:
12
  # Start a new chat with an initial greeting
13
  chat_state = model.start_chat(
14
+ messages=[
15
+ {"author": "user", "content": "Hello"},
16
+ {"author": "assistant", "content": "Great to meet you. What would you like to know?"},
17
  ]
18
  )
19
  # Initialize history if it's empty
 
21
  history = [["Hello", "Great to meet you. What would you like to know?"]]
22
  else:
23
  # Continue the conversation
24
+ pass # No need to manually append messages; send_message handles it
25
+
26
+ # Send the user's message to the model
27
+ response = chat_state.send_message(user_message)
28
+ # Append the user's message and model's response to the history
29
+ history.append([user_message, response.text])
30
  return history, chat_state, ''
31
 
32
  with gr.Blocks() as demo: