(prompt: string, apiKey: string, model: string, timeout = 30000)
| 1 | import { ChatOpenAI } from "@langchain/openai" |
| 2 | |
| 3 | export async function callOpenAI(prompt: string, apiKey: string, model: string, timeout = 30000): Promise<string> { |
| 4 | const client = new ChatOpenAI({ modelName: model, openAIApiKey: apiKey, timeout }) |
| 5 | const res = await client.invoke(prompt) |
| 6 | return typeof res.content === "string" ? res.content : Array.isArray(res.content) ? res.content.map((c: any) => (typeof c === "string" ? c : c.text || "")).join("") : JSON.stringify(res.content) |
| 7 | } |
nothing calls this directly
no outgoing calls
no test coverage detected