diff --git a/examples/nodejs/examples/pipes/pipe.list.ts b/examples/nodejs/examples/pipes/pipe.list.ts new file mode 100644 index 0000000..259fb9a --- /dev/null +++ b/examples/nodejs/examples/pipes/pipe.list.ts @@ -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(); diff --git a/packages/langbase/src/common/request.ts b/packages/langbase/src/common/request.ts index 35d2106..54551c9 100644 --- a/packages/langbase/src/common/request.ts +++ b/packages/langbase/src/common/request.ts @@ -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) { diff --git a/packages/langbase/src/pipes/pipes.ts b/packages/langbase/src/pipes/pipes.ts index efe4877..e5d4430 100644 --- a/packages/langbase/src/pipes/pipes.ts +++ b/packages/langbase/src/pipes/pipes.ts @@ -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 {} @@ -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 @@ -217,6 +220,12 @@ export class Pipe { body: options, }); } + + async list() { + return this.request.get({ + endpoint: '/v1/pipes', + }); + } } /**