repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import OpenAI from 'openai'; |
| #2 | |
| #3 | import { config } from './constants'; |
| #4 | |
| #5 | /** |
| #6 | * OpenAI 客户端实例 |
| #7 | * 用于各种 AI 生成任务,如分类、翻译、内容生成等 |
| #8 | */ |
| #9 | export const openai = new OpenAI({ |
| #10 | apiKey: process.env.OPENAI_API_KEY, |
| #11 | baseURL: process.env.OPENAI_PROXY_URL, |
| #12 | maxRetries: 4, // 最大重试次数 |
| #13 | }); |
| #14 | |
| #15 | /** |
| #16 | * 调用 OpenAI Chat Completion API |
| #17 | * @param messages 消息数组 |
| #18 | * @param options 可选参数 |
| #19 | * @returns 生成的回复内容 |
| #20 | */ |
| #21 | export const callOpenAI = async ( |
| #22 | messages: Array<{ content: string; role: 'system' | 'user' | 'assistant' }>, |
| #23 | options?: { |
| #24 | model?: string; |
| #25 | response_format?: { type: 'json_object' }; |
| #26 | temperature?: number; |
| #27 | }, |
| #28 | ) => { |
| #29 | const response = await openai.chat.completions.create({ |
| #30 | messages, |
| #31 | model: options?.model || config.modelName, |
| #32 | response_format: options?.response_format, |
| #33 | temperature: options?.temperature ?? config.temperature, |
| #34 | }); |
| #35 | |
| #36 | return response.choices[0]?.message?.content || ''; |
| #37 | }; |
| #38 | |
| #39 | |
| #40 |