MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / createStream

Function createStream

src/api/providers/base-openai-compatible-provider.ts:70–111  ·  view source on GitHub ↗
(
		systemPrompt: string,
		messages: Anthropic.Messages.MessageParam[],
		metadata?: ApiHandlerCreateMessageMetadata,
		requestOptions?: OpenAI.RequestOptions,
	)

Source from the content-addressed store, hash-verified

68 }
69
70 protected createStream(
71 systemPrompt: string,
72 messages: Anthropic.Messages.MessageParam[],
73 metadata?: ApiHandlerCreateMessageMetadata,
74 requestOptions?: OpenAI.RequestOptions,
75 ) {
76 const { id: model, info } = this.getModel()
77
78 // Centralized cap: clamp to 20% of the context window (unless provider-specific exceptions apply)
79 const max_tokens =
80 getModelMaxOutputTokens({
81 modelId: model,
82 model: info,
83 settings: this.options,
84 format: "openai",
85 }) ?? undefined
86
87 const temperature = this.options.modelTemperature ?? info.defaultTemperature ?? this.defaultTemperature
88
89 const params: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = {
90 model,
91 max_tokens,
92 temperature,
93 messages: [{ role: "system", content: systemPrompt }, ...convertToOpenAiMessages(messages)],
94 stream: true,
95 stream_options: { include_usage: true },
96 tools: this.convertToolsForOpenAI(metadata?.tools),
97 tool_choice: metadata?.tool_choice,
98 parallel_tool_calls: metadata?.parallelToolCalls ?? true,
99 }
100
101 // Add thinking parameter if reasoning is enabled and model supports it
102 if (this.options.enableReasoningEffort && info.supportsReasoningBinary) {
103 ;(params as any).thinking = { type: "enabled" }
104 }
105
106 try {
107 return this.client.chat.completions.create(params, requestOptions)
108 } catch (error) {
109 throw handleOpenAIError(error, this.providerName)
110 }
111 }
112
113 override async *createMessage(
114 systemPrompt: string,

Callers

nothing calls this directly

Calls 5

getModelMaxOutputTokensFunction · 0.90
convertToOpenAiMessagesFunction · 0.90
handleOpenAIErrorFunction · 0.90
getModelMethod · 0.65
createMethod · 0.45

Tested by

no test coverage detected