Spaces:
Runtime error
Runtime error
Commit
·
c52d87c
1
Parent(s):
ddea92b
Update functions.py
Browse files- functions.py +11 -3
functions.py
CHANGED
@@ -7,6 +7,7 @@ import random
|
|
7 |
import time
|
8 |
import os
|
9 |
import re
|
|
|
10 |
import json
|
11 |
import copy
|
12 |
# import sqlite3
|
@@ -190,7 +191,7 @@ def make_user_message_list_fn(
|
|
190 |
|
191 |
|
192 |
def sequential_chat_once_fn(payload, api_key_text, history, history_md_stable, history_md_stream, tips):
|
193 |
-
print("\n\n")
|
194 |
|
195 |
assistant_message = ""
|
196 |
tips = ""
|
@@ -200,26 +201,32 @@ def sequential_chat_once_fn(payload, api_key_text, history, history_md_stable, h
|
|
200 |
completion = openai.ChatCompletion.create(**payload)
|
201 |
|
202 |
if payload.get('stream'):
|
|
|
|
|
203 |
is_first=True
|
204 |
for chunk in completion:
|
205 |
if is_first:
|
206 |
is_first = False
|
207 |
continue
|
208 |
if chunk.choices[0].finish_reason is None:
|
209 |
-
|
|
|
210 |
assistant_message += chunk.choices[0].delta.content or ''
|
|
|
211 |
history_md_stream = make_md_line('assistant', assistant_message)
|
212 |
tips = 'streaming'
|
213 |
yield assistant_message, history_md_stream, tips, history
|
214 |
else:
|
215 |
pass
|
216 |
pass
|
|
|
217 |
print('')
|
218 |
pass
|
219 |
else:
|
220 |
assistant_message = completion.choices[0].message.content
|
221 |
history_md_stream = make_md_line('assistant', assistant_message)
|
222 |
tips = 'got'
|
|
|
223 |
print(assistant_message)
|
224 |
yield assistant_message, history_md_stream, tips, history
|
225 |
pass
|
@@ -231,7 +238,7 @@ def sequential_chat_once_fn(payload, api_key_text, history, history_md_stable, h
|
|
231 |
yield assistant_message, history_md_stream, tips, history
|
232 |
pass
|
233 |
|
234 |
-
print("\n\n")
|
235 |
|
236 |
|
237 |
def sequential_chat_fn(
|
@@ -297,6 +304,7 @@ def sequential_chat_fn(
|
|
297 |
|
298 |
for user_message in user_message_list:
|
299 |
print('')
|
|
|
300 |
print(user_message)
|
301 |
print('')
|
302 |
# make the_messages to sent
|
|
|
7 |
import time
|
8 |
import os
|
9 |
import re
|
10 |
+
import sys
|
11 |
import json
|
12 |
import copy
|
13 |
# import sqlite3
|
|
|
191 |
|
192 |
|
193 |
def sequential_chat_once_fn(payload, api_key_text, history, history_md_stable, history_md_stream, tips):
|
194 |
+
# print("\n\n")
|
195 |
|
196 |
assistant_message = ""
|
197 |
tips = ""
|
|
|
201 |
completion = openai.ChatCompletion.create(**payload)
|
202 |
|
203 |
if payload.get('stream'):
|
204 |
+
print('assistant:')
|
205 |
+
# print('->>>')
|
206 |
is_first=True
|
207 |
for chunk in completion:
|
208 |
if is_first:
|
209 |
is_first = False
|
210 |
continue
|
211 |
if chunk.choices[0].finish_reason is None:
|
212 |
+
sys.stdout.write("\r")
|
213 |
+
# print(chunk.choices[0].delta.content or '', end="")
|
214 |
assistant_message += chunk.choices[0].delta.content or ''
|
215 |
+
print(assistant_message, end="")
|
216 |
history_md_stream = make_md_line('assistant', assistant_message)
|
217 |
tips = 'streaming'
|
218 |
yield assistant_message, history_md_stream, tips, history
|
219 |
else:
|
220 |
pass
|
221 |
pass
|
222 |
+
# print('=>>>')
|
223 |
print('')
|
224 |
pass
|
225 |
else:
|
226 |
assistant_message = completion.choices[0].message.content
|
227 |
history_md_stream = make_md_line('assistant', assistant_message)
|
228 |
tips = 'got'
|
229 |
+
print('assistant:')
|
230 |
print(assistant_message)
|
231 |
yield assistant_message, history_md_stream, tips, history
|
232 |
pass
|
|
|
238 |
yield assistant_message, history_md_stream, tips, history
|
239 |
pass
|
240 |
|
241 |
+
# print("\n\n")
|
242 |
|
243 |
|
244 |
def sequential_chat_fn(
|
|
|
304 |
|
305 |
for user_message in user_message_list:
|
306 |
print('')
|
307 |
+
print(f'user({token_text}):')
|
308 |
print(user_message)
|
309 |
print('')
|
310 |
# make the_messages to sent
|