Skip to content

Commit 458ea58

Browse files
Add abortSignal
1 parent d4768b3 commit 458ea58

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

shared/llm/llm.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export interface GenerateTextOptions extends CallSettings {
8585
id?: string;
8686
thinking?: ThinkingLevel;
8787
providerOptions?: Record<string, any>;
88+
abortSignal?: AbortSignal;
8889
}
8990

9091
/**

shared/llm/llm.schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ const GenerateTextOptionsSpecificSchema = Type.Object({
175175
id: Type.Optional(Type.String()),
176176
thinking: Type.Optional(Type.Union([Type.Literal('none'), Type.Literal('low'), Type.Literal('medium'), Type.Literal('high')])),
177177
providerOptions: Type.Optional(Type.Record(Type.String(), Type.Any())),
178+
abortSignal: Type.Optional(Type.Any()),
178179
});
179180

180181
export const GenerateTextOptionsSchema = Type.Intersect([CallSettingsSchema, GenerateTextOptionsSpecificSchema], { $id: 'GenerateTextOptions' });

src/llm/services/ai-llm.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,17 @@ export abstract class AiLLM<Provider extends ProviderV2> extends BaseLLM {
246246
console.log(new Error(`No generateMessage id provided. (${promptPreview})`));
247247
}
248248

249+
const settingsToSave = { ...combinedOpts };
250+
settingsToSave.abortSignal = undefined;
251+
249252
const createLlmCallRequest: CreateLlmRequest = {
250253
messages: cloneAndTruncateBuffers(llmMessages),
251254
llmId: this.getId(),
252255
agentId: agentContext()?.agentId,
253256
// userId: currentUser().id,
254257
callStack: callStack(),
255258
description,
256-
settings: combinedOpts,
259+
settings: settingsToSave,
257260
};
258261
const llmCall: LlmCall = await this.saveLlmCallRequest(createLlmCallRequest);
259262

@@ -272,7 +275,7 @@ export abstract class AiLLM<Provider extends ProviderV2> extends BaseLLM {
272275
maxRetries: combinedOpts.maxRetries,
273276
maxOutputTokens: combinedOpts.maxOutputTokens,
274277
providerOptions: combinedOpts.providerOptions,
275-
// abortSignal: combinedOpts.abortSignal,
278+
abortSignal: (combinedOpts as any)?.abortSignal,
276279
};
277280
// Messages can be large, and model property with schemas, so just log the reference to the LlmCall its saved in
278281
logger.info({ args: { ...args, messages: `LlmCall:${llmCall.id}`, model: this.getId() } }, `Generating text - ${opts?.id}`);
@@ -414,12 +417,15 @@ export abstract class AiLLM<Provider extends ProviderV2> extends BaseLLM {
414417
service: this.service,
415418
});
416419

420+
const settingsToSave = { ...combinedOpts };
421+
settingsToSave.abortSignal = undefined;
422+
417423
const createLlmCallRequest: CreateLlmRequest = {
418424
messages: llmMessages,
419425
llmId: this.getId(),
420426
agentId: agentContext()?.agentId,
421427
callStack: callStack(),
422-
settings: combinedOpts,
428+
settings: settingsToSave,
423429
};
424430
const llmCall: LlmCall = await this.saveLlmCallRequest(createLlmCallRequest);
425431

@@ -430,7 +436,7 @@ export abstract class AiLLM<Provider extends ProviderV2> extends BaseLLM {
430436
const args: StreamTextArgs = {
431437
model: this.aiModel(),
432438
messages,
433-
// abortSignal: combinedOpts?.abortSignal,
439+
abortSignal: combinedOpts?.abortSignal,
434440
temperature: combinedOpts?.temperature,
435441
// topP: combinedOpts?.topP, // anthropic '`temperature` and `top_p` cannot both be specified for this model. Please use only one.'
436442
stopSequences: combinedOpts?.stopSequences,

0 commit comments

Comments
 (0)