Skip to content
Merged
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
16 changes: 16 additions & 0 deletions examples/nodejs/examples/pipes/memory.create.ts
Original file line number Diff line number Diff line change
@@ -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();
13 changes: 13 additions & 0 deletions examples/nodejs/examples/pipes/memory.list.ts
Original file line number Diff line number Diff line change
@@ -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();
3 changes: 3 additions & 0 deletions examples/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/langbase/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
42 changes: 42 additions & 0 deletions packages/langbase/src/memory/memory.ts
Original file line number Diff line number Diff line change
@@ -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<MemoryCreateResponse> {
return this.request.post({
endpoint: '/v1/memory',
body: options,
});
}

async list(): Promise<MemoryListResponse[]> {
return this.request.get({
endpoint: '/v1/memory',
});
}
}
54 changes: 45 additions & 9 deletions packages/langbase/src/pipes/pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ interface ToolChoice {
function: {name: string};
}

interface BaseOptions {
interface PipeBaseOptions {
name: string;
description?: string;
status?: 'public' | 'private';
Expand Down Expand Up @@ -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<string, any>;
};
}[]
| [];
memory: {
name: string;
}[] | [];
}

interface PipeBaseResponse {
name: string;
description: string;
status: 'public' | 'private';
Expand All @@ -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;
Expand Down Expand Up @@ -207,21 +243,21 @@ export class Pipe {
});
}

async create(options: CreateOptions): Promise<CreateResponse> {
async create(options: PipeCreateOptions): Promise<PipeCreateResponse> {
return this.request.post({
endpoint: '/v1/pipes',
body: options,
});
}

async update(options: UpdateOptions): Promise<UpdateResponse> {
async update(options: PipeUpdateOptions): Promise<PipeUpdateResponse> {
return this.request.post({
endpoint: `/v1/pipes/${options.name}`,
body: options,
});
}

async list() {
async list(): Promise<PipeListResponse[]> {
return this.request.get({
endpoint: '/v1/pipes',
});
Expand Down
Loading