MCPcopy Create free account
hub / github.com/CCCpan/ai-api-integration / chat

Function chat

src/node/chat.js:31–51  ·  view source on GitHub ↗
(userMessage)

Source from the content-addressed store, hash-verified

29let history = [];
30
31async function chat(userMessage) {
32 history.push({ role: "user", content: userMessage });
33 try {
34 const stream = await client.chat.completions.create({
35 model,
36 messages: history,
37 stream: true,
38 });
39 let reply = "";
40 for await (const chunk of stream) {
41 const delta = chunk.choices[0]?.delta?.content || "";
42 process.stdout.write(delta);
43 reply += delta;
44 }
45 process.stdout.write("\n");
46 history.push({ role: "assistant", content: reply });
47 } catch (err) {
48 history.pop();
49 console.error(`error: ${err.message}`);
50 }
51}
52
53async function generateImage(prompt) {
54 try {

Callers 1

promptFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected