啥,字节扣子Bot通过API调用百度文心一言?

[复制链接]
发表于 2026-2-21 14:45:59 | 显示全部楼层 |阅读模式

4月1号扣子上新啦!!
扣子插件在线IDE
扣子丰富的插件功能和机动的Workflow深受开辟者的好评,这不,扣子又推出了插件IDE,无需利用自己的IDE、无需利用自己的服务器就可以更好的写自己的插件(之前已经支持在Worflow中直接添加代码节点)。




利用axios举行HTTP哀求,先来安装依赖包,在界面左下角非常方便地安装完成,在底部控制台中会体现依赖包安装过程信息。


最开始并没有摸清晰怎么调用,会有大量的错误,看到这么多Error提示有颔首大。不外你可以试试通过“Ctrl + I”来唤起智能助手来帮你写代码,直接输入内容大概输入“/”后选择指令,会天生提示的代码,选择“Alt+Y”大概“Alt+N”来选择是否接纳这些代码。不瞒你说,这部分代码最开始就是通过提示天生的。




在这里就写了两个插件工具,此中create_feishu_doc是调用的MumuLab中自己写的API,如许就可以自界说调用险些任何API,这里选择调用飞书开放平台API并创建飞书文档,创建乐成后返回创建的飞书文档链接。

  1. /** 扣子插件IED部分代码 **/
  2. import { Args } from '@/runtime';
  3. import { Input, Output } from "@/typings/create_feishu_doc2/create_feishu_doc2";
  4. import axios from 'axios';
  5. /**
  6.   * Each file needs to export a function named `handler`. This function is the entrance to the Tool.
  7.   * @param {Object} args.input - input parameters, you can get test input value by input.xxx.
  8.   * @param {Object} args.logger - logger instance used to print logs, injected by runtime
  9.   * @returns {*} The return data of the function, which should match the declared output parameters.
  10.   * 
  11.   * Remember to fill in input/output in Metadata, it helps LLM to recognize and use tool.
  12.   */
  13. export async function handler({ input, logger }: Args<Input>): Promise<Output> {
  14. const data = {
  15.       tenant_access_token: "<your_tenant_access_token>",
  16. doc_title: "我来介绍下上海",
  17. doc_content: "1000 字介绍上海的正文内容......"
  18.     };
  19. const response = await axios({
  20. url:"<your_api_url>",
  21. method:"post",
  22. params:data
  23.     });
  24.         return {
  25. message: response.data.feishu_doc_url
  26.     };
  27.   };
复制代码
接着就可以发布自己的插件了,如今更新了下,须要确认是否会网络用户信息。






扣子插件通过API调用百度文心一言
前面我们也说了字节扣子通过API调用百度文心一言,实在就是用的扣子插件可以调用各种API来说的。
起首,在百度智能云千帆平台开通服务、创建应用。




摆设好服务后,就可以通过API来调用百度智能云平台的大模子,好比文心一言ERNIE-Speed-8k。这里示例先调用获取access_token,如下图所示,哀求乐成,而且效果会返回在respose_access_token.data中。

  1. /** 扣子插件IED部分代码 **/
  2. import { Args } from '@/runtime';
  3. import { Input, Output } from "@/typings/create_feishu_doc2/create_feishu_doc2";
  4. import axios from 'axios';
  5. /**
  6.   * Each file needs to export a function named `handler`. This function is the entrance to the Tool.
  7.   * @param {Object} args.input - input parameters, you can get test input value by input.xxx.
  8.   * @param {Object} args.logger - logger instance used to print logs, injected by runtime
  9.   * @returns {*} The return data of the function, which should match the declared output parameters.
  10.   *
  11.   * Remember to fill in input/output in Metadata, it helps LLM to recognize and use tool.
  12.   */
  13. export async function handler({ input, logger }: Args<Input>): Promise<Output> {
  14.         const data = {
  15.                         tenant_access_token: "<your_tenant_access_token>",
  16.                         doc_title: "我来介绍下上海",
  17.                         doc_content: "1000 字介绍上海的正文内容......"
  18.         };
  19.         const response = await axios({
  20.                 url:"<your_api_url>",
  21.                 method:"post",
  22.                 params:data
  23.         });
  24.         return {
  25.                 message: response.data.feishu_doc_url
  26.         };
  27. };
复制代码
获取到access_token,就可以在IED中调用以下代码和ERNIE-Speed-8K在线服务举行对话了。
  1. https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/ernie_speed?access_token=<your_access_token>
复制代码
插件通过API调用阿里云魔搭社区/智谱AI......
固然,也可以摆设好阿里云魔搭社区的在线服务大概智谱AI的在线服务,安装相应的依赖包,直接举行哀求。




扣子主页直接@Bot上新
别的扣子也上新了控制台可以大概直接@Bot来对话的功能,之前须要发布到豆包、飞书、微信等平台才气@Bot,如今通过扣子页面就可以实现了,只须要先收藏自己喜好的Bot,在自己的主页就可以为所欲为的和这些Bot对话了。



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表