Skip to content

Commit

Permalink
feat: add LlamaIndex TS framework support
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekpatil4 committed Jan 10, 2025
1 parent f33976d commit b7a8481
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 40 deletions.
2 changes: 1 addition & 1 deletion js/src/frameworks/llamaindex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("Apps class tests", () => {
let llamaindexToolSet: LlamaIndexToolSet;
beforeAll(() => {
llamaindexToolSet = new LlamaIndexToolSet({
apiKey: getTestConfig().COMPOSIO_API_KEY,
apiKey: getTestConfig().COMPOSIO_API_KEY,
baseUrl: getTestConfig().BACKEND_HERMES_URL,
});
});
Expand Down
40 changes: 1 addition & 39 deletions js/src/frameworks/llamaindex.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FunctionTool, OpenAI, OpenAIAgent, type JSONValue } from "llamaindex";
import { FunctionTool, type JSONValue } from "llamaindex";
import { z } from "zod";
import { ComposioToolSet as BaseComposioToolSet } from "../sdk/base.toolset";
import { COMPOSIO_BASE_URL } from "../sdk/client/core/OpenAPI";
Expand All @@ -15,7 +15,6 @@ export class LlamaIndexToolSet extends BaseComposioToolSet {
static FRAMEWORK_NAME = "llamaindex";
static DEFAULT_ENTITY_ID = "default";
fileName: string = "js/src/frameworks/llamaindex.ts";
private llm: OpenAI;

constructor(
config: {
Expand All @@ -31,9 +30,6 @@ export class LlamaIndexToolSet extends BaseComposioToolSet {
runtime: config?.runtime || null,
entityId: config.entityId || LlamaIndexToolSet.DEFAULT_ENTITY_ID,
});
this.llm = new OpenAI({
apiKey: config.apiKey || process.env.OPENAI_API_KEY,
});
}

private _wrapTool(
Expand Down Expand Up @@ -78,7 +74,6 @@ export class LlamaIndexToolSet extends BaseComposioToolSet {
const tools = await this.getToolsSchema(filters, entityId);
return tools.map((tool) => {
const wrappedTool = this._wrapTool(tool, entityId || this.entityId);
// Add additional properties for better logging
Object.assign(wrappedTool, {
name: tool.name,
description: tool.description,
Expand All @@ -87,37 +82,4 @@ export class LlamaIndexToolSet extends BaseComposioToolSet {
return wrappedTool;
});
}

async executeToolCall(
tool: { name: string; parameters: Record<string, unknown> },
entityId: Optional<string> = null
): Promise<string> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "executeToolCall",
file: this.fileName,
params: { tool, entityId },
});

return JSON.stringify(
await this.executeAction({
action: tool.name,
params: tool.parameters,
entityId: entityId || this.entityId,
})
);
}

async createAgent(
systemPrompt: string,
tools?: FunctionTool<Record<string, unknown>, Promise<string>>[],
entityId: Optional<string> = null
) {
const agentTools = tools || (await this.getTools({}, entityId));

return new OpenAIAgent({
llm: this.llm,
tools: agentTools,
systemPrompt,
});
}
}

0 comments on commit b7a8481

Please sign in to comment.