Skip to content
On this page

OpenAI 插件

OpenAI 插件 (@tencent/ssv-ai-sdk-plugin-openai) 是专门为 OpenAI API 设计的插件,提供了开箱即用的 OpenAI 模型接入能力。该插件处理了 OpenAI 特有的数据格式、流式响应解析以及错误处理。

安装

首先安装 OpenAI 插件包:

注意该 npm 包为 Coding Npm 的私有源,请先确定已经正确配置了 Coding Npm

bash
npm install @tencent/ssv-ai-sdk-plugin-openai --save

使用方法

js
import { useChat } from '@tencent/ssv-ai-sdk-react';
import { OpenAIPlugin } from '@tencent/ssv-ai-sdk-plugin-openai';

const { chat } = useChat({
  api: {
    chatEndpoint: 'your-chat-endpoint',
  },
  mode: 'stream',
  streamFormat: 'incremental',
  // 引入 OpenAI 插件
  plugins: [new OpenAIPlugin()],
});
js
import { useChat } from '@tencent/ssv-ai-sdk-vue3';
import { OpenAIPlugin } from '@tencent/ssv-ai-sdk-plugin-openai';

const { chat } = useChat({
  api: {
    chatEndpoint: 'your-chat-endpoint',
  },
  mode: 'stream',
  streamFormat: 'incremental',
  // 引入 OpenAI 插件
  plugins: [new OpenAIPlugin()],
});
js
import { ChatMixin } from '@tencent/ssv-ai-sdk-vue2';
import { OpenAIPlugin } from '@tencent/ssv-ai-sdk-plugin-openai';

export default {
  mixins: [
    ChatMixin({
      api: {
        chatEndpoint: 'your-chat-endpoint',
      },
      mode: 'stream',
      streamFormat: 'incremental',
      // 引入 OpenAI 插件
      plugins: [new OpenAIPlugin()],
    }),
  ],
};
js
const { ChatBehavior } = require('@tencent/ssv-ai-sdk-miniprogram');
const { OpenAIPlugin } = require('@tencent/ssv-ai-sdk-plugin-openai');

Component({
  behaviors: [
    ChatBehavior({
      api: {
        chatEndpoint: 'your-chat-endpoint',
      },
      mode: 'stream',
      streamFormat: 'incremental',
      // 引入 OpenAI 插件
      plugins: [new OpenAIPlugin()],
    }),
  ],
});

Released under the MIT License.