MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / chatCompletion

Function chatCompletion

src/tools/semantic-navigate.ts:71–103  ·  view source on GitHub ↗
(prompt: string)

Source from the content-addressed store, hash-verified

69}
70
71async function chatCompletion(prompt: string): Promise<string> {
72 if (EMBED_PROVIDER === "openai") {
73 const url = `${OPENAI_BASE_URL.replace(/\/+$/, "")}/chat/completions`;
74 const response = await fetch(url, {
75 method: "POST",
76 headers: {
77 "Content-Type": "application/json",
78 "Authorization": `Bearer ${OPENAI_API_KEY}`,
79 },
80 body: JSON.stringify({
81 model: OPENAI_CHAT_MODEL,
82 messages: [{ role: "user", content: prompt }],
83 stream: false,
84 }),
85 });
86
87 if (!response.ok) {
88 const body = await response.text().catch(() => "");
89 throw new Error(`OpenAI chat API error ${response.status}: ${body}`);
90 }
91
92 const data = await response.json() as { choices: { message: { content: string } }[] };
93 return data.choices[0]?.message?.content ?? "";
94 }
95
96 const client = await getOllamaClient();
97 const response = await client.chat({
98 model: CHAT_MODEL,
99 messages: [{ role: "user", content: prompt }],
100 stream: false,
101 });
102 return response.message.content;
103}
104
105async function embedFilesWithFallback(files: FileInfo[]): Promise<{ files: FileInfo[]; vectors: number[][]; skipped: number }> {
106 if (files.length === 0) return { files: [], vectors: [], skipped: 0 };

Callers 2

labelSiblingClustersFunction · 0.85
semanticNavigateFunction · 0.85

Calls 1

getOllamaClientFunction · 0.70

Tested by

no test coverage detected