import OpenAI from 'openai';

const baseUrl="https://wishub-x1.ctyun.cn/v1" //api前缀地址
//从环境变量获取API密钥，如果没有设置，也可以直接终端执行export XIRANG_app_key="xxx"
// const appkey= process.env.XIRANG_app_key
const modelId="xxxxx" //模型id
const question="你好啊,给一篇100字左右的作文" //对话问题


const client = new OpenAI({
    apiKey: appkey,
    baseURL:baseUrl
});

async function chatCompletion() {
    const completion = await client.chat.completions.create({
        model: modelId,
        messages: [{ role: 'user', content: question }],
    });
    console.log(completion.choices[0]?.message?.content);
}

chatCompletion();
