LLM之Agent(十二)| OpenAI Agent-Swarm简单入门

项目地址:https://github.com/openai/swarm

本文简单介绍一下如何使用Swarm:

一、首先需要安装环境(python3.10+)

# 创建python虚拟环境(可选)conda create -n python=3.10
pip install git+ssh://git@github.com/openai/swarm.git

二、设置OpenAI API​​​​​​​

import osos.environ['OPENAI_API_KEY'] =''

三、下面是一个handoff的例子​​​​​​​

from swarm import Swarm, Agent
client = Swarm()
english_agent = Agent(    name="English Agent",    instructions="You only speak English.",)
spanish_agent = Agent(    name="Spanish Agent",    instructions="You only speak Spanish.",)
def transfer_to_spanish_agent():    """Transfer spanish speaking users immediately."""    return spanish_agent
english_agent.functions.append(transfer_to_spanish_agent)
messages = [{"role": "user", "content": "Hola. ¿Como estás?"}]response = client.run(agent=english_agent, messages=messages)
print(response.messages[-1]["content"])

输出:

¡Hola! Estoy bien, gracias. ¿Y tú, cómo estás?

参考文献:https://cookbook.openai.com/examples/orchestrating_agents

上一篇:Android Audio基础——音频混音结束处理(十一)


下一篇:linux笔记(SSH)