Spaces:
Sleeping
Sleeping
mrolando
commited on
Commit
•
527456d
1
Parent(s):
4add049
added word streaming
Browse files
app.py
CHANGED
@@ -70,26 +70,32 @@ def respond(message, chat_history):
|
|
70 |
model="gpt-3.5-turbo",
|
71 |
messages= prompt,
|
72 |
temperature=0.5,
|
73 |
-
max_tokens=1000
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
with gr.Blocks() as demo:
|
95 |
gr.Markdown("""
|
|
|
70 |
model="gpt-3.5-turbo",
|
71 |
messages= prompt,
|
72 |
temperature=0.5,
|
73 |
+
max_tokens=1000,
|
74 |
+
stream = True
|
75 |
+
)#.choices[0].message.content
|
76 |
+
# chat_history.append((message, response))
|
77 |
+
|
78 |
+
token_counter = 0
|
79 |
+
partial_words = ""
|
80 |
+
|
81 |
+
for chunk in response:
|
82 |
+
chunk_message = chunk['choices'][0]['delta']
|
83 |
+
if(len(chat_history))<1:
|
84 |
+
# print("entró acaá")
|
85 |
+
partial_words += chunk_message.content
|
86 |
+
chat_history.append([message,chunk_message.content])
|
87 |
+
else:
|
88 |
+
# print("antes", chat_history)
|
89 |
+
if(len(chunk_message)!=0):
|
90 |
+
if(len(chunk_message)==2):
|
91 |
+
partial_words += chunk_message.content
|
92 |
+
chat_history.append([message,chunk_message.content])
|
93 |
+
else:
|
94 |
+
partial_words += chunk_message.content
|
95 |
+
chat_history[-1] =([message,partial_words])
|
96 |
+
yield "",chat_history
|
97 |
+
|
98 |
+
# return "",chat_history
|
99 |
|
100 |
with gr.Blocks() as demo:
|
101 |
gr.Markdown("""
|