52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
import axios from 'axios';
|
||
import * as dotenv from 'dotenv';
|
||
dotenv.config();
|
||
|
||
const FASTGPT_API_URL = process.env.FASTGPT_API_URL!;
|
||
const FASTGPT_API_KEY = process.env.FASTGPT_API_KEY!;
|
||
const HTTPS_PROXY = process.env.HTTPS_PROXY;
|
||
|
||
async function test() {
|
||
console.log('API URL:', FASTGPT_API_URL);
|
||
console.log('代理:', HTTPS_PROXY || '无');
|
||
console.log('正在发送请求...\n');
|
||
|
||
const contentText = `考勤情况:全勤,无迟到缺卡\n\n工作汇总:本月完成了前端页面开发,项目顺利交付。\n\n考核项目:\n1. 【工作目标完成情况】(权重15分)\n 员工填写:已完成所有既定目标\n 自评分:90`;
|
||
|
||
const proxyConfig = HTTPS_PROXY ? (() => {
|
||
const url = new URL(HTTPS_PROXY);
|
||
return { host: url.hostname, port: parseInt(url.port, 10), protocol: 'http' as const };
|
||
})() : undefined;
|
||
|
||
try {
|
||
const response = await axios.post(
|
||
FASTGPT_API_URL,
|
||
{
|
||
messages: [{ role: 'user', content: contentText }],
|
||
variables: { zslh34AG: '前端工程师', month: '2026-04' },
|
||
stream: false,
|
||
},
|
||
{
|
||
headers: { Authorization: `Bearer ${FASTGPT_API_KEY}`, 'Content-Type': 'application/json' },
|
||
timeout: 60_000,
|
||
proxy: proxyConfig,
|
||
}
|
||
);
|
||
|
||
console.log('状态码:', response.status);
|
||
const content = response.data?.choices?.[0]?.message?.content;
|
||
console.log('content 类型:', typeof content);
|
||
console.log('content 内容:', typeof content === 'string' ? content.substring(0, 800) : JSON.stringify(content).substring(0, 800));
|
||
} catch (err: any) {
|
||
if (err.response) {
|
||
console.error('HTTP 状态码:', err.response.status);
|
||
console.error('响应体:', JSON.stringify(err.response.data, null, 2));
|
||
} else {
|
||
console.error('错误码:', err.code);
|
||
console.error('错误信息:', err.message);
|
||
}
|
||
}
|
||
}
|
||
|
||
test();
|