ollama大模型API调用接口
ollama大模型调用:https://github.com/ollama/ollama/tree/main
from langchain_community.llms import Ollama
# 创建Ollama对象
ollama = Ollama(base_url='http://localhost:端口号', model="模型名称")
# 定义对话历史
conversation_history = [{"role": "user", "content": "你是谁"}]
# 发出第一次提问
response = ollama(conversation_history[-1]["content"])
# 打印回答
print(response)
# 更新对话历史
conversation_history.append({"role": "assistant", "content": response})
# 提出新问题并继续对话
conversation_history.append({"role": "user", "content": "你能告诉我人工智能是什么吗?"})
response2 = ollama(conversation_history[-1]["content"])
# 打印新的回答
print(response2)
# 更新对话历史
conversation_history.append({"role": "assistant", "content": response2})
界面效果:
参考
https://www.jiqizhixin.com/articles/2024-04-23-6
https://www.llamafactory.cn/ollama-docs/api.html
https://blog.csdn.net/2301_81940605/article/details/144659459?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-0-144659459-blog-140815186.235v43pc_blog_bottom_relevance_base3&spm=1001.2101.3001.4242.1&utm_relevant_index=2
https://openatomworkshop.csdn.net/67483ab33a01316874da06fa.html?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Mzk2ODksImV4cCI6MTczNzI1OTUxMSwiaWF0IjoxNzM2NjU0NzExLCJ1c2VybmFtZSI6IndlaXhpbl80MTE5NDEyOSJ9.EDvFkqP8YvZRR3QKIKRVOS9LWVDvhmf-BefeE-jklGE&spm=1001.2101.3001.6650.4&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Eactivity-4-140267809-blog-140815186.235%5Ev43%5Epc_blog_bottom_relevance_base3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Eactivity-4-140267809-blog-140815186.235%5Ev43%5Epc_blog_bottom_relevance_base3&utm_relevant_index=7
https://gitcode.csdn.net/66c9b64ec618435984a1967a.html?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Mzk2ODksImV4cCI6MTczNzI1OTUxMSwiaWF0IjoxNzM2NjU0NzExLCJ1c2VybmFtZSI6IndlaXhpbl80MTE5NDEyOSJ9.EDvFkqP8YvZRR3QKIKRVOS9LWVDvhmf-BefeE-jklGE&spm=1001.2101.3001.6650.5&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Eactivity-5-137350055-blog-140815186.235%5Ev43%5Epc_blog_bottom_relevance_base3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Eactivity-5-137350055-blog-140815186.235%5Ev43%5Epc_blog_bottom_relevance_base3&utm_relevant_index=8
https://copilot.tencent.com/chat/?fromSource=gwzcw.9272003.9272003.9272003&utm_medium=cpc&utm_id=gwzcw.9272003.9272003.9272003
https://help.aliyun.com/zh/pai/use-cases/fine-tune-a-llama3-8b-model
https://blog.csdn.net/qq_55068938/article/details/140267809
https://blog.csdn.net/yzj5464/article/details/140815186?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-4-140815186-blog-140267809.235v43pc_blog_bottom_relevance_base3&spm=1001.2101.3001.4242.3&utm_relevant_index=6