bleysg commited on
Commit
38bd567
·
1 Parent(s): e7eaa32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -90,11 +90,20 @@ def chat_double(history1, history2, system_message, max_tokens, temperature, top
90
  gen1 = chat(openai.api_model1, history1, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty, openai.api_key1, openai.api_base1)
91
  gen2 = chat(openai.api_model2, history2, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty, openai.api_key2, openai.api_base2)
92
 
93
- # We define a default value that will be used when one of the generators is exhausted
94
- default_value = ([["", ""]], [["", ""]], "")
95
-
96
- for (chatbot1_out, chat_history_state1_out, message1), (chatbot2_out, chat_history_state2_out, message2) in zip_longest(gen1, gen2, fillvalue=default_value):
97
- yield chatbot1_out, chatbot2_out, chat_history_state1_out, chat_history_state2_out, ""
 
 
 
 
 
 
 
 
 
98
 
99
 
100
  start_message = ""
 
90
  gen1 = chat(openai.api_model1, history1, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty, openai.api_key1, openai.api_base1)
91
  gen2 = chat(openai.api_model2, history2, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty, openai.api_key2, openai.api_base2)
92
 
93
+ # Define a default value that will be used when one of the generators is exhausted
94
+ latest_chatbot1_out, latest_chat_history_state1_out, _ = ([["", ""]], [["", ""]], "")
95
+ latest_chatbot2_out, latest_chat_history_state2_out, _ = ([["", ""]], [["", ""]], "")
96
+
97
+ for out1, out2 in zip_longest(gen1, gen2, fillvalue=None):
98
+ if out1 is not None: # None means gen1 is exhausted
99
+ chatbot1_out, chat_history_state1_out, _ = out1
100
+ latest_chatbot1_out, latest_chat_history_state1_out = chatbot1_out, chat_history_state1_out
101
+
102
+ if out2 is not None: # None means gen2 is exhausted
103
+ chatbot2_out, chat_history_state2_out, _ = out2
104
+ latest_chatbot2_out, latest_chat_history_state2_out = chatbot2_out, chat_history_state2_out
105
+
106
+ yield latest_chatbot1_out, latest_chatbot2_out, latest_chat_history_state1_out, latest_chat_history_state2_out, ""
107
 
108
 
109
  start_message = ""