From d917cdc3fa3303f884b026391eadf0eb8d7e67c8 Mon Sep 17 00:00:00 2001
From: Thuc Pham <51660321+thucpn@users.noreply.github.com>
Date: Tue, 23 Jul 2024 16:04:36 +0700
Subject: [PATCH] feat: add azure interpreter tool to tool factory (#1064)

---
 .changeset/tasty-seahorses-sit.md              |  5 +++++
 .../src/tools/AzureDynamicSessionTool.node.ts  |  8 +++-----
 packages/llamaindex/src/tools/ToolsFactory.ts  | 18 ++++++++++++++++--
 3 files changed, 24 insertions(+), 7 deletions(-)
 create mode 100644 .changeset/tasty-seahorses-sit.md

diff --git a/.changeset/tasty-seahorses-sit.md b/.changeset/tasty-seahorses-sit.md
new file mode 100644
index 000000000..259d33d33
--- /dev/null
+++ b/.changeset/tasty-seahorses-sit.md
@@ -0,0 +1,5 @@
+---
+"llamaindex": patch
+---
+
+Add azure interpreter tool to tool factory
diff --git a/packages/llamaindex/src/tools/AzureDynamicSessionTool.node.ts b/packages/llamaindex/src/tools/AzureDynamicSessionTool.node.ts
index aaf6bb7c5..c83c362b5 100644
--- a/packages/llamaindex/src/tools/AzureDynamicSessionTool.node.ts
+++ b/packages/llamaindex/src/tools/AzureDynamicSessionTool.node.ts
@@ -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.");
     }
   }
 
diff --git a/packages/llamaindex/src/tools/ToolsFactory.ts b/packages/llamaindex/src/tools/ToolsFactory.ts
index eb650463f..791ee8456 100644
--- a/packages/llamaindex/src/tools/ToolsFactory.ts
+++ b/packages/llamaindex/src/tools/ToolsFactory.ts
@@ -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(
-- 
GitLab