Skip to content

Commit

Permalink
📦 NEW: Pipe list support (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
msaaddev authored Nov 20, 2024
1 parent 207f708 commit 7f301db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/nodejs/examples/pipes/pipe.list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'dotenv/config';
import {Pipe} from 'langbase';

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

async function main() {
const response = await pipe.list();
console.log(response);
}

main();
8 changes: 8 additions & 0 deletions packages/langbase/src/common/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export class Request {
await this.handleErrorResponse({response});
}

if(!options.body) {
return this.handleGenerateResponse({
response,
isChat: false,
threadId: null,
})
}

const threadId = response.headers.get('lb-thread-id');

if (options.body.stream) {
Expand Down
9 changes: 9 additions & 0 deletions packages/langbase/src/pipes/pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ interface BaseResponse {
status: 'public' | 'private';
owner_login: string;
url: string;
type: 'chat' | 'generate' | 'run';
api_key: string;
}

export interface CreateOptions extends BaseOptions {}
Expand All @@ -167,6 +169,7 @@ export class Pipe {
const baseUrl = 'https://api.langbase.com';
this.request = new Request({apiKey: options.apiKey, baseUrl});
this.pipeOptions = options;

this.pipe = new PipeBaseAI({
apiKey: options.apiKey, // Langbase API key
name: options.name?.trim() || '', // Pipe name
Expand Down Expand Up @@ -217,6 +220,12 @@ export class Pipe {
body: options,
});
}

async list() {
return this.request.get({
endpoint: '/v1/pipes',
});
}
}

/**
Expand Down

0 comments on commit 7f301db

Please sign in to comment.