MCPcopy Index your code
hub / github.com/MatterAIOrg/OrbCode / createMessage

Method createMessage

src/api/client.ts:64–206  ·  view source on GitHub ↗
(
    systemPrompt: string,
    messages: OpenAI.Chat.ChatCompletionMessageParam[],
    tools: OpenAI.Chat.ChatCompletionTool[],
    abortSignal?: AbortSignal,
  )

Source from the content-addressed store, hash-verified

62 }
63
64 async *createMessage(
65 systemPrompt: string,
66 messages: OpenAI.Chat.ChatCompletionMessageParam[],
67 tools: OpenAI.Chat.ChatCompletionTool[],
68 abortSignal?: AbortSignal,
69 ): AsyncGenerator<ApiStreamChunk> {
70 const model = getModel(this.options.modelId);
71
72 const requestOptions: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming =
73 {
74 model: model.id,
75 temperature: 0.2,
76 messages: [
77 { role: "system", content: systemPrompt },
78 ...stripReasoningDetails(messages),
79 ],
80 stream: true,
81 stream_options: { include_usage: true },
82 max_tokens: model.maxOutputTokens,
83 };
84 if (tools.length > 0) {
85 requestOptions.tools = tools;
86 requestOptions.tool_choice = "auto";
87 requestOptions.parallel_tool_calls = true;
88 }
89
90 const stream = await this.client.chat.completions.create(requestOptions, {
91 headers: this.requestHeaders(),
92 signal: abortSignal,
93 });
94
95 let lastUsage: CompletionUsage | undefined;
96 let inferenceProvider: string | undefined;
97 let fullContent = "";
98 let isThinking = false;
99
100 for await (const chunk of stream) {
101 // The gateway may return an error object instead of throwing.
102 if ("error" in chunk) {
103 const error = (chunk as { error?: { message?: string; code?: number } })
104 .error;
105 const err = new Error(
106 `Axon API Error ${error?.code ?? ""}: ${error?.message ?? "unknown error"}`,
107 );
108 (err as { status?: number }).status = error?.code;
109 throw err;
110 }
111
112 if (
113 "provider" in chunk &&
114 typeof (chunk as { provider?: string }).provider === "string"
115 ) {
116 inferenceProvider = (chunk as { provider?: string }).provider;
117 }
118
119 if (chunk.usage) {
120 lastUsage = chunk.usage as CompletionUsage;
121 }

Callers

nothing calls this directly

Calls 4

requestHeadersMethod · 0.95
getTotalCostMethod · 0.95
getModelFunction · 0.85
stripReasoningDetailsFunction · 0.85

Tested by

no test coverage detected