徐州网站设计师,肥城网站建设价格,asp.net mvc5 网站开发实践,小程序的定义OpenAI开源了多智能体编排的工程swarm#xff0c;今天介绍一下swarm与OLLAMA如何结合使用的教程#xff0c;在本地构建自己的多智能体服务#xff0c;并给大家实践演示几个案例。
安装步骤
安装ollama#xff0c;在官网下载对应操作系统的版本即可#xff0c;下载后用ol…OpenAI开源了多智能体编排的工程swarm今天介绍一下swarm与OLLAMA如何结合使用的教程在本地构建自己的多智能体服务并给大家实践演示几个案例。
安装步骤
安装ollama在官网下载对应操作系统的版本即可下载后用ollama部署大模型网上教程很多本文不再描述。安装ollama的python接口
pip install ollama安装swarm框架
pip install githttps://github.com/openai/swarm.git注意这一步的前提是已经安装了git如果本地没有安装请先行下载安装
服务构建示例
swarm官网给出的使用示例如下
from swarm import Swarm, Agentclient Swarm()def transfer_to_agent_b():return agent_bagent_a Agent(nameAgent A,instructionsYou are a helpful agent.,functions[transfer_to_agent_b],
)agent_b Agent(nameAgent B,instructionsOnly speak in Haikus.,
)response client.run(agentagent_a,messages[{role: user, content: I want to talk to agent B.}],
)print(response.messages[-1][content])在这个示例的基础上与ollama以及在ollama中安装的大模型结合的方法如下 from swarm import Swarm, Agent# 利用OpenAI的接口安装swarm时会自动下载建立与ollama服务连接的客户端
from openai import OpenAI
ollama_client OpenAI(base_url http://localhost:11434/v1,api_keyollama, # required, but unused
)# 在swarm构建时指定与ollama连接的客户端
client Swarm(clientollama_client)def transfer_to_agent_b():return agent_bagent_a Agent(nameAgent A,modelqwen2.5:7b, # 在构建智能体时指定ollama中的模型传入在ollama中构建好的大模型名称即可例如qwen2.5:7binstructionsYou are a helpful agent.,functions[transfer_to_agent_b],
)agent_b Agent(nameAgent B,modelqwen2.5:7b, # 在构建智能体时指定ollama中的模型传入在ollama中构建好的大模型名称即可例如qwen2.5:7binstructionsOnly speak in Haikus.,
)response client.run(agentagent_a,messages[{role: user, content: I want to talk to agent B.}],
)print(response.messages[-1][content])总结一下若想将swarm和ollama结合比官方示例多了三步非常简单
利用OpenAI的接口安装swarm时会自动下载建立与ollama服务连接的客户端在swarm构建时指定与ollama连接的客户端在构建智能体时指定ollama中的模型
大家可以利用上述三个步骤自行尝试改造swarm开源代码中提供的示例进行尝试后面有时间也会讲讲swarm框架的具体用法供大家参考。