diff --git a/examples/nodejs/examples/pipes/memory.create.ts b/examples/nodejs/examples/pipes/memory.create.ts new file mode 100644 index 0000000..76c1394 --- /dev/null +++ b/examples/nodejs/examples/pipes/memory.create.ts @@ -0,0 +1,16 @@ +import 'dotenv/config'; +import {Memory} from 'langbase'; + +const memory = new Memory({ + apiKey: process.env.LANGBASE_API_KEY!, +}); + +async function main() { + const response = await memory.create({ + name: 'sdk-memory', + }); + + console.log(response); +} + +main(); diff --git a/examples/nodejs/examples/pipes/memory.list.ts b/examples/nodejs/examples/pipes/memory.list.ts new file mode 100644 index 0000000..93b6a74 --- /dev/null +++ b/examples/nodejs/examples/pipes/memory.list.ts @@ -0,0 +1,13 @@ +import 'dotenv/config'; +import {Memory} from 'langbase'; + +const memory = new Memory({ + apiKey: process.env.LANGBASE_API_KEY!, +}); + +async function main() { + const response = await memory.list(); + console.log(response); +} + +main(); diff --git a/examples/nodejs/package.json b/examples/nodejs/package.json index d78d159..390f4b3 100644 --- a/examples/nodejs/package.json +++ b/examples/nodejs/package.json @@ -8,7 +8,10 @@ "scripts": { "generate-text": "npx tsx ./examples/pipes/generate-text.ts", "pipe.create": "npx tsx ./examples/pipes/pipe.create.ts", + "memory.create": "npx tsx ./examples/pipes/memory.create.ts", + "memory.list": "npx tsx ./examples/pipes/memory.list.ts", "pipe.update": "npx tsx ./examples/pipes/pipe.update.ts", + "pipe.list": "npx tsx ./examples/pipes/pipe.list.ts", "pipe.run": "npx tsx ./examples/pipes/pipe.run.ts", "pipe.run.stream": "npx tsx ./examples/pipes/pipe.run.stream.ts", "generate-text-generate-pipe": "npx tsx ./examples/pipes/generate-text-generate-pipe.ts", diff --git a/packages/langbase/src/index.ts b/packages/langbase/src/index.ts index f91e4c4..89c5a13 100644 --- a/packages/langbase/src/index.ts +++ b/packages/langbase/src/index.ts @@ -1,5 +1,6 @@ export {fromReadableStream} from './lib/browser/stream'; export * from './pipes/pipes'; +export * from './memory/memory'; export * from '@baseai/core/helpers'; export type { RunOptions, diff --git a/packages/langbase/src/memory/memory.ts b/packages/langbase/src/memory/memory.ts new file mode 100644 index 0000000..571f7d8 --- /dev/null +++ b/packages/langbase/src/memory/memory.ts @@ -0,0 +1,42 @@ +import {Request} from '../common/request'; + +export interface MemoryOptions { + apiKey: string; +} + +interface MemoryBaseResponse { + name: string; + description: string; + owner_login: string; + url: string; +} + +export interface MemoryCreateOptions { + name: string; + description?: string; +} + +export interface MemoryCreateResponse extends MemoryBaseResponse {} +export interface MemoryListResponse extends MemoryBaseResponse {} + +export class Memory { + private request: Request; + + constructor(options: MemoryOptions) { + const baseUrl = 'https://api.langbase.com'; + this.request = new Request({apiKey: options.apiKey, baseUrl}); + } + + async create(options: MemoryCreateOptions): Promise { + return this.request.post({ + endpoint: '/v1/memory', + body: options, + }); + } + + async list(): Promise { + return this.request.get({ + endpoint: '/v1/memory', + }); + } +} diff --git a/packages/langbase/src/pipes/pipes.ts b/packages/langbase/src/pipes/pipes.ts index e5d4430..5764c3e 100644 --- a/packages/langbase/src/pipes/pipes.ts +++ b/packages/langbase/src/pipes/pipes.ts @@ -112,7 +112,7 @@ interface ToolChoice { function: {name: string}; } -interface BaseOptions { +interface PipeBaseOptions { name: string; description?: string; status?: 'public' | 'private'; @@ -145,7 +145,43 @@ interface BaseOptions { }[]; } -interface BaseResponse { +export interface PipeListResponse { + name: string; + description: string; + status: 'public' | 'private'; + owner_login: string; + url: string; + model: string; + stream: boolean; + json: boolean; + store: boolean; + moderate: boolean; + top_p: number; + max_tokens: number; + temperature: number; + presence_penalty: number; + frequency_penalty: number; + stop: string[]; + tool_choice: 'auto' | 'required' | ToolChoice; + parallel_tool_calls: boolean; + messages: Message[]; + variables: Variable[] | []; + tools: + | { + type: 'function'; + function: { + name: string; + description?: string; + parameters?: Record; + }; + }[] + | []; + memory: { + name: string; + }[] | []; +} + +interface PipeBaseResponse { name: string; description: string; status: 'public' | 'private'; @@ -155,10 +191,10 @@ interface BaseResponse { api_key: string; } -export interface CreateOptions extends BaseOptions {} -export interface UpdateOptions extends BaseOptions {} -export interface CreateResponse extends BaseResponse {} -export interface UpdateResponse extends BaseResponse {} +export interface PipeCreateOptions extends PipeBaseOptions {} +export interface PipeUpdateOptions extends PipeBaseOptions {} +export interface PipeCreateResponse extends PipeBaseResponse {} +export interface PipeUpdateResponse extends PipeBaseResponse {} export class Pipe { private request: Request; @@ -207,21 +243,21 @@ export class Pipe { }); } - async create(options: CreateOptions): Promise { + async create(options: PipeCreateOptions): Promise { return this.request.post({ endpoint: '/v1/pipes', body: options, }); } - async update(options: UpdateOptions): Promise { + async update(options: PipeUpdateOptions): Promise { return this.request.post({ endpoint: `/v1/pipes/${options.name}`, body: options, }); } - async list() { + async list(): Promise { return this.request.get({ endpoint: '/v1/pipes', });