import got from 'got'; | |
async function CloudFlareQwenTogether(message, { system_prompt = "" } = {}) { | |
const run = await got.post(`https://api.cloudflare.com/client/v4/accounts/${process.env['ACCOUNT_ID']}/ai/run/@cf/qwen/qwen1.5-1.8b-chat`, { | |
headers: { | |
'Authorization': `Bearer ${process.env['CLOUDFLARE_API_KEY']}`, | |
'Content-Type': 'application/json' | |
}, | |
json: { | |
'messages': [ | |
{"role": "system", "content": system_prompt}, | |
{"role": "user", "content": message} | |
], | |
'max_tokens': 200, | |
'stream': false | |
} | |
}).json(); | |
return run.result.response; | |
} | |
async function AlibabaTogether(message, { system_prompt = "" } = {}) { | |
const response = await got.post('https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions', { | |
headers: { | |
'Authorization': 'Bearer ' + process.env['ALIBABA_API_KEY'], | |
'Content-Type': 'application/json' | |
}, | |
json: { | |
'model': 'qwen-plus', | |
'messages': [ | |
{"role": "system", "content": system_prompt}, | |
{'role': 'user', 'content': message} | |
], | |
'temperature': 0.7, | |
'top_p': 0.7, | |
'repetition_penalty': 1, | |
'stream': false | |
} | |
}).json(); | |
return response.choices[0].message.content; | |
} | |
export { | |
AlibabaTogether, | |
CloudFlareQwenTogether | |
}; |