换 ai apikey
This commit is contained in:
35
server2.js
35
server2.js
@@ -121,9 +121,13 @@ app.use(express.urlencoded({ extended: true })); // 支持 form-data 字段
|
|||||||
// 初始化客户端
|
// 初始化客户端
|
||||||
|
|
||||||
const client = new OpenAI({
|
const client = new OpenAI({
|
||||||
|
//apiKey: "4pJOKPLhkW7qJQOeQBe9ACXyBrcu7A8bAjTgo2auV5lSUZbmcn1rJQQJ99CEACHYHv6XJ3w3AAAAACOGk1hV",
|
||||||
|
//baseURL: "https://tech-mp6cvddb-eastus2.cognitiveservices.azure.com/",
|
||||||
|
//apiKey: "DxvRiQWROzLTapiSHcK0FXKAAXDBlhci1XaqTTpr50sgUsAkmxfUJQQJ99BIACYeBjFXJ3w3AAABACOGZdHp",
|
||||||
apiKey: "DxvRiQWROzLTapiSHcK0FXKAAXDBlhci1XaqTTpr50sgUsAkmxfUJQQJ99BIACYeBjFXJ3w3AAABACOGZdHp",
|
apiKey: "DxvRiQWROzLTapiSHcK0FXKAAXDBlhci1XaqTTpr50sgUsAkmxfUJQQJ99BIACYeBjFXJ3w3AAABACOGZdHp",
|
||||||
baseURL: "https://satabot.openai.azure.com/openai/deployments/gpt-4.1",
|
baseURL: "https://satabot.services.ai.azure.com/openai/v1/",
|
||||||
defaultQuery: { "api-version": "2024-04-01-preview" },
|
//baseURL: "https://satabot.openai.azure.com/openai/deployments/gpt-4.1",
|
||||||
|
//defaultQuery: { "api-version": "2024-04-01-preview" },
|
||||||
timeout: 120000,
|
timeout: 120000,
|
||||||
fetch: fetchIPv4, // 关键点:把自定义 fetch 注入 SDK
|
fetch: fetchIPv4, // 关键点:把自定义 fetch 注入 SDK
|
||||||
// 确保底层也传 agent(可选,但保险)
|
// 确保底层也传 agent(可选,但保险)
|
||||||
@@ -132,9 +136,14 @@ const client = new OpenAI({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const client1 = new OpenAI({
|
const client1 = new OpenAI({
|
||||||
|
//apiKey: "4pJOKPLhkW7qJQOeQBe9ACXyBrcu7A8bAjTgo2auV5lSUZbmcn1rJQQJ99CEACHYHv6XJ3w3AAAAACOGk1hV",
|
||||||
|
//baseURL: "https://tech-mp6cvddb-eastus2.cognitiveservices.azure.com/",
|
||||||
|
//apiKey: "DxvRiQWROzLTapiSHcK0FXKAAXDBlhci1XaqTTpr50sgUsAkmxfUJQQJ99BIACYeBjFXJ3w3AAABACOGZdHp",
|
||||||
apiKey: "DxvRiQWROzLTapiSHcK0FXKAAXDBlhci1XaqTTpr50sgUsAkmxfUJQQJ99BIACYeBjFXJ3w3AAABACOGZdHp",
|
apiKey: "DxvRiQWROzLTapiSHcK0FXKAAXDBlhci1XaqTTpr50sgUsAkmxfUJQQJ99BIACYeBjFXJ3w3AAABACOGZdHp",
|
||||||
baseURL: "https://satabot.openai.azure.com/openai/deployments/gpt-5-mini/",
|
baseURL: "https://satabot.services.ai.azure.com/openai/v1/",
|
||||||
defaultQuery: { "api-version": "2024-04-01-preview" },
|
|
||||||
|
//baseURL: "https://satabot.openai.azure.com/openai/deployments/gpt-5-mini/",
|
||||||
|
//defaultQuery: { "api-version": "2024-04-01-preview" },
|
||||||
timeout: 120000,
|
timeout: 120000,
|
||||||
fetch: fetchIPv4, // 关键点:把自定义 fetch 注入 SDK
|
fetch: fetchIPv4, // 关键点:把自定义 fetch 注入 SDK
|
||||||
// 确保底层也传 agent(可选,但保险)
|
// 确保底层也传 agent(可选,但保险)
|
||||||
@@ -160,8 +169,8 @@ async function directCall() {
|
|||||||
console.timeEnd("directCall");
|
console.timeEnd("directCall");
|
||||||
}
|
}
|
||||||
|
|
||||||
test1();
|
//test1();
|
||||||
directCall();
|
//directCall();
|
||||||
|
|
||||||
// 获取 access_token
|
// 获取 access_token
|
||||||
// getAccessToken();
|
// getAccessToken();
|
||||||
@@ -2317,8 +2326,7 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
|
|
||||||
console.log("====== 开始图像分析55... ======");
|
console.log("====== 开始图像分析55... ======");
|
||||||
|
|
||||||
if (imageBase64)
|
if (imageBase64) {
|
||||||
{
|
|
||||||
const imageAnalysisMessages = [
|
const imageAnalysisMessages = [
|
||||||
{
|
{
|
||||||
role: "system",
|
role: "system",
|
||||||
@@ -2350,7 +2358,8 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
{
|
{
|
||||||
role: "user",
|
role: "user",
|
||||||
content: [
|
content: [
|
||||||
{ type: "text", text:
|
{
|
||||||
|
type: "text", text:
|
||||||
`
|
`
|
||||||
输出格式要求(固定话术,仅替换【】内容,必须1句完整文本):
|
输出格式要求(固定话术,仅替换【】内容,必须1句完整文本):
|
||||||
用户上传了一张【图片类型】的图片,从图片描述来看,这明显是一个【场景属性】的图片,有【标注特征】的特点。
|
用户上传了一张【图片类型】的图片,从图片描述来看,这明显是一个【场景属性】的图片,有【标注特征】的特点。
|
||||||
@@ -2375,7 +2384,7 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
|
|
||||||
// 去掉max_tokens限制,保证描述完整
|
// 去掉max_tokens限制,保证描述完整
|
||||||
const completion = await client.chat.completions.create({
|
const completion = await client.chat.completions.create({
|
||||||
model: "gpt-4.1",
|
model: "gpt-5.6-luna",
|
||||||
stream: true,
|
stream: true,
|
||||||
messages: imageAnalysisMessages
|
messages: imageAnalysisMessages
|
||||||
});
|
});
|
||||||
@@ -2430,7 +2439,7 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
{ role: "assistant", content: sceneText } // 传入精准场景描述
|
{ role: "assistant", content: sceneText } // 传入精准场景描述
|
||||||
];
|
];
|
||||||
const thinkingStream = await client.chat.completions.create({
|
const thinkingStream = await client.chat.completions.create({
|
||||||
model: "gpt-4",
|
model: "gpt-5.6-luna",
|
||||||
stream: true,
|
stream: true,
|
||||||
messages: thinkingMessages,
|
messages: thinkingMessages,
|
||||||
max_completion_tokens: 1500, // 根据需要调整
|
max_completion_tokens: 1500, // 根据需要调整
|
||||||
@@ -2486,7 +2495,7 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const answerStream = await client.chat.completions.create({
|
const answerStream = await client.chat.completions.create({
|
||||||
model: "gpt-4",
|
model: "gpt-5.6-luna",
|
||||||
stream: true,
|
stream: true,
|
||||||
messages: answerMessages
|
messages: answerMessages
|
||||||
});
|
});
|
||||||
@@ -2534,7 +2543,7 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const titlePrompt = `请根据以下对话内容生成一个简短的标题(不超过15字):\n用户问题: ${userPrompt}\nAI回答: ${llmText}`;
|
const titlePrompt = `请根据以下对话内容生成一个简短的标题(不超过15字):\n用户问题: ${userPrompt}\nAI回答: ${llmText}`;
|
||||||
const titleResp = await client1.chat.completions.create({
|
const titleResp = await client1.chat.completions.create({
|
||||||
model: "gpt-5-mini",
|
model: "gpt-5.6-luna",
|
||||||
messages: [
|
messages: [
|
||||||
{ role: "system", content: "你是标题生成助手,只返回标题,不要解释。" },
|
{ role: "system", content: "你是标题生成助手,只返回标题,不要解释。" },
|
||||||
{ role: "user", content: titlePrompt }
|
{ role: "user", content: titlePrompt }
|
||||||
|
|||||||
Reference in New Issue
Block a user