const _ = require('lodash'); const OpenAI = require('openai'); const API_KEY = 'YzRlYjhmYjEtZjI3Yi00ODAzLTk0OGMtN2VmYjY3M2I3MjA1'; const MODEL = 'DeepSeek-R1'; const HOST = 'https://opensseapi.cmft.com/CMHK-LMMP-PRD_DeepSeek_R1/CMHK-LMMP-PRD/v1'; const DEFAULT_OPTS = { temperature: 0 }; let dsConnector = async function (messages, llmSetting) { let apiKey = _.get(llmSetting, 'apiKey'); let host = _.get(llmSetting, 'host'); let model = _.get(llmSetting, 'model'); const openai = new OpenAI({ baseURL: host, apiKey, fetch: async (input, init = {}) => { const url = typeof input === 'string' ? input : input.url; const headers = init.headers || {}; const body = init.body; console.log('\n=== SDK request ==='); console.log('URL:', url); console.log('METHOD:', init.method); console.log('HEADERS:', headers); if (typeof body === 'string') { console.log('BODY:', body); } else { console.log('BODY type:', typeof body); } console.log('===================\n'); return fetch(input, init); }, }); return await openai.chat.completions.create({ messages, model, ...DEFAULT_OPTS, }); }; const run = async () => { let messages = [{role: 'user', content: 'Hello, how are you?'}]; let llmSetting = { apiKey: API_KEY, host: `${HOST}`, model: MODEL }; try { await dsConnector(messages, llmSetting); console.log('调用成功'); } catch (error) { console.log('调用失败', error.message); } }; run();