-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,35 @@ | ||
// Load tools here | ||
import { BaseTool } from "llamaindex"; | ||
import config from "./tool_config.json"; | ||
|
||
enum ExternalTool { | ||
GoogleSearch = "google.GoogleSearchToolSpec", | ||
Wikipedia = "wikipedia.WikipediaToolSpec", | ||
} | ||
|
||
type ToolConfig = { [key in ExternalTool]: Record<string, any> }; | ||
|
||
export default class ToolFactory { | ||
private static async createTool( | ||
key: ExternalTool, | ||
options: Record<string, any> | ||
): Promise<BaseTool> { | ||
if (key === ExternalTool.Wikipedia) { | ||
const WikipediaTool = (await import("llamaindex")).WikipediaTool; | ||
const tool = new WikipediaTool(); | ||
return tool; | ||
} | ||
|
||
// TODO: Implement GoogleSearchToolSpec | ||
|
||
throw new Error(`Sorry! Tool ${key} is not supported yet. Options: ${options}`); | ||
} | ||
|
||
public static async list(): Promise<BaseTool[]> { | ||
const tools: BaseTool[] = []; | ||
for (const [key, value] of Object.entries(config as ToolConfig)) { | ||
const tool = await ToolFactory.createTool(key as ExternalTool, value); | ||
tools.push(tool); | ||
} | ||
return tools; | ||
} | ||
} |