Spaces:
Running
Running
restore to previous version
Browse files
app.py
CHANGED
@@ -67,29 +67,25 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
|
|
67 |
|
68 |
counter=0
|
69 |
for chunk in response.iter_lines():
|
70 |
-
print(f"chunk.decode() is ^^ - {chunk.decode()}")
|
71 |
if counter == 0:
|
72 |
counter+=1
|
73 |
continue
|
74 |
counter+=1
|
75 |
# check whether each line is non-empty
|
76 |
if chunk :
|
77 |
-
|
78 |
-
if
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
yield chat, history, chat_counter # resembles {chatbot: chat, state: history}
|
91 |
-
|
92 |
-
|
93 |
|
94 |
def reset_textbox():
|
95 |
return gr.update(value='')
|
|
|
67 |
|
68 |
counter=0
|
69 |
for chunk in response.iter_lines():
|
|
|
70 |
if counter == 0:
|
71 |
counter+=1
|
72 |
continue
|
73 |
counter+=1
|
74 |
# check whether each line is non-empty
|
75 |
if chunk :
|
76 |
+
# decode each line as response data is in bytes
|
77 |
+
if len(json.loads(chunk.decode()[6:])['choices'][0]["delta"]) == 0:
|
78 |
+
break
|
79 |
+
#print(json.loads(chunk.decode()[6:])['choices'][0]["delta"]["content"])
|
80 |
+
partial_words = partial_words + json.loads(chunk.decode()[6:])['choices'][0]["delta"]["content"]
|
81 |
+
if token_counter == 0:
|
82 |
+
history.append(" " + partial_words)
|
83 |
+
else:
|
84 |
+
history[-1] = partial_words
|
85 |
+
chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
|
86 |
+
token_counter+=1
|
87 |
+
yield chat, history, chat_counter # resembles {chatbot: chat, state: history}
|
88 |
+
|
|
|
|
|
|
|
89 |
|
90 |
def reset_textbox():
|
91 |
return gr.update(value='')
|