Chad commited on
Commit
1965b20
·
1 Parent(s): 6ff7f58

uwdwndwfbfbewdwdwdwdwd boxdwdwdwdwdwdtupleddw

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -14,8 +14,7 @@ def respond(user_input, chat_history):
14
  chat_history = []
15
 
16
  if isinstance(chat_history, list):
17
- chat_history = [(str(msg[0]), str(msg[1])) for msg in chat_history if isinstance(msg, (list, tuple)) and len(msg) == 2]
18
-
19
 
20
  conversation = [{"role": "system", "content": (
21
  "Determine the language of the user's question and respond in the same language. "
@@ -25,9 +24,8 @@ def respond(user_input, chat_history):
25
  "(or the equivalent in French, depending on the input language). Then stop responding."
26
  )}]
27
 
28
- for user_msg, assistant_msg in chat_history:
29
- conversation.append({"role": "user", "content": user_msg})
30
- conversation.append({"role": "assistant", "content": assistant_msg})
31
 
32
  conversation.append({"role": "user", "content": user_input})
33
 
@@ -45,13 +43,14 @@ def respond(user_input, chat_history):
45
  except Exception as error:
46
  reply = f"Error: {error}"
47
 
48
- chat_history.append((user_input, reply))
49
-
 
50
  return chat_history, chat_history, ""
51
 
52
  with gr.Blocks() as demo:
53
  with gr.Row():
54
- chatbot = gr.Chatbot(height=450, type="tuples")
55
 
56
  chat = gr.ChatInterface(
57
  respond,
 
14
  chat_history = []
15
 
16
  if isinstance(chat_history, list):
17
+ chat_history = [{"role": msg["role"], "content": str(msg["content"])} for msg in chat_history if isinstance(msg, dict) and "role" in msg and "content" in msg]
 
18
 
19
  conversation = [{"role": "system", "content": (
20
  "Determine the language of the user's question and respond in the same language. "
 
24
  "(or the equivalent in French, depending on the input language). Then stop responding."
25
  )}]
26
 
27
+ for msg in chat_history:
28
+ conversation.append(msg)
 
29
 
30
  conversation.append({"role": "user", "content": user_input})
31
 
 
43
  except Exception as error:
44
  reply = f"Error: {error}"
45
 
46
+ chat_history.append({"role": "user", "content": user_input})
47
+ chat_history.append({"role": "assistant", "content": reply})
48
+
49
  return chat_history, chat_history, ""
50
 
51
  with gr.Blocks() as demo:
52
  with gr.Row():
53
+ chatbot = gr.Chatbot(height=450, type="messages")
54
 
55
  chat = gr.ChatInterface(
56
  respond,