MCPcopy
hub / github.com/OpenPipe/OpenPipe / getOpenaiCompletion

Function getOpenaiCompletion

app/src/server/utils/openai.ts:47–67  ·  view source on GitHub ↗
(
  projectId: string,
  input: ChatCompletionCreateParams,
)

Source from the content-addressed store, hash-verified

45 input: ChatCompletionCreateParams,
46): Promise<ChatCompletion | Stream<ChatCompletionChunk>>;
47export async function getOpenaiCompletion(
48 projectId: string,
49 input: ChatCompletionCreateParams,
50): Promise<ChatCompletion | Stream<ChatCompletionChunk>> {
51 const apiKeys = await prisma.apiKey.findMany({
52 where: { projectId: projectId },
53 });
54
55 const openaiApiKey = apiKeys.find((key) => key.provider === "OPENAI")?.apiKey;
56
57 if (!openaiApiKey) {
58 throw new Error("No OpenAI API key found");
59 }
60
61 const openai = new OriginalOpenAI({ apiKey: openaiApiKey });
62
63 return await openai.chat.completions.create({
64 ...input,
65 tools: input.tools?.length ? input.tools : undefined,
66 });
67}
68
69// Fall back to our own Azure instance for long-running requests
70export async function getAzureGpt4Completion(input: ChatCompletionCreateParams) {

Calls 1

createMethod · 0.45

Tested by

no test coverage detected