前言
略
使用方法
有空再写
直接上代码
import ollama
history = []
while True:
user_input = input("\nYou: ")
if user_input.lower() in ["exit", "quit","拜拜"]:
break
history.append([user_input, ""])
messages = []
for idx, (user_msg, model_msg) in enumerate(history):
if idx == len(history) - 1 and not model_msg:
messages.append({"role": "user", "content": user_msg})
break
if user_msg:
messages.append({"role": "user", "content": user_msg})
if model_msg:
messages.append({"role": "assistant", "content": model_msg})
# generate a response combining the prompt and data we retrieved in step 2
output = ollama.chat(
model="qwen2:72b",
messages=messages
)
print(output['message']['content'])