(
_messages: ChatMessage[],
signal: AbortSignal,
options: LLMFullCompletionOptions = {},
messageOptions?: MessageOption,
)
| 1093 | |
| 1094 | // Update the streamChat method: |
| 1095 | async *streamChat( |
| 1096 | _messages: ChatMessage[], |
| 1097 | signal: AbortSignal, |
| 1098 | options: LLMFullCompletionOptions = {}, |
| 1099 | messageOptions?: MessageOption, |
| 1100 | ): AsyncGenerator<ChatMessage, PromptLog> { |
| 1101 | this.lastRequestId = undefined; |
| 1102 | |
| 1103 | // Apply per-model tool overrides if configured |
| 1104 | let effectiveTools = options.tools; |
| 1105 | if (this.toolOverrides?.length && options.tools?.length) { |
| 1106 | const { tools: overriddenTools, errors } = applyToolOverrides( |
| 1107 | options.tools, |
| 1108 | this.toolOverrides, |
| 1109 | ); |
| 1110 | effectiveTools = overriddenTools; |
| 1111 | // Log any warnings for unknown tool names |
| 1112 | for (const error of errors) { |
| 1113 | if (!error.fatal) { |
| 1114 | console.warn(`Tool override warning: ${error.message}`); |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | // Use effectiveTools for the rest of this method |
| 1120 | const optionsWithOverrides = { ...options, tools: effectiveTools }; |
| 1121 | |
| 1122 | let { completionOptions, logEnabled } = |
| 1123 | this._parseCompletionOptions(optionsWithOverrides); |
| 1124 | const interaction = logEnabled |
| 1125 | ? this.logger?.createInteractionLog() |
| 1126 | : undefined; |
| 1127 | let status: InteractionStatus = "in_progress"; |
| 1128 | |
| 1129 | completionOptions = this._modifyCompletionOptions(completionOptions); |
| 1130 | |
| 1131 | let messages = _messages; |
| 1132 | |
| 1133 | // If not precompiled, compile the chat messages |
| 1134 | if (!messageOptions?.precompiled) { |
| 1135 | const { compiledChatMessages } = compileChatMessages({ |
| 1136 | modelName: completionOptions.model, |
| 1137 | msgs: _messages, |
| 1138 | knownContextLength: this._contextLength, |
| 1139 | maxTokens: completionOptions.maxTokens ?? DEFAULT_MAX_TOKENS, |
| 1140 | supportsImages: this.supportsImages(), |
| 1141 | tools: optionsWithOverrides.tools, |
| 1142 | }); |
| 1143 | |
| 1144 | messages = compiledChatMessages; |
| 1145 | } |
| 1146 | |
| 1147 | const messagesCopy = [...messages]; // templateMessages may modify messages. |
| 1148 | |
| 1149 | const prompt = this.templateMessages |
| 1150 | ? this.templateMessages(messagesCopy) |
| 1151 | : this._formatChatMessages(messagesCopy); |
| 1152 |
nothing calls this directly
no test coverage detected