-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: switch from client.actions to getToolsSchema #1174
base: master
Are you sure you want to change the base?
Changes from 2 commits
8e4f421
0eda3b1
806f9e1
755d346
d42dfda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { beforeAll, describe, expect, it } from "@jest/globals"; | ||
import { z } from "zod"; | ||
import { getTestConfig } from "../../config/getTestConfig"; | ||
import { ActionExecuteResponse } from "../sdk/models/actions"; | ||
import { VercelAIToolSet } from "./vercel"; | ||
|
||
describe("Apps class tests", () => { | ||
|
@@ -25,4 +27,34 @@ describe("Apps class tests", () => { | |
}); | ||
expect(Object.keys(tools).length).toBe(1); | ||
}); | ||
|
||
it("Should create custom action to star a repository", async () => { | ||
await vercelAIToolSet.createAction({ | ||
actionName: "starRepositoryCustomAction", | ||
toolName: "github", | ||
description: "This action stars a repository", | ||
inputParams: z.object({ | ||
owner: z.string(), | ||
repo: z.string(), | ||
}), | ||
callback: async ( | ||
inputParams, | ||
_authCredentials, | ||
executeRequest | ||
): Promise<ActionExecuteResponse> => { | ||
const res = await executeRequest({ | ||
endpoint: `/user/starred/${inputParams.owner}/${inputParams.repo}`, | ||
method: "PUT", | ||
parameters: [], | ||
}); | ||
return res; | ||
}, | ||
}); | ||
|
||
const tools = await vercelAIToolSet.getTools({ | ||
actions: ["starRepositoryCustomAction"], | ||
}); | ||
|
||
await expect(Object.keys(tools).length).toBe(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test case could benefit from additional assertions to verify the created action's properties. Consider adding checks for:
This would ensure the action is created correctly with all expected properties. |
||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { jsonSchema, tool } from "ai"; | ||
import { CoreTool, jsonSchema, tool } from "ai"; | ||
import { z } from "zod"; | ||
import { ComposioToolSet as BaseComposioToolSet } from "../sdk/base.toolset"; | ||
import { TELEMETRY_LOGGER } from "../sdk/utils/telemetry"; | ||
|
@@ -62,7 +62,7 @@ export class VercelAIToolSet extends BaseComposioToolSet { | |
useCase?: Optional<string>; | ||
usecaseLimit?: Optional<number>; | ||
filterByAvailableApps?: Optional<boolean>; | ||
}): Promise<{ [key: string]: RawActionData }> { | ||
}): Promise<{ [key: string]: CoreTool }> { | ||
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type of tools should be |
||
method: "getTools", | ||
file: this.fileName, | ||
|
@@ -78,25 +78,24 @@ export class VercelAIToolSet extends BaseComposioToolSet { | |
actions, | ||
} = ZExecuteToolCallParams.parse(filters); | ||
|
||
const actionsList = await this.client.actions.list({ | ||
...(apps && { apps: apps?.join(",") }), | ||
...(tags && { tags: tags?.join(",") }), | ||
...(useCase && { useCase: useCase }), | ||
...(actions && { actions: actions?.join(",") }), | ||
...(usecaseLimit && { usecaseLimit: usecaseLimit }), | ||
filterByAvailableApps: filterByAvailableApps ?? undefined, | ||
}); | ||
|
||
const tools = {}; | ||
actionsList.items?.forEach((actionSchema) => { | ||
// @ts-ignore | ||
tools[actionSchema.name!] = this.generateVercelTool( | ||
// @ts-ignore | ||
actionSchema as ActionData | ||
); | ||
}); | ||
const tools = await this.getToolsSchema( | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error handling for the const tools = await this.getToolsSchema(
{
apps,
tags,
useCase,
filterByAvailableApps,
actions,
useCaseLimit: usecaseLimit,
},
this.entityId
).catch(error => {
TELEMETRY_LOGGER.error('Failed to fetch tools schema', { error });
throw error;
}); |
||
apps, | ||
tags, | ||
useCase, | ||
filterByAvailableApps, | ||
actions, | ||
useCaseLimit: usecaseLimit, | ||
}, | ||
this.entityId | ||
); | ||
|
||
return tools; | ||
return Object.fromEntries( | ||
tools.map((tool) => [ | ||
tool.name, | ||
this.generateVercelTool(tool as RawActionData), | ||
]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type cast to |
||
); | ||
} | ||
|
||
async executeToolCall( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Quality: The added test case for creating a custom action to star a repository is a good addition. However, ensure that the test case is complete and follows the existing test structure. Consider adding assertions to verify the expected behavior of the
createAction
method. This will enhance the test's robustness and ensure it validates the intended functionality effectively.🔧 Suggested Code Diff:
📝 Committable Code Suggestion