update
This commit is contained in:
36
src/test.ts
Normal file
36
src/test.ts
Normal 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();
|
||||
Reference in New Issue
Block a user