1.终端调用
#查看ollama版本
ollama -v
#查看本地模型
ollama list
#调用本地模型,进入对话
ollama run {model name}
#安装模型
ollama pull {model_name}
#删除模型
ollama rm {model_name}
#命令退出
/bye
2.代码调用
from ollama import chat
from ollama import ChatResponse
# 定义一个函数来获取chat响应
def get_chat_response():
try:
response: ChatResponse = chat(
model='deepseek-r1:7b',
messages=[
{"role": "system", "content": "你是一个资深的数据分析专家"},
{"role": "user",
"content": "数据分析专家是一名具有丰富的分析经验的专业人士,掌握数据挖掘、数据分析、数据可视化等技能。那么 数据可视化 需要用到Python的哪些技术呢?,请列出5-10种"}
],
stream=False
)
# 提取并返回answer
return response.message.content
except Exception as e:
# 更具体的错误信息输出
print(f"在与模型交互时发生错误: {e}")
return None
# 获取并打印answer
answer = get_chat_response()
if answer:
print(answer)
else:
print("没有获取到有效的回答。")