Minimax AI

v1.0.3发布于:2024-02-27 16:47

说明文档
回复列表 (0)

介绍

MiniMax 是国内领先的拥有文本、语音、视觉三模态融合的千亿参数语言大模型,并打通产品全链路的创业公司。通过搭建超大规模实验平台与推理平台,跑通技术与产品的迭代闭环,实现模型能力与用户交互量的极速增长。

官网:https://api.minimax.chat

插件集成了 MiniMax 的接口,可以方便的调用 MiniMax 的接口

标识

调用插件的时候需要用到标识,标识是唯一的,不能重复,建议使用英文,不要使用中文,对应插件 plugin.json 中的 key 字段

  • 标识:minimax

配置

{
  "baseUrl": "https://api.minimax.chat",
  "group_id": "Minimax账户的groupID",
  "api_key": "Minimax的apiKey",
  "options": {
    "model": "模型 abab5.5-chat、abab6-chat等",
    "bot_name": "机器人名称",
    "sender_name": "发送者名称"
  }
}

其他配置参照MiniMax 官网的配置

方法

下面是插件提供的一些方法

  • chat

聊天

 /**
   * 调用模型
   * @param messages 消息列表
   * @param options 配置,参考官方文档: https://api.minimax.chat/
   * @param options callback 当stream为true时,回调函数
   * @returns 返回模型结果
   */
  async chat(
    messages: Message[],
    options: any = {
      model: "abab5.5-chat",
      bot_name: "COOL", // 机器人名称
      sender_name: "USER", // 发送者名称
      stream: false, // 是否流式调用
      url: "/v1/text/chatcompletion_pro" // 调用的接口
    },
    callback?: (data: any) => void
  )

消息体

// 消息体
interface Message {
  // 角色
  role: "system" | "user" | "assistant";
  // 内容
  content: any;
}
  • embeddings

向量化

  /**
    * 向量化
    * @param inputs 输入 字符串数组
    * @param options 配置  model 模型名称 url 接口地址  type 可选值:db、query
    */
  async embeddings(
    inputs: string[],
    options: any = {
      model: "embo-01",
      url: "/v1/embeddings",
      type: "query"
    }
  )
  • text2Voice

文本转声音

  /**
   * 文本转语音
   * @param text
   * @param options url 模型地址 model 模型名称 voice_id 语音id 配置参考文档https://www.minimaxi.com/document/guides/T2A-model/tts/api
   * @returns 返回音频文件的arraybuffer
   */
  async text2Voice(
    text: string,
    options: any = {
      url: "/v1/text_to_speech",
      model: "speech-02",
      voice_id: "female-shaonv",
    }
  )

options 配置参考文档,https://www.minimaxi.com/document/guides/T2A-model/tts/api

调用示例

@Inject()
pluginService: PluginService;

// 非流式调用
const result = await this.pluginService.invoke('minimax', 'chat',[
  { role: "system", content: "你的名字叫COOL, 你是一个编程助手" },
  { role: "user", content: "你是谁" },
]);

// 流式调用
await this.pluginService.invoke('minimax', 'chat',[
  { role: "system", content: "你的名字叫COOL, 你是一个编程助手" },
  { role: "user", content: "你是谁" },
],{
    stream: true,
  },
  (res) => {
    console.log(res);
});

// 向量化
const result = await this.pluginService.invoke('minimax', 'embeddings', ['你好']);
console.log(result);

// 文本转语音
const arraybuffer = await this.pluginService.invoke('minimax', 'text2Voice', '你一个项目用COOL就够了好');
// 生成文件
const fs = require("fs");
fs.writeFileSync("test.mp3", Buffer.from(arraybuffer));

函数回调

@Inject()
pluginService: PluginService;

const instance = await this.pluginService.getInstance('minimax');

// 函数回调
const messages: any = [
  { role: "system", content: "你是一个天气助手" },
  { role: "user", content: "帮我查询下厦门的天气" },

];

const tools = [
  {
      "type": "function",
      "function": {
          "name": "weather_info",
          "description": `查询天气`,
          "parameters": JSON.stringify({
            "type": "object",
            "properties": {    
              "city": {
                "type": "string",
                "description": "城市"
              }
            },
            "required": [
                "city"
            ]
        })
      }
  }
] 
instance.chat(messages, { stream: true, tools, tool_choice: 'auto' }, (res) => {
  console.log(JSON.stringify(res));
// 返回结果
//   {
//     "tool_calls": [
//         {
//             "id": "call_function_6305794571",
//             "type": "function",
//             "function": {
//                 "name": "weather_info",
//                 "arguments": "{\"city\": \"上海\"}"
//             }
//         }
//     ],
//     "usage": {
//         "total_tokens": 139
//     },
//     "isEnd": true
// }
});

更新日志

  • v1.0.3 (2024-03-08)

    • 新增函数回调
  • v1.0.2 (2024-03-08)

    • 新增文本转语音
  • v1.0.1 (2024-03-04)

    • 新增向量化方法
  • v1.0.0 (2024-02-05)

    • 初始版本