
llama3.2-1B 在香橙派 5 plus 使用ollama部署
从结果来看,速度也是相当不错,下载的模型应该是量化的版本,我不确定是多少位的量化,模型的大小是1.3GB,原始模型的大小是2.3GB。前段时间使用香橙派部署了llama3.2-1B的FP16的原始模型,又使用树莓派5部署了ollama去调用llama3.2-1B,发现使用ollama调用的速度很快啊,为了做一个对比测试,我在香橙派也安装了ollama去调用llama3.2-1B。步骤跟树莓派部署一
·
前段时间使用香橙派部署了llama3.2-1B的FP16的原始模型,又使用树莓派5部署了ollama去调用llama3.2-1B,发现使用ollama调用的速度很快啊,为了做一个对比测试,我在香橙派也安装了ollama去调用llama3.2-1B。步骤跟树莓派部署一样Llama 3.2 1B 大型语言模型(LLMs)在Raspberry Pi 5(树莓派 5 ) --Linux Ubuntu 上安装并运行-CSDN博客。从结果来看,速度也是相当不错,下载的模型应该是量化的版本,我不确定是多少位的量化,模型的大小是1.3GB,原始模型的大小是2.3GB。回答的效果也还可以,具体测试视频我放在b站啦,其中还讲了一下如何使用github下载ollama去加速安装,还有如何使用python调用ollama的api,ollama-python的官方文档看这里GitHub - ollama/ollama-python: Ollama Python library。
详情请看llama3.2-1B -香橙派5plus-RK3588的ollama部署_哔哩哔哩_bilibili
调用代码:
import subprocess
import time
import ollama
# 启动 ollama 服务
def start_ollama_service():
# 启动 ollama 服务
process = subprocess.Popen(['ollama', 'serve'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print("Starting ollama service...")
# 等待服务启动完成
time.sleep(5) # 根据实际情况调整等待时间
return process
# 初始化对话历史
conversation_history = []
def send_message(message):
# 将用户消息添加到对话历史中
conversation_history.append({'role': 'user', 'content': message})
# 调用模型进行对话
response = ollama.chat(
model='llama3.2:1b',
messages=conversation_history
)
# 将模型回复添加到对话历史中
conversation_history.append(response['message'])
# 返回模型的回复内容
return response['message']['content']
# 主程序
def main():
# 启动 ollama 服务
ollama_process = start_ollama_service()
try:
# 示例多轮对话
user_message = input("You: ")
while user_message.lower() != 'exit':
# 发送用户消息并获取模型回复
bot_response = send_message(user_message)
print(f"Bot: {bot_response}")
# 获取用户下一条消息
user_message = input("You: ")
# 打印完整的对话历史
print("\nComplete Conversation History:")
for message in conversation_history:
role = message['role']
content = message['content']
print(f"{role.capitalize()}: {content}")
finally:
# 关闭 ollama 服务
ollama_process.terminate()
ollama_process.wait()
print("ollama service terminated.")
if __name__ == "__main__":
main()
更多推荐
所有评论(0)