diff --git a/src/test.ts b/src/test.ts new file mode 100644 index 0000000..56314be --- /dev/null +++ b/src/test.ts @@ -0,0 +1,36 @@ +import dotenv from 'dotenv'; +dotenv.config(); + +const token = process.env.BAILIAN_API_KEY || ''; + +const chat = async (message: { role: string, content: string }[]) => { + const baseURL = 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions'; + + return fetch(baseURL, { method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}` + }, + body: JSON.stringify({ + // model: 'qwen-turbo-latest', + model: 'qwen2.5-7b-instruct-1m', + messages: message, + response_format: { + type: 'json_object' + }, + stream: false + }) + }).then(res => res.json()); +}; + +const main = async () => { + const contnet = `我提供我的的用户名是abc,密码是1234567822, 返回我JSON数据,内容是{username, password},不要返回我多余的其他信息。` + const messages = [ + { role: 'user', content: contnet } + ]; + + const res = await chat(messages); + console.log('返回结果:', res.choices[0].message.content); +} + +main(); \ No newline at end of file