Skip to content
Snippets Groups Projects
Unverified Commit fececd89 authored by Thuc Pham's avatar Thuc Pham Committed by GitHub
Browse files

feat: add tool factory (#663)

parent 48e28789
No related branches found
No related tags found
No related merge requests found
---
"llamaindex": patch
---
feat: add tool factory
import type { BaseTool } from "../types.js";
import { WikipediaTool } from "./WikipediaTool.js";
enum Tools {
Wikipedia = "wikipedia.WikipediaToolSpec",
}
type ToolConfig = { [key in Tools]: Record<string, any> };
export class ToolFactory {
private static async createTool(
key: Tools,
options: Record<string, any>,
): Promise<BaseTool> {
if (key === Tools.Wikipedia) {
const tool = new WikipediaTool();
return tool;
}
throw new Error(
`Sorry! Tool ${key} is not supported yet. Options: ${options}`,
);
}
public static async createTools(config: ToolConfig): Promise<BaseTool[]> {
const tools: BaseTool[] = [];
for (const [key, value] of Object.entries(config as ToolConfig)) {
const tool = await ToolFactory.createTool(key as Tools, value);
tools.push(tool);
}
return tools;
}
}
export * from "./QueryEngineTool.js";
export * from "./ToolFactory.js";
export * from "./WikipediaTool.js";
export * from "./functionTool.js";
export * from "./types.js";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment