返回顶部
热门问答 更多热门问答
技术文章 更多技术文章

介绍一个AI工具平台Composio,支持多种大模型和Agent操作

[复制链接]
链载Ai 显示全部楼层 发表于 前天 12:47 |阅读模式 打印 上一主题 下一主题

Composio MCP Servers

这个组件服务平台是Claude的公司Anthropic推出的,你可以通过api调用平台上面的工具,调用上面的那些mcp组件。还是老样子,仓库和官网链接先放出来:


这个平台通过mcp server支持数百种应用程序,你可以通过远程调用将各种操作集成到自己的应用里面。


如何使用

关于使用方面,我这里用的是python3.12版本,我们先新建一个conda虚拟环境,然后把依赖包安装好:

condacreateenv-ncomposiocondaactivatecomposio

创建好环境后,安装好依赖包:

pipinstallcomposio-corecomposio-openai

然后现在我们根据官网的例子,用Composio的GitHub工具给给它的仓库加一个star。运行视频放在这:


在做这项任务之前,我们需要先在命令行运行下面这个命令,将你的composio关联到你的github:

composioaddgithub

运行命令行之后会出现一个 CLI API KEY,将这个东西复制完粘贴到你的命令行,然后完成github的连接验证,之后你就可以在本地调用你的github进行操作。

然后来到composio的控制台页面,找到你关联账号的apikey,记住这个东西后面要用:

之后我们新建一个python文件,或者新建一个notebook,我这里是在python文件写的代码测试。

from composio_openai import ComposioToolSet, App, Actionfrom openai import OpenAI
openai_client = OpenAI( base_url="", api_key="")
# 连接工具列表composio_toolset = ComposioToolSet(api_key="") # 这里替换成刚才上面关联账号的apikey# 选择要用到的工具tools = composio_toolset.get_tools(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER])
# 提示词,也是你的任务task ="帮我给一个仓库点star: composiohq/composio on GitHub"
response = openai_client.chat.completions.create( model="deepseek-ai/DeepSeek-V2.5", tools=tools, messages=[ {"role":"system","content":"You are a helpful assistant."}, {"role":"user","content": task}, ],)result = composio_toolset.handle_tool_calls(response)print(result)

将上面的代码配置完后运行,当你的界面出现这个的时候,说明成功了:

而到仓库里面也能看到已经被我们的工具成功加了个star了。


其他组件和调用流程

我们来到仓库,这里还有其他的工具组件可以用,里面还配有Serpapi,Firecrawl等等这些搜索引擎检索工具。

那么它是如何工作的呢?以大模型用计算器为例子,我们来看看下面这张流程图:

上面这张图对应这个代码:

fromcomposio_openaiimportComposioToolSet, actionfromtypingimportAnnotatedfromopenaiimportOpenAIimportmath
client = OpenAI()toolset = ComposioToolSet()
@action(toolname="calculate_square_root", requires=["math"])defcalculate_square_root( a: Annotated[int,"Number from which to take the square root"],) ->float: """ Calculate the square root of a number. :param a: Number from which to take the square root :return sqrt: Square root of the number """ returnmath.sqrt(a)
tools = toolset.get_tools([calculate_square_root])
question ="What is the square root of 212?"
response = client.chat.completions.create( model="gpt-4o-mini", messages=[ { "role":"user", "content": question, } ], tools=tools, tool_choice="auto",)
result = toolset.handle_tool_calls(response=response)
print("Question: ", question)print("Answer: ", result[0]["data"]["sum"])

一是创建工具,代码中的函数被转换为LLM可以理解的形式。在这里,这通过 @action 包装器来完成,对应代码里面的:

@action(toolname="calculate_square_root",requires=["math"])

二是大模型调用工具,大模型根据我们的输入,来决定是否使用工具,如果确定使用工具的话,就会生成一个格式正确的工具使用请求。这个对应的是图里面的2、3

最后是Composio调用定义的工具。handle_tool_calls方法解释工具的调用并调用定义的那些工具。

Composio支持三种调用工具的方法,一种是刚才提到的整个平台的工具,

另一种是本地已经有的工具,最后一种是用Composio提供的自定义工具格式创建的工具。

对于我们日常使用的来讲,免费计划已经够我们白嫖了,每个月有1w次api请求机会:


图片

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

链载AI是专业的生成式人工智能教程平台。提供Stable Diffusion、Midjourney AI绘画教程,Suno AI音乐生成指南,以及Runway、Pika等AI视频制作与动画生成实战案例。从提示词编写到参数调整,手把手助您从入门到精通。
  • 官方手机版

  • 微信公众号

  • 商务合作

  • Powered by Discuz! X3.5 | Copyright © 2025-2025. | 链载Ai
  • 桂ICP备2024021734号 | 营业执照 | |广西笔趣文化传媒有限公司|| QQ