Skip to content

Commit 504f2ee

Browse files
authored
📦 NEW: Memory create and list support (#75)
1 parent 7f301db commit 504f2ee

File tree

6 files changed

+120
-9
lines changed

6 files changed

+120
-9
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'dotenv/config';
2+
import {Memory} from 'langbase';
3+
4+
const memory = new Memory({
5+
apiKey: process.env.LANGBASE_API_KEY!,
6+
});
7+
8+
async function main() {
9+
const response = await memory.create({
10+
name: 'sdk-memory',
11+
});
12+
13+
console.log(response);
14+
}
15+
16+
main();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'dotenv/config';
2+
import {Memory} from 'langbase';
3+
4+
const memory = new Memory({
5+
apiKey: process.env.LANGBASE_API_KEY!,
6+
});
7+
8+
async function main() {
9+
const response = await memory.list();
10+
console.log(response);
11+
}
12+
13+
main();

examples/nodejs/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"scripts": {
99
"generate-text": "npx tsx ./examples/pipes/generate-text.ts",
1010
"pipe.create": "npx tsx ./examples/pipes/pipe.create.ts",
11+
"memory.create": "npx tsx ./examples/pipes/memory.create.ts",
12+
"memory.list": "npx tsx ./examples/pipes/memory.list.ts",
1113
"pipe.update": "npx tsx ./examples/pipes/pipe.update.ts",
14+
"pipe.list": "npx tsx ./examples/pipes/pipe.list.ts",
1215
"pipe.run": "npx tsx ./examples/pipes/pipe.run.ts",
1316
"pipe.run.stream": "npx tsx ./examples/pipes/pipe.run.stream.ts",
1417
"generate-text-generate-pipe": "npx tsx ./examples/pipes/generate-text-generate-pipe.ts",

packages/langbase/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export {fromReadableStream} from './lib/browser/stream';
22
export * from './pipes/pipes';
3+
export * from './memory/memory';
34
export * from '@baseai/core/helpers';
45
export type {
56
RunOptions,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {Request} from '../common/request';
2+
3+
export interface MemoryOptions {
4+
apiKey: string;
5+
}
6+
7+
interface MemoryBaseResponse {
8+
name: string;
9+
description: string;
10+
owner_login: string;
11+
url: string;
12+
}
13+
14+
export interface MemoryCreateOptions {
15+
name: string;
16+
description?: string;
17+
}
18+
19+
export interface MemoryCreateResponse extends MemoryBaseResponse {}
20+
export interface MemoryListResponse extends MemoryBaseResponse {}
21+
22+
export class Memory {
23+
private request: Request;
24+
25+
constructor(options: MemoryOptions) {
26+
const baseUrl = 'https://api.langbase.com';
27+
this.request = new Request({apiKey: options.apiKey, baseUrl});
28+
}
29+
30+
async create(options: MemoryCreateOptions): Promise<MemoryCreateResponse> {
31+
return this.request.post({
32+
endpoint: '/v1/memory',
33+
body: options,
34+
});
35+
}
36+
37+
async list(): Promise<MemoryListResponse[]> {
38+
return this.request.get({
39+
endpoint: '/v1/memory',
40+
});
41+
}
42+
}

packages/langbase/src/pipes/pipes.ts

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ interface ToolChoice {
112112
function: {name: string};
113113
}
114114

115-
interface BaseOptions {
115+
interface PipeBaseOptions {
116116
name: string;
117117
description?: string;
118118
status?: 'public' | 'private';
@@ -145,7 +145,43 @@ interface BaseOptions {
145145
}[];
146146
}
147147

148-
interface BaseResponse {
148+
export interface PipeListResponse {
149+
name: string;
150+
description: string;
151+
status: 'public' | 'private';
152+
owner_login: string;
153+
url: string;
154+
model: string;
155+
stream: boolean;
156+
json: boolean;
157+
store: boolean;
158+
moderate: boolean;
159+
top_p: number;
160+
max_tokens: number;
161+
temperature: number;
162+
presence_penalty: number;
163+
frequency_penalty: number;
164+
stop: string[];
165+
tool_choice: 'auto' | 'required' | ToolChoice;
166+
parallel_tool_calls: boolean;
167+
messages: Message[];
168+
variables: Variable[] | [];
169+
tools:
170+
| {
171+
type: 'function';
172+
function: {
173+
name: string;
174+
description?: string;
175+
parameters?: Record<string, any>;
176+
};
177+
}[]
178+
| [];
179+
memory: {
180+
name: string;
181+
}[] | [];
182+
}
183+
184+
interface PipeBaseResponse {
149185
name: string;
150186
description: string;
151187
status: 'public' | 'private';
@@ -155,10 +191,10 @@ interface BaseResponse {
155191
api_key: string;
156192
}
157193

158-
export interface CreateOptions extends BaseOptions {}
159-
export interface UpdateOptions extends BaseOptions {}
160-
export interface CreateResponse extends BaseResponse {}
161-
export interface UpdateResponse extends BaseResponse {}
194+
export interface PipeCreateOptions extends PipeBaseOptions {}
195+
export interface PipeUpdateOptions extends PipeBaseOptions {}
196+
export interface PipeCreateResponse extends PipeBaseResponse {}
197+
export interface PipeUpdateResponse extends PipeBaseResponse {}
162198

163199
export class Pipe {
164200
private request: Request;
@@ -207,21 +243,21 @@ export class Pipe {
207243
});
208244
}
209245

210-
async create(options: CreateOptions): Promise<CreateResponse> {
246+
async create(options: PipeCreateOptions): Promise<PipeCreateResponse> {
211247
return this.request.post({
212248
endpoint: '/v1/pipes',
213249
body: options,
214250
});
215251
}
216252

217-
async update(options: UpdateOptions): Promise<UpdateResponse> {
253+
async update(options: PipeUpdateOptions): Promise<PipeUpdateResponse> {
218254
return this.request.post({
219255
endpoint: `/v1/pipes/${options.name}`,
220256
body: options,
221257
});
222258
}
223259

224-
async list() {
260+
async list(): Promise<PipeListResponse[]> {
225261
return this.request.get({
226262
endpoint: '/v1/pipes',
227263
});

0 commit comments

Comments
 (0)