Skip to content

Commit

Permalink
feat: #ENG-1255
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-dixit committed Sep 12, 2024
1 parent a042c78 commit 01413d4
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 28 deletions.
8 changes: 8 additions & 0 deletions js/src/frameworks/cloudflare.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ describe("Apps class tests", () => {
expect(tools.length).toBe(1);
});

it("check if apps are coming", async () => {
const tools = await cloudflareToolSet.getTools({
actions: ['GITHUB_GITHUB_API_ROOT']
});

expect(tools.length).toBe(1);
});

});
8 changes: 6 additions & 2 deletions js/src/frameworks/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export class CloudflareToolSet extends BaseComposioToolSet {
);
}

/**
* @deprecated Use getTools instead.
*/
async getActions(filters: {
actions: Sequence<string>;
}): Promise<Sequence<AiTextGenerationToolInput>> {
Expand Down Expand Up @@ -74,7 +77,8 @@ export class CloudflareToolSet extends BaseComposioToolSet {
}

async getTools(filters: {
apps: Sequence<string>;
actions?: Optional<Sequence<string>>;
apps?: Sequence<string>;
tags?: Optional<Array<string>>;
useCase?: Optional<string>;
}): Promise<Sequence<AiTextGenerationToolInput>> {
Expand Down Expand Up @@ -122,7 +126,7 @@ export class CloudflareToolSet extends BaseComposioToolSet {
entityId: Optional<string> = null
): Promise<string> {
return JSON.stringify(
await this.executeAction(
await this.execute_action(
tool.name,
typeof tool.arguments === "string" ? JSON.parse(tool.arguments) : tool.arguments,
entityId || this.entityId
Expand Down
7 changes: 7 additions & 0 deletions js/src/frameworks/langchain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ describe("Apps class tests", () => {
expect(tools.length).toBe(1);
});

it("check if getTools, actions are coming", async () => {
const tools = await langchainToolSet.getTools({
actions: ['GITHUB_GITHUB_API_ROOT']
});

expect(tools.length).toBe(1)
});
});
8 changes: 6 additions & 2 deletions js/src/frameworks/langchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ export class LangchainToolSet extends BaseComposioToolSet {
});
}

/**
* @deprecated Use getTools instead.
*/
async getActions(
filters: {
actions?: Optional<Sequence<string>>
Expand All @@ -105,7 +108,7 @@ export class LangchainToolSet extends BaseComposioToolSet {
}

/**
* @deprecated Use getActions instead.
* @deprecated Use getTools instead.
*/
async get_actions(filters: {
actions?: Optional<Sequence<string>>
Expand All @@ -116,7 +119,8 @@ export class LangchainToolSet extends BaseComposioToolSet {

async getTools(
filters: {
apps: Sequence<string>;
actions?: Optional<Array<string>>;
apps?: Sequence<string>;
tags?: Optional<Array<string>>;
useCase?: Optional<string>;
},
Expand Down
8 changes: 8 additions & 0 deletions js/src/frameworks/openai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ describe("Apps class tests", () => {
expect(Object.keys(tools).length).toBe(1);
});

it("check if getTools -> actions are coming", async () => {
const tools = await openAIToolset.getTools({
actions: ['GITHUB_GITHUB_API_ROOT']
});

expect(Object.keys(tools).length).toBe(1);
});

});
8 changes: 6 additions & 2 deletions js/src/frameworks/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export class OpenAIToolSet extends BaseComposioToolSet {
);
}

/**
* @deprecated Use getTools instead.
*/
async getActions(
filters: { actions?: Optional<Sequence<string>> } = {},
entityId?: Optional<string>
Expand All @@ -56,7 +59,7 @@ export class OpenAIToolSet extends BaseComposioToolSet {
}

/**
* @deprecated Use getActions instead.
* @deprecated Use getTools instead.
*/
async get_actions(filters: {
actions?: Optional<Sequence<string>>
Expand All @@ -67,7 +70,8 @@ export class OpenAIToolSet extends BaseComposioToolSet {

async getTools(
filters: {
apps: Sequence<string>;
actions?: Sequence<string>;
apps?: Sequence<string>;
tags?: Optional<Array<string>>;
useCase?: Optional<string>;
},
Expand Down
7 changes: 1 addition & 6 deletions js/src/frameworks/vercel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { describe, it, expect, beforeAll } from "@jest/globals";
import { CloudflareToolSet } from "./cloudflare";
import { get } from "http";
import { getTestConfig } from "../../config/getTestConfig";
import { LangchainToolSet } from "./langchain";
import { OpenAIToolSet } from "./openai";
import { VercelAIToolSet } from "./vercel";


Expand All @@ -27,10 +23,9 @@ describe("Apps class tests", () => {
});

it("check if actions are coming", async () => {
const tools = await vercelAIToolSet.get_actions({
const tools = await vercelAIToolSet.getTools({
actions: ['GITHUB_GITHUB_API_ROOT']
});

expect(Object.keys(tools).length).toBe(1);
});

Expand Down
25 changes: 20 additions & 5 deletions js/src/frameworks/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,23 @@ export class VercelAIToolSet extends BaseComposioToolSet {

// change this implementation
async get_tools(filters: {
apps: Array<string>;
actions?: Array<string>
apps?: Array<string>;
tags?: Optional<Array<string>>;
useCase?: Optional<string>;
}): Promise<{ [key: string]: any }> {


const actionsList = await this.client.actions.list({
apps: filters.apps.join(","),
tags: filters.tags?.join(","),
filterImportantActions: !filters.tags && !filters.useCase,
useCase: filters.useCase || undefined,
...(filters?.apps && { apps: filters?.apps?.join(",") }),
...(filters?.tags && { tags: filters?.tags?.join(",") }),
...(filters?.useCase && { useCase: filters?.useCase }),
...(filters?.actions && { actions: filters?.actions?.join(",") }),
...(filters?.actions && { actions: filters?.actions?.join(",") }),
});



const tools = {};
actionsList.items?.forEach(actionSchema => {
// @ts-ignore
Expand All @@ -67,6 +73,15 @@ export class VercelAIToolSet extends BaseComposioToolSet {
return tools;
}

async getTools(filters: {
actions?: Sequence<string>
apps?: Array<string>;
tags?: Optional<Array<string>>;
useCase?: Optional<string>;
}): Promise<{ [key: string]: any }> {
return await this.get_tools(filters);
}

async execute_tool_call(
tool: { name: string; arguments: unknown; },
entityId: Optional<string> = null
Expand Down
24 changes: 13 additions & 11 deletions js/src/sdk/base.toolset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export class ComposioToolSet {

async getToolsSchema(
filters: {
apps: Sequence<string>;
actions?: Optional<Array<string>>;
apps?: Array<string>;
tags?: Optional<Array<string>>;
useCase?: Optional<string>;
},
Expand All @@ -120,18 +121,19 @@ export class ComposioToolSet {
await this.setup();

const apps = await this.client.actions.list({
apps: filters.apps.join(","),
tags: filters.tags?.join(","),
showAll: true,
filterImportantActions: !filters.tags && !filters.useCase,
useCase: filters.useCase || undefined
...(filters?.apps && { apps: filters?.apps?.join(",") }),
...(filters?.tags && { tags: filters?.tags?.join(",") }),
...(filters?.useCase && { useCase: filters?.useCase }),
...(filters?.actions && { actions: filters?.actions?.join(",") }),
});
const localActions = new Map<string, NonNullable<GetListActionsResponse["items"]>[0]>();
for (const appName of filters.apps!) {
const actionData = this.localActions?.filter((a: any) => a.appName === appName);
if(actionData) {
for (const action of actionData) {
localActions.set(action.name, action);
if(filters.apps && Array.isArray(filters.apps)) {
for (const appName of filters.apps!) {
const actionData = this.localActions?.filter((a: any) => a.appName === appName);
if(actionData) {
for (const action of actionData) {
localActions.set(action.name, action);
}
}
}
}
Expand Down

0 comments on commit 01413d4

Please sign in to comment.