Добавлена поддержка стриминга сообщений через yield токены. 'Деактивирован' метод generate_stream в ollamaapi

This commit is contained in:
2026-05-12 22:51:42 +03:00
parent 30ce868764
commit 1504c5fee7
6 changed files with 158 additions and 91 deletions
+6 -11
View File
@@ -34,7 +34,6 @@ class OllamaProvider:
return f"Ошибка: {error_msg}"
def generate_stream_tokens(self, messages, temperature=0.8, max_tokens=300):
"""Генерирует ответ от Ollama и возвращает его в виде стрима"""
try:
stream = ollama.chat(
model=self.model,
@@ -46,17 +45,13 @@ class OllamaProvider:
},
)
# Собираем ответ в строку
response_text = ""
for chunk in stream:
content = chunk['message']['content']
#print(content, end='', flush=True)
#response_text += content
#return response_text
yield content
if content:
yield content # 🔥 ВАЖНО: внутри цикла
except Exception as e:
error_msg = str(e)
if "502" in error_msg:
return "Ошибка: Проверьте наличие VPN или Proxy."
return f"Ошибка: {error_msg}"
yield f"Error: {str(e)}"
if "502" in e:
yield "Ошибка: Проверьте наличие VPN или Proxy."