Comparing version 1.1.7 to 1.1.8
@@ -8,39 +8,2 @@ import { ChatCompletionStream } from 'openai/lib/ChatCompletionStream'; | ||
declare class Stream<Item> implements AsyncIterable<Item> { | ||
private iterator; | ||
controller: AbortController; | ||
constructor(iterator: () => AsyncIterator<Item>, controller: AbortController); | ||
/** | ||
* Creates a stream of AsyncIterator from a Server-Sent Events (SSE) response. | ||
* | ||
* @template Item - The type of items in the stream. | ||
* @param {Response} response - The SSE response object. | ||
* @param {AbortController} controller - The abort controller used to cancel the ongoing request. | ||
* @returns {Stream<AsyncIterator<Item, any, undefined>>} - The stream created from the SSE response. | ||
* @throws {Error} - If the stream has already been consumed. | ||
*/ | ||
static fromSSEResponse<Item>(response: Response, controller: AbortController): Stream<Item>; | ||
/** | ||
* Generates a Stream from a newline-separated ReadableStream | ||
* where each item is a JSON value. | ||
* | ||
* @template Item - The type of items in the stream. | ||
* @param {ReadableStream} readableStream - The readable stream to create the stream from. | ||
* @param {AbortController} controller - The abort controller to control the stream. | ||
* @returns {Stream<Item>} - The created stream. | ||
*/ | ||
static fromReadableStream<Item>(readableStream: ReadableStream, controller: AbortController): Stream<Item>; | ||
[Symbol.asyncIterator](): AsyncIterator<Item>; | ||
/** | ||
* Splits the stream into two streams which can be | ||
* independently read from at different speeds. | ||
*/ | ||
tee(): [Stream<Item>, Stream<Item>]; | ||
/** | ||
* Converts this stream to a newline-separated ReadableStream of | ||
* JSON stringified values in the stream which can be turned back into a Stream with `Stream.fromReadableStream()`. | ||
*/ | ||
toReadableStream(): ReadableStream; | ||
} | ||
type Role = 'user' | 'assistant' | 'system' | 'tool'; | ||
@@ -75,64 +38,2 @@ interface RunOptions extends RunOptions$1 { | ||
} | ||
interface GenerateOptions { | ||
messages?: Message[]; | ||
variables?: Variable[]; | ||
threadId?: string; | ||
chat?: boolean; | ||
} | ||
interface StreamOptions { | ||
messages?: Message[]; | ||
variables?: Variable[]; | ||
threadId?: string | null; | ||
chat?: boolean; | ||
} | ||
interface ChoiceGenerate { | ||
index: number; | ||
message: Message; | ||
logprobs: boolean | null; | ||
finish_reason: string; | ||
} | ||
interface ChoiceStream { | ||
index: number; | ||
delta: Delta; | ||
logprobs: boolean | null; | ||
finish_reason: string; | ||
} | ||
interface Delta { | ||
role?: Role; | ||
content?: string; | ||
tool_calls?: ToolCall[]; | ||
} | ||
interface Usage { | ||
prompt_tokens: number; | ||
completion_tokens: number; | ||
total_tokens: number; | ||
} | ||
interface GenerateResponse { | ||
completion: string; | ||
threadId?: string; | ||
id: string; | ||
object: string; | ||
created: number; | ||
model: string; | ||
choices: ChoiceGenerate[]; | ||
usage: Usage; | ||
system_fingerprint: string | null; | ||
} | ||
type StreamText = Stream<StreamChunk>; | ||
interface StreamResponse { | ||
stream: StreamText; | ||
threadId: string | null; | ||
} | ||
interface StreamChunk { | ||
id: string; | ||
object: string; | ||
created: number; | ||
model: string; | ||
choices: ChoiceStream[]; | ||
} | ||
interface PipeOptions { | ||
apiKey: string; | ||
baseUrl?: string; | ||
name?: string; | ||
} | ||
interface ToolChoice { | ||
@@ -226,41 +127,2 @@ type: 'function'; | ||
} | ||
declare class Pipe { | ||
private request; | ||
private pipe; | ||
private pipeOptions; | ||
constructor(options: PipeOptions); | ||
run(options: RunOptionsStream): Promise<RunResponseStream>; | ||
run(options: RunOptions): Promise<RunResponse>; | ||
generateText(options: GenerateOptions): Promise<GenerateResponse>; | ||
streamText(options: StreamOptions): Promise<StreamResponse>; | ||
/** | ||
* Creates a new pipe on Langbase. | ||
* | ||
* @param {PipeCreateOptions} options - The options for creating the pipe. | ||
* @returns {Promise<PipeCreateResponse>} A promise that resolves to the response of the pipe creation. | ||
*/ | ||
create(options: PipeCreateOptions): Promise<PipeCreateResponse>; | ||
/** | ||
* Updates a pipe on Langbase. | ||
* | ||
* @param {PipeUpdateOptions} options - The options for updating the pipe. | ||
* @returns {Promise<PipeUpdateResponse>} A promise that resolves to the response of the update operation. | ||
*/ | ||
update(options: PipeUpdateOptions): Promise<PipeUpdateResponse>; | ||
/** | ||
* Retrieves a list of pipes. | ||
* | ||
* @returns {Promise<PipeListResponse[]>} A promise that resolves to an array of PipeListResponse objects. | ||
*/ | ||
list(): Promise<PipeListResponse[]>; | ||
} | ||
/** | ||
* Print stream to standard output (console). | ||
* @param stream The stream to print | ||
*/ | ||
declare const printStreamToStdout: (stream: StreamText) => Promise<void>; | ||
interface MemoryOptions { | ||
apiKey: string; | ||
} | ||
interface MemoryBaseResponse { | ||
@@ -299,3 +161,3 @@ name: string; | ||
file: Buffer | File | FormData | ReadableStream; | ||
contentType: 'application/pdf' | 'text/plain' | 'text/markdown' | 'text/csv'; | ||
contentType: 'application/pdf' | 'text/plain' | 'text/markdown' | 'text/csv' | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | 'application/vnd.ms-excel'; | ||
} | ||
@@ -310,2 +172,3 @@ interface MemoryRetryDocEmbedOptions { | ||
interface MemoryListResponse extends MemoryBaseResponse { | ||
embedding_model: 'openai:text-embedding-3-large' | 'cohere:embed-multilingual-v3.0' | 'cohere:embed-multilingual-light-v3.0'; | ||
} | ||
@@ -339,7 +202,54 @@ interface BaseDeleteResponse { | ||
} | ||
declare class Memory { | ||
interface LangbaseOptions { | ||
apiKey: string; | ||
} | ||
declare class Langbase { | ||
private request; | ||
private apiKey; | ||
constructor(options: MemoryOptions); | ||
pipe: { | ||
list: () => Promise<PipeListResponse[]>; | ||
create: (options: PipeCreateOptions) => Promise<PipeCreateResponse>; | ||
update: (options: PipeUpdateOptions) => Promise<PipeUpdateResponse>; | ||
run: { | ||
(options: RunOptionsStream): Promise<RunResponseStream>; | ||
(options: RunOptions): Promise<RunResponse>; | ||
}; | ||
}; | ||
memory: { | ||
create: (options: MemoryCreateOptions) => Promise<MemoryCreateResponse>; | ||
delete: (options: MemoryDeleteOptions) => Promise<MemoryDeleteResponse>; | ||
retrieve: (options: MemoryRetrieveOptions) => Promise<MemoryRetrieveResponse[]>; | ||
list: () => Promise<MemoryListResponse[]>; | ||
documents: { | ||
list: (options: MemoryListDocOptions) => Promise<MemoryListDocResponse[]>; | ||
delete: (options: MemoryDeleteDocOptions) => Promise<MemoryDeleteDocResponse>; | ||
upload: (options: MemoryUploadDocOptions) => Promise<Response>; | ||
embedding: { | ||
retry: (options: MemoryRetryDocEmbedOptions) => Promise<MemoryRetryDocEmbedResponse>; | ||
}; | ||
}; | ||
}; | ||
constructor(options: LangbaseOptions); | ||
private runPipe; | ||
/** | ||
* Creates a new pipe on Langbase. | ||
* | ||
* @param {PipeCreateOptions} options - The options for creating the pipe. | ||
* @returns {Promise<PipeCreateResponse>} A promise that resolves to the response of the pipe creation. | ||
*/ | ||
private createPipe; | ||
/** | ||
* Updates a pipe on Langbase. | ||
* | ||
* @param {PipeUpdateOptions} options - The options for updating the pipe. | ||
* @returns {Promise<PipeUpdateResponse>} A promise that resolves to the response of the update operation. | ||
*/ | ||
private updatePipe; | ||
/** | ||
* Retrieves a list of pipes. | ||
* | ||
* @returns {Promise<PipeListResponse[]>} A promise that resolves to an array of PipeListResponse objects. | ||
*/ | ||
private listPipe; | ||
/** | ||
* Creates a new memory on Langbase. | ||
@@ -352,3 +262,3 @@ * | ||
*/ | ||
create(options: MemoryCreateOptions): Promise<MemoryCreateResponse>; | ||
private createMemory; | ||
/** | ||
@@ -359,3 +269,3 @@ * Retrieves a list of all memories on Langbase. | ||
*/ | ||
list(): Promise<MemoryListResponse[]>; | ||
private listMemory; | ||
/** | ||
@@ -368,3 +278,3 @@ * Deletes a memory on Langbase. | ||
*/ | ||
delete(options: MemoryDeleteOptions): Promise<MemoryDeleteResponse>; | ||
private deleteMemory; | ||
/** | ||
@@ -379,3 +289,3 @@ * Retrieves similar text from the memory. | ||
*/ | ||
retrieve(options: MemoryRetrieveOptions): Promise<MemoryRetrieveResponse[]>; | ||
private retrieveMemory; | ||
/** | ||
@@ -388,3 +298,3 @@ * Retrieves a list of documents inside a memory. | ||
*/ | ||
listDocs(options: MemoryListDocOptions): Promise<MemoryListDocResponse[]>; | ||
private listDocs; | ||
/** | ||
@@ -398,3 +308,3 @@ * Deletes a document from a memory. | ||
*/ | ||
deleteDoc(options: MemoryDeleteDocOptions): Promise<MemoryDeleteDocResponse>; | ||
private deleteDoc; | ||
/** | ||
@@ -412,3 +322,3 @@ * Uploads a document to the memory. | ||
*/ | ||
uploadDoc(options: MemoryUploadDocOptions): Promise<Response>; | ||
private uploadDocs; | ||
/** | ||
@@ -422,5 +332,116 @@ * Retries the embedding process for a specific document in memory. | ||
*/ | ||
retryDocEmbed(options: MemoryRetryDocEmbedOptions): Promise<MemoryRetryDocEmbedResponse>; | ||
private retryDocEmbed; | ||
} | ||
export { type BaseDeleteResponse, type Function, type GenerateOptions, type GenerateResponse, Memory, type MemoryCreateOptions, type MemoryCreateResponse, type MemoryDeleteDocOptions, type MemoryDeleteDocResponse, type MemoryDeleteOptions, type MemoryDeleteResponse, type MemoryListDocOptions, type MemoryListDocResponse, type MemoryListResponse, type MemoryOptions, type MemoryRetrieveOptions, type MemoryRetrieveResponse, type MemoryRetryDocEmbedOptions, type MemoryRetryDocEmbedResponse, type MemoryUploadDocOptions, type Message, Pipe, type PipeCreateOptions, type PipeCreateResponse, type PipeListResponse, type PipeOptions, type PipeUpdateOptions, type PipeUpdateResponse, type Role, type StreamChunk, type StreamOptions, type StreamResponse, type StreamText, type ToolCall, type Usage, type Variable, fromReadableStream, printStreamToStdout }; | ||
declare class Stream<Item> implements AsyncIterable<Item> { | ||
private iterator; | ||
controller: AbortController; | ||
constructor(iterator: () => AsyncIterator<Item>, controller: AbortController); | ||
/** | ||
* Creates a stream of AsyncIterator from a Server-Sent Events (SSE) response. | ||
* | ||
* @template Item - The type of items in the stream. | ||
* @param {Response} response - The SSE response object. | ||
* @param {AbortController} controller - The abort controller used to cancel the ongoing request. | ||
* @returns {Stream<AsyncIterator<Item, any, undefined>>} - The stream created from the SSE response. | ||
* @throws {Error} - If the stream has already been consumed. | ||
*/ | ||
static fromSSEResponse<Item>(response: Response, controller: AbortController): Stream<Item>; | ||
/** | ||
* Generates a Stream from a newline-separated ReadableStream | ||
* where each item is a JSON value. | ||
* | ||
* @template Item - The type of items in the stream. | ||
* @param {ReadableStream} readableStream - The readable stream to create the stream from. | ||
* @param {AbortController} controller - The abort controller to control the stream. | ||
* @returns {Stream<Item>} - The created stream. | ||
*/ | ||
static fromReadableStream<Item>(readableStream: ReadableStream, controller: AbortController): Stream<Item>; | ||
[Symbol.asyncIterator](): AsyncIterator<Item>; | ||
/** | ||
* Splits the stream into two streams which can be | ||
* independently read from at different speeds. | ||
*/ | ||
tee(): [Stream<Item>, Stream<Item>]; | ||
/** | ||
* Converts this stream to a newline-separated ReadableStream of | ||
* JSON stringified values in the stream which can be turned back into a Stream with `Stream.fromReadableStream()`. | ||
*/ | ||
toReadableStream(): ReadableStream; | ||
} | ||
interface GenerateOptions { | ||
messages?: Message[]; | ||
variables?: Variable[]; | ||
threadId?: string; | ||
chat?: boolean; | ||
} | ||
interface StreamOptions { | ||
messages?: Message[]; | ||
variables?: Variable[]; | ||
threadId?: string | null; | ||
chat?: boolean; | ||
} | ||
interface ChoiceGenerate { | ||
index: number; | ||
message: Message; | ||
logprobs: boolean | null; | ||
finish_reason: string; | ||
} | ||
interface ChoiceStream { | ||
index: number; | ||
delta: Delta; | ||
logprobs: boolean | null; | ||
finish_reason: string; | ||
} | ||
interface Delta { | ||
role?: Role; | ||
content?: string; | ||
tool_calls?: ToolCall[]; | ||
} | ||
interface Usage { | ||
prompt_tokens: number; | ||
completion_tokens: number; | ||
total_tokens: number; | ||
} | ||
interface GenerateResponse { | ||
completion: string; | ||
threadId?: string; | ||
id: string; | ||
object: string; | ||
created: number; | ||
model: string; | ||
choices: ChoiceGenerate[]; | ||
usage: Usage; | ||
system_fingerprint: string | null; | ||
} | ||
type StreamText = Stream<StreamChunk>; | ||
interface StreamResponse { | ||
stream: StreamText; | ||
threadId: string | null; | ||
} | ||
interface StreamChunk { | ||
id: string; | ||
object: string; | ||
created: number; | ||
model: string; | ||
choices: ChoiceStream[]; | ||
} | ||
interface PipeOptions { | ||
apiKey: string; | ||
baseUrl?: string; | ||
name?: string; | ||
} | ||
declare class Pipe { | ||
private request; | ||
constructor(options: PipeOptions); | ||
generateText(options: GenerateOptions): Promise<GenerateResponse>; | ||
streamText(options: StreamOptions): Promise<StreamResponse>; | ||
} | ||
/** | ||
* Print stream to standard output (console). | ||
* @param stream The stream to print | ||
*/ | ||
declare const printStreamToStdout: (stream: StreamText) => Promise<void>; | ||
export { type BaseDeleteResponse, type Function, type GenerateOptions, type GenerateResponse, Langbase, type LangbaseOptions, type MemoryCreateOptions, type MemoryCreateResponse, type MemoryDeleteDocOptions, type MemoryDeleteDocResponse, type MemoryDeleteOptions, type MemoryDeleteResponse, type MemoryListDocOptions, type MemoryListDocResponse, type MemoryListResponse, type MemoryRetrieveOptions, type MemoryRetrieveResponse, type MemoryRetryDocEmbedOptions, type MemoryRetryDocEmbedResponse, type MemoryUploadDocOptions, type Message, Pipe, type PipeCreateOptions, type PipeCreateResponse, type PipeListResponse, type PipeOptions, type PipeUpdateOptions, type PipeUpdateResponse, type Role, type StreamChunk, type StreamOptions, type StreamResponse, type StreamText, type ToolCall, type Usage, type Variable, fromReadableStream, printStreamToStdout }; |
@@ -24,3 +24,3 @@ "use strict"; | ||
__export(src_exports, { | ||
Memory: () => Memory, | ||
Langbase: () => Langbase, | ||
Pipe: () => Pipe, | ||
@@ -681,13 +681,34 @@ fromReadableStream: () => fromReadableStream, | ||
// src/pipes/pipes.ts | ||
// src/langbase/langbase.ts | ||
var import_core = require("@baseai/core"); | ||
var Pipe = class { | ||
var Langbase = class { | ||
constructor(options) { | ||
var _a; | ||
const baseUrl = "https://api.langbase.com"; | ||
this.apiKey = options.apiKey; | ||
this.request = new Request({ apiKey: options.apiKey, baseUrl }); | ||
this.pipeOptions = options; | ||
this.pipe = new import_core.Pipe({ | ||
apiKey: options.apiKey, | ||
// Langbase API key | ||
this.pipe = { | ||
list: this.listPipe.bind(this), | ||
create: this.createPipe.bind(this), | ||
update: this.updatePipe.bind(this), | ||
run: this.runPipe.bind(this) | ||
}; | ||
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) | ||
} | ||
} | ||
}; | ||
} | ||
async runPipe(options) { | ||
var _a; | ||
const pipe = new import_core.Pipe({ | ||
apiKey: this.apiKey, | ||
name: ((_a = options.name) == null ? void 0 : _a.trim()) || "", | ||
@@ -700,18 +721,4 @@ // Pipe name | ||
}); | ||
return await pipe.run({ ...options, runTools: false }); | ||
} | ||
async run(options) { | ||
return await this.pipe.run({ ...options, runTools: false }); | ||
} | ||
async generateText(options) { | ||
return this.request.post({ | ||
endpoint: options.chat ? "/beta/chat" : "/beta/generate", | ||
body: { ...options, stream: false } | ||
}); | ||
} | ||
async streamText(options) { | ||
return this.request.post({ | ||
endpoint: options.chat ? "/beta/chat" : "/beta/generate", | ||
body: { ...options, stream: true } | ||
}); | ||
} | ||
/** | ||
@@ -723,3 +730,3 @@ * Creates a new pipe on Langbase. | ||
*/ | ||
async create(options) { | ||
async createPipe(options) { | ||
return this.request.post({ | ||
@@ -736,3 +743,3 @@ endpoint: "/v1/pipes", | ||
*/ | ||
async update(options) { | ||
async updatePipe(options) { | ||
return this.request.post({ | ||
@@ -748,3 +755,3 @@ endpoint: `/v1/pipes/${options.name}`, | ||
*/ | ||
async list() { | ||
async listPipe() { | ||
return this.request.get({ | ||
@@ -754,18 +761,2 @@ endpoint: "/v1/pipes" | ||
} | ||
}; | ||
var printStreamToStdout = async (stream) => { | ||
var _a, _b; | ||
for await (const chunk of stream) { | ||
const textPart = ((_b = (_a = chunk.choices[0]) == null ? void 0 : _a.delta) == null ? void 0 : _b.content) || ""; | ||
process.stdout.write(textPart); | ||
} | ||
}; | ||
// src/memory/memory.ts | ||
var Memory = class { | ||
constructor(options) { | ||
const baseUrl = "https://api.langbase.com"; | ||
this.apiKey = options.apiKey; | ||
this.request = new Request({ apiKey: options.apiKey, baseUrl }); | ||
} | ||
/** | ||
@@ -779,3 +770,3 @@ * Creates a new memory on Langbase. | ||
*/ | ||
async create(options) { | ||
async createMemory(options) { | ||
return this.request.post({ | ||
@@ -791,3 +782,3 @@ endpoint: "/v1/memory", | ||
*/ | ||
async list() { | ||
async listMemory() { | ||
return this.request.get({ | ||
@@ -804,3 +795,3 @@ endpoint: "/v1/memory" | ||
*/ | ||
async delete(options) { | ||
async deleteMemory(options) { | ||
return this.request.delete({ | ||
@@ -819,3 +810,3 @@ endpoint: `/v1/memory/${options.name}` | ||
*/ | ||
async retrieve(options) { | ||
async retrieveMemory(options) { | ||
return this.request.post({ | ||
@@ -863,3 +854,3 @@ endpoint: "/v1/memory/retrieve", | ||
*/ | ||
async uploadDoc(options) { | ||
async uploadDocs(options) { | ||
try { | ||
@@ -902,2 +893,29 @@ const response = await this.request.post({ | ||
// src/pipes/pipes.ts | ||
var Pipe = class { | ||
constructor(options) { | ||
const baseUrl = "https://api.langbase.com"; | ||
this.request = new Request({ apiKey: options.apiKey, baseUrl }); | ||
} | ||
async generateText(options) { | ||
return this.request.post({ | ||
endpoint: options.chat ? "/beta/chat" : "/beta/generate", | ||
body: { ...options, stream: false } | ||
}); | ||
} | ||
async streamText(options) { | ||
return this.request.post({ | ||
endpoint: options.chat ? "/beta/chat" : "/beta/generate", | ||
body: { ...options, stream: true } | ||
}); | ||
} | ||
}; | ||
var printStreamToStdout = async (stream) => { | ||
var _a, _b; | ||
for await (const chunk of stream) { | ||
const textPart = ((_b = (_a = chunk.choices[0]) == null ? void 0 : _a.delta) == null ? void 0 : _b.content) || ""; | ||
process.stdout.write(textPart); | ||
} | ||
}; | ||
// src/index.ts | ||
@@ -907,3 +925,3 @@ __reExport(src_exports, require("@baseai/core/helpers"), module.exports); | ||
0 && (module.exports = { | ||
Memory, | ||
Langbase, | ||
Pipe, | ||
@@ -910,0 +928,0 @@ fromReadableStream, |
{ | ||
"name": "langbase", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
205518
2221