Update ollama_with_python.py

This commit is contained in:
guanjihuan 2025-01-28 00:59:25 +08:00
parent 3cde4d784f
commit d6d7b6d6a1

View File

@ -9,7 +9,7 @@ response = ollama.chat(model="llama3.2:latest", messages=[{"role": "user", "cont
for part in response: for part in response:
print(part['message']['content'], end='', flush=True) print(part['message']['content'], end='', flush=True)
# 流式输出,且模型后台常驻(需要手动 ollama stop 关闭) # 流式输出,同时设置模型为后台常驻,需要手动 ollama stop 关闭
import ollama import ollama
response = ollama.chat(model="llama3.2:latest", messages=[{"role": "user", "content": "你好"}], stream=True, keep_alive=-1) response = ollama.chat(model="llama3.2:latest", messages=[{"role": "user", "content": "你好"}], stream=True, keep_alive=-1)
for part in response: for part in response: