Skip to content
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: add custom Tool.createFromFunc method #15

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .fernignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Specify files that shouldn't be modified by Fern

tests/custom.test.ts
.github/workflows/ci.yml
.github/workflows/ci.yml
src/wrapper
src/index.ts
2 changes: 1 addition & 1 deletion src/api/resources/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./client";
export * from "./client";
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * as Letta from "./api";
export { LettaClient } from "./Client";
export { LettaClient } from "./wrapper/Client";
export { LettaEnvironment } from "./environments";
export { LettaError, LettaTimeoutError } from "./errors";
11 changes: 11 additions & 0 deletions src/wrapper/Client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { LettaClient as FernClient } from "../Client";
import { Tools } from "./ToolsClient";

export class LettaClient extends FernClient {

protected _tools: Tools | undefined;

public get tools(): Tools {
return (this._tools ??= new Tools(this._options));
}
}
34 changes: 34 additions & 0 deletions src/wrapper/ToolsClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import dedent from 'dedent';

Check failure on line 1 in src/wrapper/ToolsClient.ts

View workflow job for this annotation

GitHub Actions / compile

Could not find a declaration file for module 'dedent'. '/home/runner/work/letta-node/letta-node/node_modules/dedent/dist/dedent.js' implicitly has an 'any' type.

import { Letta } from "..";
import { Tools as FernTools } from "../api/resources/tools/client/Client";

export class Tools extends FernTools {
/**
* Create a new tool from a function
*
* @param {ToolCreateFromFunction} request
* @param {Tools.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Letta.UnprocessableEntityError}
*
* @example
* await client.tools.create({
* func: tool_implementation
* })
*/
public async createFromFunction(
request: ToolCreateFromFunction,
requestOptions?: FernTools.RequestOptions
): Promise<Letta.LettaSchemasToolTool> {
const toolCreateRequest: Letta.ToolCreate = {
...request,
sourceCode: dedent(request.func.toString()),
};
return this.create(toolCreateRequest, requestOptions);
}
}

export interface ToolCreateFromFunction extends Omit<Letta.ToolCreate, "sourceCode"> {
func: Function;
}
Loading