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
17 changes: 17 additions & 0 deletions examples/nodejs/examples/pipes/pipe.create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'dotenv/config';
import {Pipe} from 'langbase';

const pipe = new Pipe({
apiKey: process.env.LANGBASE_API_KEY!,
});

async function main() {
const response = await pipe.create({
name: 'summary-pipe',
status: 'private',
});

console.log(response);
}

main();
18 changes: 18 additions & 0 deletions examples/nodejs/examples/pipes/pipe.update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'dotenv/config';
import {Pipe} from 'langbase';

const pipe = new Pipe({
apiKey: process.env.LANGBASE_API_KEY!,
});

async function main() {
const response = await pipe.update({
name: 'summary-pipe',
description: 'This is a pipe updated with the SDK',
model: 'google:gemini-1.5-flash-8b-latest',
});

console.log(response);
}

main();
2 changes: 2 additions & 0 deletions examples/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"main": "index.js",
"scripts": {
"generate-text": "npx tsx ./examples/pipes/generate-text.ts",
"pipe.create": "npx tsx ./examples/pipes/pipe.create.ts",
"pipe.update": "npx tsx ./examples/pipes/pipe.update.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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"license": "Apache-2.0",
"scripts": {
"dev": "turbo dev",
"dev:pkgs": "turbo run dev --filter=./packages/*",
"prepare": "husky",
"lint": "turbo lint",
"test": "turbo test",
Expand Down
67 changes: 66 additions & 1 deletion packages/langbase/src/pipes/pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ToolCall {
export interface Message {
role: Role;
content: string | null;
name?: string;
name?: 'json' | 'safety' | 'opening' | 'rag';
tool_call_id?: string;
tool_calls?: ToolCall[];
}
Expand Down Expand Up @@ -107,6 +107,57 @@ export interface PipeOptions {
name?: string;
}

interface ToolChoice {
type: 'function';
function: {name: string};
}

interface BaseOptions {
name: string;
description?: string;
status?: 'public' | 'private';
upsert?: boolean;
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[];
tools?: {
type: 'function';
function: {
name: string;
description?: string;
parameters?: Record<string, any>;
};
}[];
tool_choice?: 'auto' | 'required' | ToolChoice;
parallel_tool_calls?: boolean;
messages?: Message[];
variables?: Variable[];
memory?: {
name: string;
}[];
}

interface BaseResponse {
name: string;
description: string;
status: 'public' | 'private';
owner_login: string;
url: string;
}

export interface CreateOptions extends BaseOptions {}
export interface UpdateOptions extends BaseOptions {}
export interface CreateResponse extends BaseResponse {}
export interface UpdateResponse extends BaseResponse {}

export class Pipe {
private request: Request;
private pipe: PipeBaseAI;
Expand Down Expand Up @@ -152,6 +203,20 @@ export class Pipe {
body: {...options, stream: true},
});
}

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

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

/**
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading