feat: add azure interpreter tool to tool factory (#1064)

This commit is contained in:
Thuc Pham
2024-07-23 16:04:36 +07:00
committed by GitHub
parent b370edf329
commit d917cdc3fa
3 changed files with 24 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"llamaindex": patch
---
Add azure interpreter tool to tool factory
@@ -177,7 +177,7 @@ export class AzureDynamicSessionTool
/**
* The endpoint of the Azure pool management service.
* This is where the tool will send requests to interact with the session pool.
* If not provided, the tool will use the value of the `AZURE_CONTAINER_APP_SESSION_POOL_MANAGEMENT_ENDPOINT` environment variable.
* If not provided, the tool will use the value of the `AZURE_POOL_MANAGEMENT_ENDPOINT` environment variable.
*/
private poolManagementEndpoint: string;
@@ -191,14 +191,12 @@ export class AzureDynamicSessionTool
this.sessionId = params?.sessionId || randomUUID();
this.poolManagementEndpoint =
params?.poolManagementEndpoint ||
(getEnv("AZURE_CONTAINER_APP_SESSION_POOL_MANAGEMENT_ENDPOINT") ?? "");
(getEnv("AZURE_POOL_MANAGEMENT_ENDPOINT") ?? "");
this.azureADTokenProvider =
params?.azureADTokenProvider ?? getAzureADTokenProvider();
if (!this.poolManagementEndpoint) {
throw new Error(
"AZURE_CONTAINER_APP_SESSION_POOL_MANAGEMENT_ENDPOINT must be defined.",
);
throw new Error("AZURE_POOL_MANAGEMENT_ENDPOINT must be defined.");
}
}
+16 -2
View File
@@ -1,12 +1,18 @@
import { WikipediaTool } from "./WikipediaTool.js";
import {
AzureDynamicSessionTool,
type AzureDynamicSessionToolParams,
} from "./AzureDynamicSessionTool.node.js";
import { WikipediaTool, type WikipediaToolParams } from "./WikipediaTool.js";
export namespace ToolsFactory {
type ToolsMap = {
[Tools.Wikipedia]: typeof WikipediaTool;
[Tools.AzureCodeInterpreter]: typeof AzureDynamicSessionTool;
};
export enum Tools {
Wikipedia = "wikipedia.WikipediaToolSpec",
AzureCodeInterpreter = "azure_code_interpreter.AzureCodeInterpreterToolSpec",
}
export async function createTool<Tool extends Tools>(
@@ -14,7 +20,15 @@ export namespace ToolsFactory {
...params: ConstructorParameters<ToolsMap[Tool]>
): Promise<InstanceType<ToolsMap[Tool]>> {
if (key === Tools.Wikipedia) {
return new WikipediaTool(...params) as InstanceType<ToolsMap[Tool]>;
return new WikipediaTool(
...(params as WikipediaToolParams[]),
) as InstanceType<ToolsMap[Tool]>;
}
if (key === Tools.AzureCodeInterpreter) {
return new AzureDynamicSessionTool(
...(params as AzureDynamicSessionToolParams[]),
) as InstanceType<ToolsMap[Tool]>;
}
throw new Error(