Skip to content

Commit

Permalink
fix: abort signal propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamwhiteuk committed Sep 20, 2024
1 parent e0e9095 commit 42b0020
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/tools/imageDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class ImageDescriptionTool extends Tool<StringToolOutput, ToolOptions, To
const imageDescriptionOutput = await this.requestImageDescriptionForURL(
input.imageUrl,
input.prompt,
_options?.signal,
);

return new StringToolOutput(
Expand Down Expand Up @@ -107,7 +108,7 @@ export class ImageDescriptionTool extends Tool<StringToolOutput, ToolOptions, To
});
}

protected async queryVllmAPI(completionPrompt: VllmChatCompletionPrompt) {
protected async queryVllmAPI(completionPrompt: VllmChatCompletionPrompt, signal?: AbortSignal) {
const vllmApiUrl = new URL("/v1/chat/completions", this.vllmApiEndpoint);
const headers = {
"accept": "application/json",
Expand All @@ -120,6 +121,7 @@ export class ImageDescriptionTool extends Tool<StringToolOutput, ToolOptions, To
method: "POST",
body: JSON.stringify(completionPrompt),
headers: headers,
signal: signal,
});

if (!vllmResponse.ok) {
Expand Down Expand Up @@ -149,7 +151,11 @@ export class ImageDescriptionTool extends Tool<StringToolOutput, ToolOptions, To
*
* @returns A String description of the image.
*/
protected async requestImageDescriptionForURL(imageUrl: string, prompt: string): Promise<any> {
protected async requestImageDescriptionForURL(
imageUrl: string,
prompt: string,
signal?: AbortSignal,
): Promise<any> {
const modelPrompt: VllmChatCompletionPrompt = {
model: this.vllmApiModelId,
messages: [
Expand All @@ -163,7 +169,7 @@ export class ImageDescriptionTool extends Tool<StringToolOutput, ToolOptions, To
],
};

const modelResponse = await this.queryVllmAPI(modelPrompt);
const modelResponse = await this.queryVllmAPI(modelPrompt, signal);
return modelResponse;
}
}

0 comments on commit 42b0020

Please sign in to comment.