Промежуточный коммит. Добавлены методы stream_responce (agent), generate_stream_token (ollamaprovider)

This commit is contained in:
2026-05-12 22:24:39 +03:00
parent 3b4c8a1151
commit 30ce868764
8 changed files with 67 additions and 9 deletions
Binary file not shown.
+28
View File
@@ -27,6 +27,34 @@ class OllamaProvider:
response_text += content
return response_text
except Exception as e:
error_msg = str(e)
if "502" in error_msg:
return "Ошибка: Проверьте наличие VPN или Proxy."
return f"Ошибка: {error_msg}"
def generate_stream_tokens(self, messages, temperature=0.8, max_tokens=300):
"""Генерирует ответ от Ollama и возвращает его в виде стрима"""
try:
stream = ollama.chat(
model=self.model,
messages=messages,
stream=True,
options={
"temperature": temperature,
"num_predict": max_tokens,
},
)
# Собираем ответ в строку
response_text = ""
for chunk in stream:
content = chunk['message']['content']
#print(content, end='', flush=True)
#response_text += content
#return response_text
yield content
except Exception as e:
error_msg = str(e)
if "502" in error_msg: