Skip to content

Commit 6a5633a

Browse files
committed
📦 NEW: /run endpoint support
1 parent ab5652b commit 6a5633a

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

packages/langbase/.eslintrc.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
module.exports = {
22
root: true,
3-
extends: ['@langbase/eslint-config/library.js'],
3+
extends: [
4+
'@langbase/eslint-config/library.js',
5+
'plugin:prettier/recommended', // prettier
6+
],
47
parser: '@typescript-eslint/parser',
58
parserOptions: {
69
project: true,
710
},
11+
plugins: ['prettier'], // prettier
12+
rules: {
13+
'prettier/prettier': 'error', // prettier
14+
},
815
};

packages/langbase/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"test:ui:react:watch": "vitest --config vitest.ui.react.config.js"
3030
},
3131
"dependencies": {
32+
"@baseai/core": "0.9.30",
3233
"dotenv": "^16.4.5",
3334
"openai": "^4.53.0",
3435
"zod": "^3.23.8",

packages/langbase/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
export {fromReadableStream} from './lib/browser/stream';
22
export * from './pipes/pipes';
3+
export * from '@baseai/core/helpers';
4+
export type {
5+
RunOptions,
6+
RunOptionsStream,
7+
RunResponse,
8+
RunResponseStream,
9+
} from '@baseai/core';

packages/langbase/src/pipes/pipes.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import {Request} from '../common/request';
22
import {Stream} from '../common/stream';
3+
import {
4+
Pipe as PipeBaseAI,
5+
RunOptions,
6+
RunOptionsStream,
7+
RunResponse,
8+
RunResponseStream,
9+
} from '@baseai/core';
310

411
export type Role = 'user' | 'assistant' | 'system' | 'tool';
512

@@ -97,14 +104,36 @@ export interface StreamChunk {
97104
export interface PipeOptions {
98105
apiKey: string;
99106
baseUrl?: string;
107+
name?: string;
100108
}
101109

102110
export class Pipe {
103111
private request: Request;
112+
private pipe: PipeBaseAI;
113+
private pipeOptions;
104114

105115
constructor(options: PipeOptions) {
106116
const baseUrl = 'https://api.langbase.com';
107117
this.request = new Request({apiKey: options.apiKey, baseUrl});
118+
this.pipeOptions = options;
119+
this.pipe = new PipeBaseAI({
120+
apiKey: options.apiKey, // Langbase API key
121+
name: options.name?.trim() || '', // Pipe name
122+
prod: true,
123+
} as any);
124+
}
125+
126+
public async run(options: RunOptionsStream): Promise<RunResponseStream>;
127+
public async run(options: RunOptions): Promise<RunResponse>;
128+
public async run(
129+
options: RunOptions | RunOptionsStream,
130+
): Promise<RunResponse | RunResponseStream> {
131+
if (!this.pipeOptions.name) {
132+
throw new Error(
133+
'Pipe name is required with run. Please provide pipe name when creating Pipe instance.',
134+
);
135+
}
136+
return await this.pipe.run({...options, runTools: false});
108137
}
109138

110139
async generateText(options: GenerateOptions): Promise<GenerateResponse> {

0 commit comments

Comments
 (0)