Update app.py
Browse files
app.py
CHANGED
@@ -108,7 +108,8 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=None,
|
|
108 |
if response.status_code != 200:
|
109 |
print(f"API hatası: {response.text}")
|
110 |
return chatbot, history, chat_counter
|
111 |
-
|
|
|
112 |
assistant_response = ""
|
113 |
for chunk in response.iter_lines():
|
114 |
if not chunk:
|
@@ -120,15 +121,14 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=None,
|
|
120 |
chunk_data = json.loads(chunk_str[6:])
|
121 |
delta = chunk_data['choices'][0]['delta']
|
122 |
if 'content' in delta and delta['content']:
|
123 |
-
|
124 |
-
assistant_response += content
|
125 |
-
# Parça parça güncelleme yerine, yalnızca akış sonunda sonuç üretiliyor.
|
126 |
except json.JSONDecodeError as e:
|
127 |
print(f"JSON parse hatası: {e} - Chunk: {chunk_str}")
|
128 |
elif chunk_str == "data: [DONE]":
|
129 |
print("Akış tamamlandı: [DONE] alındı")
|
130 |
break
|
131 |
|
|
|
132 |
if assistant_response:
|
133 |
history.append(assistant_response)
|
134 |
chatbot.append({"role": "assistant", "content": assistant_response})
|
@@ -139,8 +139,6 @@ def predict(system_msg, inputs, top_p, temperature, chat_counter, chatbot=None,
|
|
139 |
except Exception as e:
|
140 |
print(f"Dosya yazma hatası (Bot): {e}")
|
141 |
|
142 |
-
yield chatbot, history, chat_counter
|
143 |
-
print(f"Son chatbot durumu: {chatbot}")
|
144 |
return chatbot, history, chat_counter
|
145 |
|
146 |
def save_chat(chatbot):
|
|
|
108 |
if response.status_code != 200:
|
109 |
print(f"API hatası: {response.text}")
|
110 |
return chatbot, history, chat_counter
|
111 |
+
|
112 |
+
# Gelen yanıt parçalarını toplayıp tek bir yanıt oluşturuyoruz
|
113 |
assistant_response = ""
|
114 |
for chunk in response.iter_lines():
|
115 |
if not chunk:
|
|
|
121 |
chunk_data = json.loads(chunk_str[6:])
|
122 |
delta = chunk_data['choices'][0]['delta']
|
123 |
if 'content' in delta and delta['content']:
|
124 |
+
assistant_response += delta['content']
|
|
|
|
|
125 |
except json.JSONDecodeError as e:
|
126 |
print(f"JSON parse hatası: {e} - Chunk: {chunk_str}")
|
127 |
elif chunk_str == "data: [DONE]":
|
128 |
print("Akış tamamlandı: [DONE] alındı")
|
129 |
break
|
130 |
|
131 |
+
# Tüm yanıt tek parça halinde eklendi
|
132 |
if assistant_response:
|
133 |
history.append(assistant_response)
|
134 |
chatbot.append({"role": "assistant", "content": assistant_response})
|
|
|
139 |
except Exception as e:
|
140 |
print(f"Dosya yazma hatası (Bot): {e}")
|
141 |
|
|
|
|
|
142 |
return chatbot, history, chat_counter
|
143 |
|
144 |
def save_chat(chatbot):
|