Skip to content

Latest commit

 

History

History
48 lines (35 loc) · 1.04 KB

hunyuan.md

File metadata and controls

48 lines (35 loc) · 1.04 KB

混元助手

在这里获取你的 API密钥

通用对话

当前支持 hunyuan 模型。

import { HunYuanAI } from '@zhengxs/ai';

const client = new HunYuanAI({
  appId: 'My APP ID', // defaults to process.env["HUNYUAN_APP_ID"]
  secretId: 'My Secret ID', // defaults to process.env["HUNYUAN_SECRET_ID"]
  secretKey: 'My Secret Key', // defaults to process.env["HUNYUAN_SECRET_KEY"]
});

async function main() {
  const chatCompletion = await client.chat.completions.create({
    model: 'hunyuan',
    messages: [{ role: 'user', content: 'Say this is a test' }],
  });
}

main();

支持流式

import { HunYuanAI } from '@zhengxs/ai';

const client = new HunYuanAI();

async function main() {
  const stream = await client.chat.completions.create({
    model: 'hunyuan',
    messages: [{ role: 'user', content: 'Say this is a test' }],
    stream: true,
  });

  for await (const chunk of stream) {
    process.stdout.write(chunk.choices[0]?.delta?.content || '');
  }
}

main();