Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
whiterabbit1983 committed Aug 28, 2024
1 parent c57f412 commit 8529ad5
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 26 deletions.
64 changes: 64 additions & 0 deletions sdks/ts/src/agents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Agents_CreateAgentRequest, Common_uuid, Agents_UpdateAgentRequest, Common_limit, Common_offset, Agents_PatchAgentRequest, Docs_VectorDocSearchRequest, Docs_TextOnlyDocSearchRequest, Docs_HybridDocSearchRequest } from "./api";
import { JulepApiClient } from "./api/JulepApiClient";

export class AgentsRoutes {
constructor(private apiClient: JulepApiClient) { }

async create({ requestBody }: { requestBody: Agents_CreateAgentRequest }) {
return await this.apiClient.default.agentsRouteCreate({ requestBody })
}

async createOrUpdate({ id, requestBody }: { id: Common_uuid, requestBody: Agents_UpdateAgentRequest }) {
return await this.apiClient.default.agentsRouteCreateOrUpdate({ id, requestBody })
}

async delete({ id }: { id: Common_uuid }) {
return await this.apiClient.default.agentsRouteDelete({ id })
}

async get({ id }: { id: Common_uuid }) {
return await this.apiClient.default.agentsRouteGet({ id })
}

async list({
limit = 100,
offset,
sortBy = "created_at",
direction = "asc",
metadataFilter = "{}",
}: {
limit?: Common_limit;
offset: Common_offset;
sortBy?: "created_at" | "updated_at";
direction?: "asc" | "desc";
metadataFilter?: string;
}) {
return await this.apiClient.default.agentsRouteList({ limit, offset, sortBy, direction, metadataFilter })
}

async patch({ id, requestBody }: {
id: Common_uuid;
requestBody: Agents_PatchAgentRequest;
}) {
return await this.apiClient.default.agentsRoutePatch({ id, requestBody })
}

async update({ id, requestBody }: {
id: Common_uuid;
requestBody: Agents_UpdateAgentRequest;
}) {
return await this.apiClient.default.agentsRouteUpdate({ id, requestBody })
}

async searchDocs({ id, requestBody }: {
id: Common_uuid;
requestBody: {
body:
| Docs_VectorDocSearchRequest
| Docs_TextOnlyDocSearchRequest
| Docs_HybridDocSearchRequest;
};
}) {
return await this.apiClient.default.agentsDocsSearchRouteSearch({ id, requestBody })
}
}
44 changes: 26 additions & 18 deletions sdks/ts/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import { OpenAI } from "openai";
import { Chat, Completions } from "openai/resources/index";
import typia, { tags } from "typia";

import { AgentsManager } from "./managers/agent";
import { UsersManager } from "./managers/user";
import { DocsManager } from "./managers/doc";
import { MemoriesManager } from "./managers/memory";
import { SessionsManager } from "./managers/session";
import { ToolsManager } from "./managers/tool";
// import { AgentsManager } from "./managers/agent";
// import { UsersManager } from "./managers/user";
// import { DocsManager } from "./managers/doc";
// import { MemoriesManager } from "./managers/memory";
// import { SessionsManager } from "./managers/session";
// import { ToolsManager } from "./managers/tool";
import { AgentsRoutes } from "./agents";
import { JulepApiClient } from "./api";
import { JULEP_API_KEY, JULEP_API_URL } from "./env";
import { patchCreate } from "./utils/openaiPatch";
import { UsersRoutes } from "./users";

interface ClientOptions {
apiKey?: string;
Expand Down Expand Up @@ -57,53 +59,59 @@ export class Client {
dangerouslyAllowBrowser: true,
});

this.agents = new AgentsManager(this._apiClient);
this.users = new UsersManager(this._apiClient);
this.sessions = new SessionsManager(this._apiClient);
this.docs = new DocsManager(this._apiClient);
this.memories = new MemoriesManager(this._apiClient);
this.tools = new ToolsManager(this._apiClient);
// this.agents = new AgentsManager(this._apiClient);
// this.users = new UsersManager(this._apiClient);
// this.sessions = new SessionsManager(this._apiClient);
// this.docs = new DocsManager(this._apiClient);
// this.memories = new MemoriesManager(this._apiClient);
// this.tools = new ToolsManager(this._apiClient);
this.agents = new AgentsRoutes(this._apiClient)
this.users = new UsersRoutes(this._apiClient)
this.chat = this._openaiClient.chat;
patchCreate(this.chat.completions, this.chat);
this.completions = this._openaiClient.completions;
patchCreate(this.completions);
}

get apiClient() {
return this._apiClient
}

/**
* Manager for interacting with agents.
* Provides methods to manage and interact with agents within the Julep API.
*/
agents: AgentsManager;
agents: AgentsRoutes;

/**
* Manager for interacting with users.
* Offers functionalities to handle user accounts and their data.
*/
users: UsersManager;
users: UsersRoutes;

/**
* Manager for interacting with sessions.
* Facilitates the creation, management, and retrieval of user sessions.
*/
sessions: SessionsManager;
// sessions: SessionsManager;

/**
* Manager for interacting with documents.
* Enables document management including creation, update, and deletion.
*/
docs: DocsManager;
// docs: DocsManager;

/**
* Manager for interacting with memories.
* Allows for storing and retrieving user-specific data and preferences.
*/
memories: MemoriesManager;
// memories: MemoriesManager;

/**
* Manager for interacting with tools.
* Provides access to various utility tools and functionalities.
*/
tools: ToolsManager;
// tools: ToolsManager;

/**
* OpenAI Chat API.
Expand Down
61 changes: 61 additions & 0 deletions sdks/ts/src/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { JulepApiClient } from "./api/JulepApiClient";
import { Users_CreateUserRequest, Common_uuid, Users_UpdateUserRequest, Common_limit, Common_offset, Users_PatchUserRequest } from "./api";

export class UsersRoutes {
constructor(private apiClient: JulepApiClient) { }

async create({ requestBody }: {
requestBody: Users_CreateUserRequest;
}) {
return await this.apiClient.default.usersRouteCreate({ requestBody })
}

async createOrUpdate({ id, requestBody }: {
id: Common_uuid;
requestBody: Users_UpdateUserRequest;
}) {
return await this.apiClient.default.usersRouteCreateOrUpdate({ id, requestBody })
}

async delete({ id }: {
id: Common_uuid;
}) {
return await this.apiClient.default.usersRouteDelete({ id })
}

async get({ id }: {
id: Common_uuid;
}) {
return await this.apiClient.default.usersRouteGet({ id })
}

async list({
limit = 100,
offset,
sortBy = "created_at",
direction = "asc",
metadataFilter = "{}",
}: {
limit?: Common_limit;
offset: Common_offset;
sortBy?: "created_at" | "updated_at";
direction?: "asc" | "desc";
metadataFilter?: string;
}) {
return await this.apiClient.default.usersRouteList({ limit, offset, sortBy, direction, metadataFilter })
}

async patch({ id, requestBody }: {
id: Common_uuid;
requestBody: Users_PatchUserRequest;
}) {
return this.apiClient.default.usersRoutePatch({ id, requestBody })
}

async update({id, requestBody}: {
id: Common_uuid;
requestBody: Users_UpdateUserRequest;
}) {
return await this.apiClient.default.usersRouteUpdate({id, requestBody})
}
}
7 changes: 5 additions & 2 deletions sdks/ts/tests/agents.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// agents.test.ts

import { describe, expect, test } from "@jest/globals";
import { Agent } from "../src/api";
import { Agents_Agent as Agent } from "../src/api";

import { setupClient } from "./fixtures";

Expand All @@ -25,7 +25,10 @@ describe("Julep Client Tests", () => {
let testAgent: Partial<Agent> & { id: string };

test("agents.create", async () => {
const response = await client.agents.create(mockAgent);
const response = await client.apiClient.default.createAgent({
mockAgent
});
// const response = await client.agents.create(mockAgent);

testAgent = response;

Expand Down
2 changes: 1 addition & 1 deletion sdks/ts/tests/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { afterAll, beforeAll, describe, expect, test } from "@jest/globals";

import { setupClient } from "./fixtures";
import { Client } from "../src";
import { Agent, User } from "../src/api";
import { Agents_Agent as Agent, Users_User as User } from "../src/api";

describe("Julep Client Tests", () => {
let client: Client;
Expand Down
2 changes: 1 addition & 1 deletion sdks/ts/tests/memories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { afterAll, beforeAll, describe, expect, test } from "@jest/globals";

import { setupClient } from "./fixtures";
import { Client } from "../src";
import { Agent, User } from "../src/api";
import { Agents_Agent as Agent, Users_User as User } from "../src/api";

describe("Julep Client Tests", () => {
let client: Client;
Expand Down
2 changes: 1 addition & 1 deletion sdks/ts/tests/sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { afterAll, beforeAll, describe, expect, it } from "@jest/globals";

import { setupClient } from "./fixtures"; // Adjust path if necessary
import { Agent, User } from "../src/api";
import { Agents_Agent as Agent, Users_User as User } from "../src/api";
import { Client } from "../src";

const { TEST_MODEL } = process.env;
Expand Down
2 changes: 1 addition & 1 deletion sdks/ts/tests/simpleExample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { beforeEach, describe, expect, it } from "@jest/globals";

import { setupClient } from "./fixtures";
import { Client } from "../src";
import { InputChatMLMessage } from "../src/api";
import { Entries_InputChatMLMessage as InputChatMLMessage } from "../src/api";

const { TEST_MODEL } = process.env;

Expand Down
2 changes: 1 addition & 1 deletion sdks/ts/tests/tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { afterAll, beforeAll, describe, expect, it, test } from "@jest/globals";

import { setupClient } from "./fixtures"; // Adjust the path as necessary
import { Client } from "../src";
import { Agent, Tool } from "../src/api";
import { Agents_Agent as Agent, Tools_Tool as Tool } from "../src/api";

describe("Tools API", () => {
let client: Client;
Expand Down
2 changes: 1 addition & 1 deletion sdks/ts/tests/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { beforeAll, describe, expect, test } from "@jest/globals";

import { setupClient } from "./fixtures";
import { Client } from "../src";
import { User } from "../src/api";
import { Users_User as User } from "../src/api";

const mockUser = {
name: "test user",
Expand Down

0 comments on commit 8529ad5

Please sign in to comment.