Skip to content

Commit

Permalink
Merge pull request #7 from homanp/tools
Browse files Browse the repository at this point in the history
Tools
  • Loading branch information
homanp authored Jun 6, 2023
2 parents a949427 + e0e2467 commit 54de235
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ await superagent.agents().create({
name: "Ny agent",
llm: {
provider: "openai-chat",
model: "gpt-3.5-turbo",
model: "gpt-4",
api_key: process.env.OPENAI_API_KEY,
},
has_memory: true,
promptId: "<PROMPT_ID>",
documentId: "<DOCUMENT_ID>",
toolId: "<TOOL_ID>",
});

// Run an agent
Expand All @@ -72,6 +75,25 @@ await superagent.agents().predict({
});
```

### Tools

```javascript
// List all tools
await superagent.tools().list();

// Retuns a specific tool
await superagent.tools().get("<TOOL_ID>");

// Delete tool
await superagent.tools().delete("<TOOL_ID>");

// Create tool
await superagent.tools().create({
name: "My tool",
type: "SEARCH",
});
```

### Documents

```javascript
Expand Down
11 changes: 11 additions & 0 deletions src/superagent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ declare module 'superagentSDK' {
authorization?: string | null;
}

interface Tool {
name: string;
type: string;
}

interface Agent {
name: string;
llm: string;
Expand Down Expand Up @@ -49,5 +54,11 @@ declare module 'superagentSDK' {
create(agent: Agent): Promise<any>;
predict(prediction: Prediction): Promise<any>;
};
tools(): {
delete(id: string): Promise<any>;
list(): Promise<any>;
get(id: string): Promise<any>;
create(tool: Tool): Promise<any>;
}
}
}
13 changes: 13 additions & 0 deletions src/superagent.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,17 @@ export default class SuperagentSDK {
}),
};
}

tools() {
return {
delete: async (id) => await this._request("DELETE", `/tools/${id}`),
list: async () => await this._request("GET", "/tools"),
get: async (id) => await this._request("GET", `/tools/${id}`),
create: async ({ name, type = "SEARCH" }) =>
await this._request("POST", "/tools", {
name,
type,
}),
};
}
}
37 changes: 37 additions & 0 deletions test/sdk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,43 @@ describe("Prompts", () => {
});
});

describe("Tools", () => {
let tool;

it("should create a tool", async () => {
const { success, data } = await superagent.tools().create({
name: "My test tool",
type: "SEARCH",
});

tool = data;

expect(success).to.equal(true);
expect(data).to.be.an("object");
});

it("should retrieve a list of tools", async () => {
const { success, data } = await superagent.tools().list();

expect(success).to.equal(true);
expect(data).to.be.an("array");
});

it("should retrieve a single tool", async () => {
const { success, data } = await superagent.tools().get(tool.id);

expect(success).to.equal(true);
expect(data).to.be.an("object");
});

it("should delete a single tool", async () => {
const { success, data } = await superagent.tools().delete(tool.id);

expect(success).to.equal(true);
expect(data).to.equal(null);
});
});

describe("Documents", () => {
let document;

Expand Down

0 comments on commit 54de235

Please sign in to comment.