Skip to content

Commit 69e12b0

Browse files
authored
📦 NEW: Pipe create and update support (#73)
* 📦 NEW: Pipe create and update support * 👌 IMPROVE: Type
1 parent 682d4bb commit 69e12b0

File tree

6 files changed

+107
-4
lines changed

6 files changed

+107
-4
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'dotenv/config';
2+
import {Pipe} from 'langbase';
3+
4+
const pipe = new Pipe({
5+
apiKey: process.env.LANGBASE_API_KEY!,
6+
});
7+
8+
async function main() {
9+
const response = await pipe.create({
10+
name: 'summary-pipe',
11+
status: 'private',
12+
});
13+
14+
console.log(response);
15+
}
16+
17+
main();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'dotenv/config';
2+
import {Pipe} from 'langbase';
3+
4+
const pipe = new Pipe({
5+
apiKey: process.env.LANGBASE_API_KEY!,
6+
});
7+
8+
async function main() {
9+
const response = await pipe.update({
10+
name: 'summary-pipe',
11+
description: 'This is a pipe updated with the SDK',
12+
model: 'google:gemini-1.5-flash-8b-latest',
13+
});
14+
15+
console.log(response);
16+
}
17+
18+
main();

examples/nodejs/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"main": "index.js",
88
"scripts": {
99
"generate-text": "npx tsx ./examples/pipes/generate-text.ts",
10+
"pipe.create": "npx tsx ./examples/pipes/pipe.create.ts",
11+
"pipe.update": "npx tsx ./examples/pipes/pipe.update.ts",
1012
"pipe.run": "npx tsx ./examples/pipes/pipe.run.ts",
1113
"pipe.run.stream": "npx tsx ./examples/pipes/pipe.run.stream.ts",
1214
"generate-text-generate-pipe": "npx tsx ./examples/pipes/generate-text-generate-pipe.ts",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"license": "Apache-2.0",
55
"scripts": {
66
"dev": "turbo dev",
7+
"dev:pkgs": "turbo run dev --filter=./packages/*",
78
"prepare": "husky",
89
"lint": "turbo lint",
910
"test": "turbo test",

packages/langbase/src/pipes/pipes.ts

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface ToolCall {
2424
export interface Message {
2525
role: Role;
2626
content: string | null;
27-
name?: string;
27+
name?: 'json' | 'safety' | 'opening' | 'rag';
2828
tool_call_id?: string;
2929
tool_calls?: ToolCall[];
3030
}
@@ -107,6 +107,57 @@ export interface PipeOptions {
107107
name?: string;
108108
}
109109

110+
interface ToolChoice {
111+
type: 'function';
112+
function: {name: string};
113+
}
114+
115+
interface BaseOptions {
116+
name: string;
117+
description?: string;
118+
status?: 'public' | 'private';
119+
upsert?: boolean;
120+
model?: string;
121+
stream?: boolean;
122+
json?: boolean;
123+
store?: boolean;
124+
moderate?: boolean;
125+
top_p?: number;
126+
max_tokens?: number;
127+
temperature?: number;
128+
presence_penalty?: number;
129+
frequency_penalty?: number;
130+
stop?: string[];
131+
tools?: {
132+
type: 'function';
133+
function: {
134+
name: string;
135+
description?: string;
136+
parameters?: Record<string, any>;
137+
};
138+
}[];
139+
tool_choice?: 'auto' | 'required' | ToolChoice;
140+
parallel_tool_calls?: boolean;
141+
messages?: Message[];
142+
variables?: Variable[];
143+
memory?: {
144+
name: string;
145+
}[];
146+
}
147+
148+
interface BaseResponse {
149+
name: string;
150+
description: string;
151+
status: 'public' | 'private';
152+
owner_login: string;
153+
url: string;
154+
}
155+
156+
export interface CreateOptions extends BaseOptions {}
157+
export interface UpdateOptions extends BaseOptions {}
158+
export interface CreateResponse extends BaseResponse {}
159+
export interface UpdateResponse extends BaseResponse {}
160+
110161
export class Pipe {
111162
private request: Request;
112163
private pipe: PipeBaseAI;
@@ -152,6 +203,20 @@ export class Pipe {
152203
body: {...options, stream: true},
153204
});
154205
}
206+
207+
async create(options: CreateOptions): Promise<CreateResponse> {
208+
return this.request.post({
209+
endpoint: '/v1/pipes',
210+
body: options,
211+
});
212+
}
213+
214+
async update(options: UpdateOptions): Promise<UpdateResponse> {
215+
return this.request.post({
216+
endpoint: `/v1/pipes/${options.name}`,
217+
body: options,
218+
});
219+
}
155220
}
156221

157222
/**

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)