diff --git a/examples/nextjs/app/langbase/pipe/run-stream/route.ts b/examples/nextjs/app/langbase/pipe/run-stream/route.ts index c57dd06..102c628 100644 --- a/examples/nextjs/app/langbase/pipe/run-stream/route.ts +++ b/examples/nextjs/app/langbase/pipe/run-stream/route.ts @@ -1,16 +1,16 @@ -import {Pipe} from 'langbase'; +import {Langbase} from 'langbase'; import {NextRequest} from 'next/server'; export async function POST(req: NextRequest) { const {prompt} = await req.json(); // 1. Initiate the Pipe. - const myPipe = new Pipe({ + const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); // 2. Generate a stream by asking a question - const {stream, threadId} = await myPipe.run({ + const {stream, threadId} = await langbase.pipe.run({ messages: [{role: 'user', content: prompt}], stream: true, name: 'summary', diff --git a/examples/nextjs/app/langbase/pipe/run/route.ts b/examples/nextjs/app/langbase/pipe/run/route.ts index 3b3ccc6..8981d88 100644 --- a/examples/nextjs/app/langbase/pipe/run/route.ts +++ b/examples/nextjs/app/langbase/pipe/run/route.ts @@ -1,16 +1,16 @@ -import {Pipe} from 'langbase'; +import {Langbase} from 'langbase'; import {NextRequest} from 'next/server'; export async function POST(req: NextRequest) { const {prompt} = await req.json(); // 1. Initiate the Pipe. - const myPipe = new Pipe({ + const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); // 2. Generate a stream by asking a question - const result = await myPipe.run({ + const result = await langbase.pipe.run({ messages: [{role: 'user', content: prompt}], name: 'summary', }); diff --git a/examples/nodejs/examples/memory/memory.create.ts b/examples/nodejs/examples/memory/memory.create.ts index 250b6f2..b3cfd52 100644 --- a/examples/nodejs/examples/memory/memory.create.ts +++ b/examples/nodejs/examples/memory/memory.create.ts @@ -1,13 +1,13 @@ import 'dotenv/config'; -import {Memory} from 'langbase'; +import {Langbase} from 'langbase'; -const memory = new Memory({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); async function main() { - const response = await memory.create({ - name: 'sdk-memory-2', + const response = await langbase.memory.create({ + name: 'sdk-memory', embedding_model: 'cohere:embed-multilingual-v3.0' }); diff --git a/examples/nodejs/examples/memory/memory.delete.ts b/examples/nodejs/examples/memory/memory.delete.ts index ce82e04..067308f 100644 --- a/examples/nodejs/examples/memory/memory.delete.ts +++ b/examples/nodejs/examples/memory/memory.delete.ts @@ -1,12 +1,12 @@ import 'dotenv/config'; -import {Memory} from 'langbase'; +import {Langbase} from 'langbase'; -const memory = new Memory({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); async function main() { - const response = await memory.delete({ + const response = await langbase.memory.delete({ name: 'memory-sdk', }); diff --git a/examples/nodejs/examples/memory/memory.docs.delete.ts b/examples/nodejs/examples/memory/memory.docs.delete.ts index 6f0d664..099e0d0 100644 --- a/examples/nodejs/examples/memory/memory.docs.delete.ts +++ b/examples/nodejs/examples/memory/memory.docs.delete.ts @@ -1,12 +1,12 @@ import 'dotenv/config'; -import {Memory} from 'langbase'; +import {Langbase} from 'langbase'; -const memory = new Memory({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); async function main() { - const response = await memory.deleteDoc({ + const response = await langbase.memory.documents.delete({ memoryName: 'memory-sdk', documentName: 'readme.md', }); diff --git a/examples/nodejs/examples/memory/memory.docs.list.ts b/examples/nodejs/examples/memory/memory.docs.list.ts index 0917887..e315feb 100644 --- a/examples/nodejs/examples/memory/memory.docs.list.ts +++ b/examples/nodejs/examples/memory/memory.docs.list.ts @@ -1,13 +1,13 @@ import 'dotenv/config'; -import {Memory} from 'langbase'; +import {Langbase} from 'langbase'; -const memory = new Memory({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); async function main() { - const response = await memory.listDocs({ - memoryName: 'memory-sdk' + const response = await langbase.memory.documents.list({ + memoryName: 'memory-sdk', }); console.log(response); diff --git a/examples/nodejs/examples/memory/memory.docs.retry-embed.ts b/examples/nodejs/examples/memory/memory.docs.retry-embed.ts index 9dccaf3..f684a18 100644 --- a/examples/nodejs/examples/memory/memory.docs.retry-embed.ts +++ b/examples/nodejs/examples/memory/memory.docs.retry-embed.ts @@ -1,12 +1,12 @@ import 'dotenv/config'; -import {Memory} from 'langbase'; +import {Langbase} from 'langbase'; -const memory = new Memory({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); async function main() { - const response = await memory.retryDocEmbed({ + const response = await langbase.memory.documents.embedding.retry({ memoryName: 'memory-sdk', documentName: 'memory.upload.doc.ts', }); diff --git a/examples/nodejs/examples/memory/memory.docs.upload.ts b/examples/nodejs/examples/memory/memory.docs.upload.ts index 3b30448..96d4fce 100644 --- a/examples/nodejs/examples/memory/memory.docs.upload.ts +++ b/examples/nodejs/examples/memory/memory.docs.upload.ts @@ -1,9 +1,9 @@ import 'dotenv/config'; -import {Memory} from 'langbase'; +import {Langbase} from 'langbase'; import fs from 'fs'; import path from 'path'; -const memory = new Memory({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); @@ -16,7 +16,7 @@ async function main() { ); const file = fs.readFileSync(src); - const response = await memory.uploadDoc({ + const response = await langbase.memory.documents.upload({ file, memoryName: 'memory-sdk', fileName: 'memory.upload.doc.ts', diff --git a/examples/nodejs/examples/memory/memory.list.ts b/examples/nodejs/examples/memory/memory.list.ts index 93b6a74..9d78019 100644 --- a/examples/nodejs/examples/memory/memory.list.ts +++ b/examples/nodejs/examples/memory/memory.list.ts @@ -1,12 +1,12 @@ import 'dotenv/config'; -import {Memory} from 'langbase'; +import {Langbase} from 'langbase'; -const memory = new Memory({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); async function main() { - const response = await memory.list(); + const response = await langbase.memory.list(); console.log(response); } diff --git a/examples/nodejs/examples/memory/memory.retrieve.ts b/examples/nodejs/examples/memory/memory.retrieve.ts index 8eb61e6..22cdefd 100644 --- a/examples/nodejs/examples/memory/memory.retrieve.ts +++ b/examples/nodejs/examples/memory/memory.retrieve.ts @@ -1,12 +1,12 @@ import 'dotenv/config'; -import {Memory} from 'langbase'; +import {Langbase} from 'langbase'; -const memory = new Memory({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); async function main() { - const response = await memory.retrieve({ + const response = await langbase.memory.retrieve({ memory: [ { name: 'langbase-docs', diff --git a/examples/nodejs/examples/pipes/pipe.create.ts b/examples/nodejs/examples/pipes/pipe.create.ts index d7f8769..4e15a96 100644 --- a/examples/nodejs/examples/pipes/pipe.create.ts +++ b/examples/nodejs/examples/pipes/pipe.create.ts @@ -1,13 +1,13 @@ import 'dotenv/config'; -import {Pipe} from 'langbase'; +import {Langbase} from 'langbase'; -const pipe = new Pipe({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); async function main() { - const response = await pipe.create({ - name: 'summary-pipe', + const response = await langbase.pipe.create({ + name: 'summary-pipe2', status: 'private', }); diff --git a/examples/nodejs/examples/pipes/pipe.list.ts b/examples/nodejs/examples/pipes/pipe.list.ts index 259fb9a..bebd2b6 100644 --- a/examples/nodejs/examples/pipes/pipe.list.ts +++ b/examples/nodejs/examples/pipes/pipe.list.ts @@ -1,12 +1,12 @@ import 'dotenv/config'; -import {Pipe} from 'langbase'; +import {Langbase} from 'langbase'; -const pipe = new Pipe({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); async function main() { - const response = await pipe.list(); + const response = await langbase.pipe.list(); console.log(response); } diff --git a/examples/nodejs/examples/pipes/pipe.run.stream.ts b/examples/nodejs/examples/pipes/pipe.run.stream.ts index 089d85b..29f6f39 100644 --- a/examples/nodejs/examples/pipes/pipe.run.stream.ts +++ b/examples/nodejs/examples/pipes/pipe.run.stream.ts @@ -1,7 +1,7 @@ import 'dotenv/config'; -import {getRunner, Pipe} from 'langbase'; +import {getRunner, Langbase} from 'langbase'; -const pipe = new Pipe({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); @@ -9,7 +9,7 @@ async function main() { const userMsg = 'Who is an AI Engineer?'; // Get readable stream - const {stream, threadId, rawResponse} = await pipe.run({ + const {stream, threadId, rawResponse} = await langbase.pipe.run({ messages: [{role: 'user', content: userMsg}], stream: true, rawResponse: true, diff --git a/examples/nodejs/examples/pipes/pipe.run.ts b/examples/nodejs/examples/pipes/pipe.run.ts index b4f7a7e..441cabf 100644 --- a/examples/nodejs/examples/pipes/pipe.run.ts +++ b/examples/nodejs/examples/pipes/pipe.run.ts @@ -1,14 +1,14 @@ import 'dotenv/config'; -import {Pipe} from 'langbase'; +import {Langbase} from 'langbase'; -const pipe = new Pipe({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); async function main() { const userMsg = 'Who is an AI Engineer?'; - const response = await pipe.run({ + const response = await langbase.pipe.run({ messages: [ { role: 'user', diff --git a/examples/nodejs/examples/pipes/pipe.update.ts b/examples/nodejs/examples/pipes/pipe.update.ts index 9612a62..039fefc 100644 --- a/examples/nodejs/examples/pipes/pipe.update.ts +++ b/examples/nodejs/examples/pipes/pipe.update.ts @@ -1,12 +1,12 @@ import 'dotenv/config'; -import {Pipe} from 'langbase'; +import {Langbase} from 'langbase'; -const pipe = new Pipe({ +const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); async function main() { - const response = await pipe.update({ + const response = await langbase.pipe.update({ name: 'summary-pipe', description: 'This is a pipe updated with the SDK', model: 'google:gemini-1.5-flash-8b-latest', diff --git a/packages/langbase/src/index.ts b/packages/langbase/src/index.ts index 89c5a13..6d84533 100644 --- a/packages/langbase/src/index.ts +++ b/packages/langbase/src/index.ts @@ -1,6 +1,6 @@ export {fromReadableStream} from './lib/browser/stream'; +export * from './langbase/langbase'; export * from './pipes/pipes'; -export * from './memory/memory'; export * from '@baseai/core/helpers'; export type { RunOptions, diff --git a/packages/langbase/src/memory/memory.ts b/packages/langbase/src/langbase/langbase.ts similarity index 50% rename from packages/langbase/src/memory/memory.ts rename to packages/langbase/src/langbase/langbase.ts index 84b0ecc..d12c2a9 100644 --- a/packages/langbase/src/memory/memory.ts +++ b/packages/langbase/src/langbase/langbase.ts @@ -1,9 +1,140 @@ import {Request} from '../common/request'; +import { + Pipe as PipeBaseAI, + RunOptions as RunOptionsT, + RunOptionsStream as RunOptionsStreamT, + RunResponse, + RunResponseStream, +} from '@baseai/core'; -export interface MemoryOptions { - apiKey: string; +export type Role = 'user' | 'assistant' | 'system' | 'tool'; + +export interface RunOptions extends RunOptionsT { + name: string; + messages: Message[]; +} + +export interface RunOptionsStream extends RunOptionsStreamT { + name: string; + messages: Message[]; +} + +export interface Function { + name: string; + arguments: string; +} + +export interface ToolCall { + id: string; + type: 'function'; + function: Function; +} + +export interface Message { + role: Role; + content: string | null; + name?: 'json' | 'safety' | 'opening' | 'rag'; + tool_call_id?: string; + tool_calls?: ToolCall[]; +} + +export interface Variable { + name: string; + value: string; } + +interface ToolChoice { + type: 'function'; + function: {name: string}; +} + +interface PipeBaseOptions { + 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; + }; + }[]; + tool_choice?: 'auto' | 'required' | ToolChoice; + parallel_tool_calls?: boolean; + messages?: Message[]; + variables?: Variable[]; + memory?: { + name: string; + }[]; +} + +export interface PipeListResponse { + name: string; + description: string; + status: 'public' | 'private'; + owner_login: string; + url: string; + 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[]; + tool_choice: 'auto' | 'required' | ToolChoice; + parallel_tool_calls: boolean; + messages: Message[]; + variables: Variable[] | []; + tools: + | { + type: 'function'; + function: { + name: string; + description?: string; + parameters?: Record; + }; + }[] + | []; + memory: + | { + name: string; + }[] + | []; +} + +interface PipeBaseResponse { + name: string; + description: string; + status: 'public' | 'private'; + owner_login: string; + url: string; + type: 'chat' | 'generate' | 'run'; + api_key: string; +} + +export interface PipeCreateOptions extends PipeBaseOptions {} +export interface PipeUpdateOptions extends PipeBaseOptions {} +export interface PipeCreateResponse extends PipeBaseResponse {} +export interface PipeUpdateResponse extends PipeBaseResponse {} + interface MemoryBaseResponse { name: string; description: string; @@ -50,7 +181,9 @@ export interface MemoryUploadDocOptions { | 'application/pdf' | 'text/plain' | 'text/markdown' - | 'text/csv'; + | 'text/csv' + | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' + | 'application/vnd.ms-excel'; } export interface MemoryRetryDocEmbedOptions { @@ -64,7 +197,12 @@ export interface MemoryCreateResponse extends MemoryBaseResponse { | 'cohere:embed-multilingual-v3.0' | 'cohere:embed-multilingual-light-v3.0'; } -export interface MemoryListResponse extends MemoryBaseResponse {} +export interface MemoryListResponse extends MemoryBaseResponse { + embedding_model: + | 'openai:text-embedding-3-large' + | 'cohere:embed-multilingual-v3.0' + | 'cohere:embed-multilingual-light-v3.0'; +} export interface BaseDeleteResponse { success: boolean; } @@ -99,14 +237,133 @@ export interface MemoryListDocResponse { owner_login: string; } -export class Memory { +export interface LangbaseOptions { + apiKey: string; +} + +export class Langbase { private request: Request; private apiKey: string; + public pipe: { + list: () => Promise; + create: (options: PipeCreateOptions) => Promise; + update: (options: PipeUpdateOptions) => Promise; + run: { + (options: RunOptionsStream): Promise; + (options: RunOptions): Promise; + }; + }; + public memory: { + create: (options: MemoryCreateOptions) => Promise; + delete: (options: MemoryDeleteOptions) => Promise; + retrieve: ( + options: MemoryRetrieveOptions, + ) => Promise; + list: () => Promise; + documents: { + list: ( + options: MemoryListDocOptions, + ) => Promise; + delete: ( + options: MemoryDeleteDocOptions, + ) => Promise; + upload: (options: MemoryUploadDocOptions) => Promise; + embedding: { + retry: ( + options: MemoryRetryDocEmbedOptions, + ) => Promise; + }; + }; + }; - constructor(options: MemoryOptions) { + constructor(options: LangbaseOptions) { const baseUrl = 'https://api.langbase.com'; this.apiKey = options.apiKey; this.request = new Request({apiKey: options.apiKey, baseUrl}); + + // Initialize pipe property with method bindings + this.pipe = { + list: this.listPipe.bind(this), + create: this.createPipe.bind(this), + update: this.updatePipe.bind(this), + run: this.runPipe.bind(this), + }; + + // Initialize memory property with method bindings + this.memory = { + create: this.createMemory.bind(this), + delete: this.deleteMemory.bind(this), + retrieve: this.retrieveMemory.bind(this), + list: this.listMemory.bind(this), + documents: { + list: this.listDocs.bind(this), + delete: this.deleteDoc.bind(this), + upload: this.uploadDocs.bind(this), + embedding: { + retry: this.retryDocEmbed.bind(this), + }, + }, + }; + } + + private async runPipe( + options: RunOptionsStream, + ): Promise; + private async runPipe(options: RunOptions): Promise; + private async runPipe( + options: RunOptions | RunOptionsStream, + ): Promise { + const pipe = new PipeBaseAI({ + apiKey: this.apiKey, + name: options.name?.trim() || '', // Pipe name + prod: true, + // default values + model: 'openai:gpt-4o-mini', + tools: [], + } as any); + + return await pipe.run({...options, runTools: false}); + } + + /** + * Creates a new pipe on Langbase. + * + * @param {PipeCreateOptions} options - The options for creating the pipe. + * @returns {Promise} A promise that resolves to the response of the pipe creation. + */ + private async createPipe( + options: PipeCreateOptions, + ): Promise { + return this.request.post({ + endpoint: '/v1/pipes', + body: options, + }); + } + + /** + * Updates a pipe on Langbase. + * + * @param {PipeUpdateOptions} options - The options for updating the pipe. + * @returns {Promise} A promise that resolves to the response of the update operation. + */ + private async updatePipe( + options: PipeUpdateOptions, + ): Promise { + return this.request.post({ + endpoint: `/v1/pipes/${options.name}`, + body: options, + }); + } + + /** + * Retrieves a list of pipes. + * + * @returns {Promise} A promise that resolves to an array of PipeListResponse objects. + */ + private async listPipe(): Promise { + return this.request.get({ + endpoint: '/v1/pipes', + }); } /** @@ -117,7 +374,7 @@ export class Memory { * @param {string} options.description - The description of the memory. * @returns {Promise} A promise that resolves to the response of the memory creation. */ - async create(options: MemoryCreateOptions): Promise { + private async createMemory(options: MemoryCreateOptions): Promise { return this.request.post({ endpoint: '/v1/memory', body: options, @@ -129,7 +386,7 @@ export class Memory { * * @returns {Promise} A promise that resolves to an array of memory list responses. */ - async list(): Promise { + private async listMemory(): Promise { return this.request.get({ endpoint: '/v1/memory', }); @@ -142,7 +399,7 @@ export class Memory { * @param {string} options.name - The name of the memory to delete. * @returns {Promise} A promise that resolves to the response of the delete operation. */ - async delete(options: MemoryDeleteOptions): Promise { + private async deleteMemory(options: MemoryDeleteOptions): Promise { return this.request.delete({ endpoint: `/v1/memory/${options.name}`, }); @@ -157,7 +414,7 @@ export class Memory { * @param {number} [options.topK] - The number of similar texts to retrieve. * @returns A promise that resolves to an array of `MemoryRetrieveResponse` objects. */ - async retrieve( + private async retrieveMemory( options: MemoryRetrieveOptions, ): Promise { return this.request.post({ @@ -173,7 +430,7 @@ export class Memory { * @param {string} options.memoryName - The name of the memory to list documents from. * @returns A promise that resolves to an array of `MemoryListDocResponse` objects. */ - async listDocs( + private async listDocs( options: MemoryListDocOptions, ): Promise { return this.request.get({ @@ -189,7 +446,7 @@ export class Memory { * @param {string} options.documentName - The name of the document to delete. * @returns A promise that resolves to a `MemoryDeleteDocResponse` indicating the result of the delete operation. */ - async deleteDoc( + private async deleteDoc( options: MemoryDeleteDocOptions, ): Promise { return this.request.delete({ @@ -209,7 +466,7 @@ export class Memory { * @returns {Promise} The response from the upload request. * @throws Will throw an error if the upload fails. */ - async uploadDoc(options: MemoryUploadDocOptions): Promise { + private async uploadDocs(options: MemoryUploadDocOptions): Promise { try { const response = (await this.request.post({ endpoint: `/v1/memory/documents`, @@ -243,7 +500,7 @@ export class Memory { * @param options.documentName - The name of the document to retry embedding for. * @returns A promise that resolves to the response of the retry operation. */ - async retryDocEmbed( + private async retryDocEmbed( options: MemoryRetryDocEmbedOptions, ): Promise { return this.request.get({ diff --git a/packages/langbase/src/pipes/pipes.ts b/packages/langbase/src/pipes/pipes.ts index 3de65e1..0edbe1c 100644 --- a/packages/langbase/src/pipes/pipes.ts +++ b/packages/langbase/src/pipes/pipes.ts @@ -1,48 +1,7 @@ +import { Message, Role, ToolCall, Variable } from '@/langbase/langbase'; import {Request} from '../common/request'; import {Stream} from '../common/stream'; -import { - Pipe as PipeBaseAI, - RunOptions as RunOptionsT, - RunOptionsStream as RunOptionsStreamT, - RunResponse, - RunResponseStream, -} from '@baseai/core'; -export type Role = 'user' | 'assistant' | 'system' | 'tool'; - -export interface RunOptions extends RunOptionsT { - name: string; - messages: Message[]; -} - -export interface RunOptionsStream extends RunOptionsStreamT { - name: string; - messages: Message[]; -} - -export interface Function { - name: string; - arguments: string; -} - -export interface ToolCall { - id: string; - type: 'function'; - function: Function; -} - -export interface Message { - role: Role; - content: string | null; - name?: 'json' | 'safety' | 'opening' | 'rag'; - tool_call_id?: string; - tool_calls?: ToolCall[]; -} - -export interface Variable { - name: string; - value: string; -} export interface GenerateOptions { messages?: Message[]; @@ -117,123 +76,12 @@ export interface PipeOptions { name?: string; } -interface ToolChoice { - type: 'function'; - function: {name: string}; -} - -interface PipeBaseOptions { - 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; - }; - }[]; - tool_choice?: 'auto' | 'required' | ToolChoice; - parallel_tool_calls?: boolean; - messages?: Message[]; - variables?: Variable[]; - memory?: { - name: string; - }[]; -} - -export interface PipeListResponse { - name: string; - description: string; - status: 'public' | 'private'; - owner_login: string; - url: string; - 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[]; - tool_choice: 'auto' | 'required' | ToolChoice; - parallel_tool_calls: boolean; - messages: Message[]; - variables: Variable[] | []; - tools: - | { - type: 'function'; - function: { - name: string; - description?: string; - parameters?: Record; - }; - }[] - | []; - memory: - | { - name: string; - }[] - | []; -} - -interface PipeBaseResponse { - name: string; - description: string; - status: 'public' | 'private'; - owner_login: string; - url: string; - type: 'chat' | 'generate' | 'run'; - api_key: string; -} - -export interface PipeCreateOptions extends PipeBaseOptions {} -export interface PipeUpdateOptions extends PipeBaseOptions {} -export interface PipeCreateResponse extends PipeBaseResponse {} -export interface PipeUpdateResponse extends PipeBaseResponse {} - export class Pipe { private request: Request; - private pipe: PipeBaseAI; - private pipeOptions; constructor(options: PipeOptions) { 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 - prod: true, - // default values - model: 'openai:gpt-4o-mini', - tools: [], - } as any); - } - - public async run(options: RunOptionsStream): Promise; - public async run(options: RunOptions): Promise; - public async run( - options: RunOptions | RunOptionsStream, - ): Promise { - return await this.pipe.run({...options, runTools: false}); } async generateText(options: GenerateOptions): Promise { @@ -249,43 +97,6 @@ export class Pipe { body: {...options, stream: true}, }); } - - /** - * Creates a new pipe on Langbase. - * - * @param {PipeCreateOptions} options - The options for creating the pipe. - * @returns {Promise} A promise that resolves to the response of the pipe creation. - */ - async create(options: PipeCreateOptions): Promise { - return this.request.post({ - endpoint: '/v1/pipes', - body: options, - }); - } - - /** - * Updates a pipe on Langbase. - * - * @param {PipeUpdateOptions} options - The options for updating the pipe. - * @returns {Promise} A promise that resolves to the response of the update operation. - */ - async update(options: PipeUpdateOptions): Promise { - return this.request.post({ - endpoint: `/v1/pipes/${options.name}`, - body: options, - }); - } - - /** - * Retrieves a list of pipes. - * - * @returns {Promise} A promise that resolves to an array of PipeListResponse objects. - */ - async list(): Promise { - return this.request.get({ - endpoint: '/v1/pipes', - }); - } } /**