This commit is contained in:
2025-10-27 22:56:57 +08:00
parent b7e1af9b10
commit 79f755630d

36
src/test.ts Normal file
View File

@@ -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();