明树Git Lab

Commit 3b841d47 authored by zfp1's avatar zfp1

update

parent 4847908d
...@@ -3,5 +3,4 @@ node_modules/ ...@@ -3,5 +3,4 @@ node_modules/
package-lock.json package-lock.json
.vscode .vscode
test/ test/
test.js
public/avatar public/avatar
\ No newline at end of file
const axios = require('axios');
async function callDashScope() {
// 若没有配置环境变量,可用百炼API Key将下行替换为:apiKey='sk-xxx'。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
const apiKey = "sk-0ff2fc43671f4ed28dd7c80289da04e7";
const appId = '6de1065c75074ee1a11238ab90c1aa34';// 替换为实际的应用 ID
const url = `https://dashscope.aliyuncs.com/api/v1/apps/${appId}/completion`;
const data = {
input: {
prompt: "你是谁?"
},
parameters: {},
debug: {}
};
try {
const response = await axios.post(url, data, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
});
if (response.status === 200) {
console.log(`${response.data.output.text}`);
} else {
console.log(`request_id=${response.headers['request_id']}`);
console.log(`code=${response.status}`);
console.log(`message=${response.data.message}`);
}
} catch (error) {
console.error(`Error calling DashScope: ${error.message}`);
if (error.response) {
console.error(`Response status: ${error.response.status}`);
console.error(`Response data: ${JSON.stringify(error.response.data, null, 2)}`);
}
}
}
callDashScope();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment