From e4a2acd9c0a736cffb32248ce1ac606811c186ee Mon Sep 17 00:00:00 2001 From: msaaddev Date: Fri, 28 Feb 2025 20:34:12 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20SDK=20syntax?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 +-- .../app/langbase/pipe/run-stream/route.ts | 2 +- .../nextjs/app/langbase/pipe/run/route.ts | 2 +- examples/nodejs/agents/index.js | 2 +- examples/nodejs/agents/index.ts | 2 +- examples/nodejs/agents/summarize.ts | 2 +- .../nodejs/examples/memory/memory.create.ts | 2 +- .../nodejs/examples/memory/memory.delete.ts | 2 +- .../examples/memory/memory.docs.delete.ts | 2 +- .../examples/memory/memory.docs.list.ts | 2 +- .../memory/memory.docs.retry-embed.ts | 2 +- .../examples/memory/memory.docs.upload.ts | 2 +- .../nodejs/examples/memory/memory.list.ts | 2 +- .../nodejs/examples/memory/memory.retrieve.ts | 2 +- examples/nodejs/examples/pipes/multi-agent.ts | 4 +- examples/nodejs/examples/pipes/pipe.create.ts | 2 +- examples/nodejs/examples/pipes/pipe.list.ts | 2 +- .../nodejs/examples/pipes/pipe.run.chat.ts | 4 +- .../examples/pipes/pipe.run.pipe.key.ts | 2 +- .../examples/pipes/pipe.run.stream.chat.ts | 4 +- .../examples/pipes/pipe.run.stream.llmkey.ts | 2 +- .../nodejs/examples/pipes/pipe.run.stream.ts | 2 +- examples/nodejs/examples/pipes/pipe.run.ts | 2 +- .../nodejs/examples/pipes/pipe.tool.stream.ts | 2 +- examples/nodejs/examples/pipes/pipe.tool.ts | 2 +- examples/nodejs/examples/pipes/pipe.update.ts | 2 +- .../nodejs/examples/threads/thread.delete.ts | 22 ---- .../examples/threads/thread.messages.add.ts | 26 ---- .../examples/threads/thread.messages.list.ts | 22 ---- examples/nodejs/examples/tools/crawl.ts | 6 +- examples/nodejs/examples/tools/web-search.ts | 2 +- examples/nodejs/package.json | 2 +- packages/langbase/src/langbase/langbase.ts | 112 +++++++++++++++--- packages/langbase/src/pipes/pipes.ts | 4 +- pnpm-lock.yaml | 4 +- 35 files changed, 142 insertions(+), 128 deletions(-) delete mode 100644 examples/nodejs/examples/threads/thread.delete.ts delete mode 100644 examples/nodejs/examples/threads/thread.messages.add.ts delete mode 100644 examples/nodejs/examples/threads/thread.messages.list.ts diff --git a/README.md b/README.md index abc1b5c..4bb4306 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ yarn add langbase ### Usage -You can [`langbase.pipe.run()`](https://langbase.com/docs/sdk/pipe/run) to generate or stream from a Pipe. +You can [`langbase.pipes.run()`](https://langbase.com/docs/sdk/pipe/run) to generate or stream from a Pipe. Check our [SDK documentation](https://langbase.com/docs/sdk) for more details. @@ -60,9 +60,9 @@ LANGBASE_API_KEY="your-api-key" --- -### Generate text [`langbase.pipe.run()`](https://langbase.com/docs/sdk/pipe/run) +### Generate text [`langbase.pipes.run()`](https://langbase.com/docs/sdk/pipe/run) -Set the `stream` to `false`. For more, check the API reference of [`langbase.pipe.run()`](https://langbase.com/docs/langbase-sdk/generate-text) +Set the `stream` to `false`. For more, check the API reference of [`langbase.pipes.run()`](https://langbase.com/docs/langbase-sdk/generate-text) ```ts import 'dotenv/config'; @@ -76,7 +76,7 @@ const langbase = new Langbase({ async function main() { // 2. Run the pipe with a question. - const response = await langbase.pipe.run({ + const response = await langbase.pipes.run({ stream: false, name: 'summary' // pipe name to run messages: [ @@ -96,9 +96,9 @@ main(); --- -### Stream text [`langbase.pipe.run()`](https://langbase.com/docs/sdk/pipe/run) +### Stream text [`langbase.pipes.run()`](https://langbase.com/docs/sdk/pipe/run) -Set the `stream` to `true`. For more, check the API reference of [`langbase.pipe.run()`](https://langbase.com/docs/langbase-sdk/generate-text) +Set the `stream` to `true`. For more, check the API reference of [`langbase.pipes.run()`](https://langbase.com/docs/langbase-sdk/generate-text) ```ts import 'dotenv/config'; @@ -114,7 +114,7 @@ async function main() { const userMsg = 'Who is an AI Engineer?'; // 2. Run the pipe with a question. - const {****stre**am**} = await langbase.pipe.run({ + const {stream} = await langbase.pipes.run({ stream: true, name: 'summary', // pipe name to run messages: [{role: 'user', content: userMsg}], diff --git a/examples/nextjs/app/langbase/pipe/run-stream/route.ts b/examples/nextjs/app/langbase/pipe/run-stream/route.ts index 522b877..8b463c5 100644 --- a/examples/nextjs/app/langbase/pipe/run-stream/route.ts +++ b/examples/nextjs/app/langbase/pipe/run-stream/route.ts @@ -10,7 +10,7 @@ export async function POST(req: NextRequest) { }); // 2. Generate a stream by asking a question - const {stream, threadId} = await langbase.pipe.run({ + const {stream, threadId} = await langbase.pipes.run({ messages: options.messages, 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 a89fbba..b6c165a 100644 --- a/examples/nextjs/app/langbase/pipe/run/route.ts +++ b/examples/nextjs/app/langbase/pipe/run/route.ts @@ -10,7 +10,7 @@ export async function POST(req: NextRequest) { }); // 2. Generate a stream by asking a question - const result = await langbase.pipe.run({ + const result = await langbase.pipes.run({ messages: [{role: 'user', content: prompt}], name: 'summary', stream: false diff --git a/examples/nodejs/agents/index.js b/examples/nodejs/agents/index.js index 7b5d793..ac8510c 100644 --- a/examples/nodejs/agents/index.js +++ b/examples/nodejs/agents/index.js @@ -6,7 +6,7 @@ export default async function Route(request, env) { apiKey: 'API_KEY', }); - const pipes = await langbase.pipe.list(); + const pipes = await langbase.pipes.list(); // User code will be injected here return new Response(JSON.stringify(pipes), {status: 200}); diff --git a/examples/nodejs/agents/index.ts b/examples/nodejs/agents/index.ts index 7b5d793..ac8510c 100644 --- a/examples/nodejs/agents/index.ts +++ b/examples/nodejs/agents/index.ts @@ -6,7 +6,7 @@ export default async function Route(request, env) { apiKey: 'API_KEY', }); - const pipes = await langbase.pipe.list(); + const pipes = await langbase.pipes.list(); // User code will be injected here return new Response(JSON.stringify(pipes), {status: 200}); diff --git a/examples/nodejs/agents/summarize.ts b/examples/nodejs/agents/summarize.ts index 7b5d793..ac8510c 100644 --- a/examples/nodejs/agents/summarize.ts +++ b/examples/nodejs/agents/summarize.ts @@ -6,7 +6,7 @@ export default async function Route(request, env) { apiKey: 'API_KEY', }); - const pipes = await langbase.pipe.list(); + const pipes = await langbase.pipes.list(); // User code will be injected here return new Response(JSON.stringify(pipes), {status: 200}); diff --git a/examples/nodejs/examples/memory/memory.create.ts b/examples/nodejs/examples/memory/memory.create.ts index c431618..f259304 100644 --- a/examples/nodejs/examples/memory/memory.create.ts +++ b/examples/nodejs/examples/memory/memory.create.ts @@ -6,7 +6,7 @@ const langbase = new Langbase({ }); async function main() { - const response = await langbase.memory.create({ + const response = await langbase.memories.create({ name: 'memory-sdk', 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 067308f..4ec7dbb 100644 --- a/examples/nodejs/examples/memory/memory.delete.ts +++ b/examples/nodejs/examples/memory/memory.delete.ts @@ -6,7 +6,7 @@ const langbase = new Langbase({ }); async function main() { - const response = await langbase.memory.delete({ + const response = await langbase.memories.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 099e0d0..c3369e7 100644 --- a/examples/nodejs/examples/memory/memory.docs.delete.ts +++ b/examples/nodejs/examples/memory/memory.docs.delete.ts @@ -6,7 +6,7 @@ const langbase = new Langbase({ }); async function main() { - const response = await langbase.memory.documents.delete({ + const response = await langbase.memories.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 e315feb..bf1cebf 100644 --- a/examples/nodejs/examples/memory/memory.docs.list.ts +++ b/examples/nodejs/examples/memory/memory.docs.list.ts @@ -6,7 +6,7 @@ const langbase = new Langbase({ }); async function main() { - const response = await langbase.memory.documents.list({ + const response = await langbase.memories.documents.list({ memoryName: 'memory-sdk', }); diff --git a/examples/nodejs/examples/memory/memory.docs.retry-embed.ts b/examples/nodejs/examples/memory/memory.docs.retry-embed.ts index f684a18..7418c24 100644 --- a/examples/nodejs/examples/memory/memory.docs.retry-embed.ts +++ b/examples/nodejs/examples/memory/memory.docs.retry-embed.ts @@ -6,7 +6,7 @@ const langbase = new Langbase({ }); async function main() { - const response = await langbase.memory.documents.embedding.retry({ + const response = await langbase.memories.documents.embeddings.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 97bf8f0..754077d 100644 --- a/examples/nodejs/examples/memory/memory.docs.upload.ts +++ b/examples/nodejs/examples/memory/memory.docs.upload.ts @@ -15,7 +15,7 @@ async function main() { 'memory.docs.upload.ts', ); - const response = await langbase.memory.documents.upload({ + const response = await langbase.memories.documents.upload({ document: fs.readFileSync(src), memoryName: 'memory-sdk', documentName: 'memory.docs.upload.ts', diff --git a/examples/nodejs/examples/memory/memory.list.ts b/examples/nodejs/examples/memory/memory.list.ts index 9d78019..e7bd62e 100644 --- a/examples/nodejs/examples/memory/memory.list.ts +++ b/examples/nodejs/examples/memory/memory.list.ts @@ -6,7 +6,7 @@ const langbase = new Langbase({ }); async function main() { - const response = await langbase.memory.list(); + const response = await langbase.memories.list(); console.log(response); } diff --git a/examples/nodejs/examples/memory/memory.retrieve.ts b/examples/nodejs/examples/memory/memory.retrieve.ts index 22cdefd..1e664a4 100644 --- a/examples/nodejs/examples/memory/memory.retrieve.ts +++ b/examples/nodejs/examples/memory/memory.retrieve.ts @@ -6,7 +6,7 @@ const langbase = new Langbase({ }); async function main() { - const response = await langbase.memory.retrieve({ + const response = await langbase.memories.retrieve({ memory: [ { name: 'langbase-docs', diff --git a/examples/nodejs/examples/pipes/multi-agent.ts b/examples/nodejs/examples/pipes/multi-agent.ts index bfd1563..fc48e5e 100644 --- a/examples/nodejs/examples/pipes/multi-agent.ts +++ b/examples/nodejs/examples/pipes/multi-agent.ts @@ -12,7 +12,7 @@ const langbase = new Langbase({ async function main() { // First agent: Summarize text const summarizeAgent = async (text: string) => { - const response = await langbase.pipe.run({ + const response = await langbase.pipes.run({ stream: false, name: "summarize", messages: [ @@ -31,7 +31,7 @@ async function main() { // Second agent: Generate questions const questionsAgent = async (summary: string) => { - const response = await langbase.pipe.run({ + const response = await langbase.pipes.run({ stream: false, name: "generate-questions", messages: [ diff --git a/examples/nodejs/examples/pipes/pipe.create.ts b/examples/nodejs/examples/pipes/pipe.create.ts index 4e15a96..92e8ef7 100644 --- a/examples/nodejs/examples/pipes/pipe.create.ts +++ b/examples/nodejs/examples/pipes/pipe.create.ts @@ -6,7 +6,7 @@ const langbase = new Langbase({ }); async function main() { - const response = await langbase.pipe.create({ + const response = await langbase.pipes.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 bebd2b6..94fcced 100644 --- a/examples/nodejs/examples/pipes/pipe.list.ts +++ b/examples/nodejs/examples/pipes/pipe.list.ts @@ -6,7 +6,7 @@ const langbase = new Langbase({ }); async function main() { - const response = await langbase.pipe.list(); + const response = await langbase.pipes.list(); console.log(response); } diff --git a/examples/nodejs/examples/pipes/pipe.run.chat.ts b/examples/nodejs/examples/pipes/pipe.run.chat.ts index 9141e1b..a100559 100644 --- a/examples/nodejs/examples/pipes/pipe.run.chat.ts +++ b/examples/nodejs/examples/pipes/pipe.run.chat.ts @@ -7,7 +7,7 @@ const langbase = new Langbase({ async function main() { // Message 1: Tell something to the LLM. - const response1 = await langbase.pipe.run({ + const response1 = await langbase.pipes.run({ name: 'summary', messages: [{role: 'user', content: 'My company is called Langbase'}], }); @@ -17,7 +17,7 @@ async function main() { // Message 2: Ask something about the first message. // Continue the conversation in the same thread by sending // `threadId` from the second message onwards. - const response2 = await langbase.pipe.run({ + const response2 = await langbase.pipes.run({ name: 'summary', threadId: response1.threadId!, messages: [{role: 'user', content: 'Tell me the name of my company?'}], diff --git a/examples/nodejs/examples/pipes/pipe.run.pipe.key.ts b/examples/nodejs/examples/pipes/pipe.run.pipe.key.ts index c355c5a..09d63ae 100644 --- a/examples/nodejs/examples/pipes/pipe.run.pipe.key.ts +++ b/examples/nodejs/examples/pipes/pipe.run.pipe.key.ts @@ -9,7 +9,7 @@ async function main() { const userMsg = 'Who is an AI Engineer?'; // Get readable stream - const {stream, threadId, rawResponse} = await langbase.pipe.run({ + const {stream, threadId, rawResponse} = await langbase.pipes.run({ messages: [{role: 'user', content: userMsg}], stream: true, rawResponse: true, diff --git a/examples/nodejs/examples/pipes/pipe.run.stream.chat.ts b/examples/nodejs/examples/pipes/pipe.run.stream.chat.ts index 8388b40..fb1cf07 100644 --- a/examples/nodejs/examples/pipes/pipe.run.stream.chat.ts +++ b/examples/nodejs/examples/pipes/pipe.run.stream.chat.ts @@ -6,7 +6,7 @@ const langbase = new Langbase({ }); // Message 1: Tell something to the LLM. -const response1 = await langbase.pipe.run({ +const response1 = await langbase.pipes.run({ name: 'summary', stream: true, messages: [{role: 'user', content: 'My company is called Langbase'}], @@ -21,7 +21,7 @@ runner1.on('content', content => { // Message 2: Ask something about the first message. // Continue the conversation in the same thread by sending // `threadId` from the second message onwards. -const response2 = await langbase.pipe.run({ +const response2 = await langbase.pipes.run({ name: 'summary', stream: true, threadId: response1.threadId!, diff --git a/examples/nodejs/examples/pipes/pipe.run.stream.llmkey.ts b/examples/nodejs/examples/pipes/pipe.run.stream.llmkey.ts index 336f302..f9f854c 100644 --- a/examples/nodejs/examples/pipes/pipe.run.stream.llmkey.ts +++ b/examples/nodejs/examples/pipes/pipe.run.stream.llmkey.ts @@ -9,7 +9,7 @@ async function main() { const userMsg = 'Who is an AI Engineer?'; // Get readable stream - const {stream, threadId, rawResponse} = await langbase.pipe.run({ + const {stream, threadId, rawResponse} = await langbase.pipes.run({ messages: [{role: 'user', content: userMsg}], stream: true, rawResponse: true, diff --git a/examples/nodejs/examples/pipes/pipe.run.stream.ts b/examples/nodejs/examples/pipes/pipe.run.stream.ts index 50bbf71..d4cae9e 100644 --- a/examples/nodejs/examples/pipes/pipe.run.stream.ts +++ b/examples/nodejs/examples/pipes/pipe.run.stream.ts @@ -9,7 +9,7 @@ async function main() { const userMsg = 'Who is an AI Engineer?'; // Get readable stream - const {stream, threadId, rawResponse} = await langbase.pipe.run({ + const {stream, threadId, rawResponse} = await langbase.pipes.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 441cabf..84eb451 100644 --- a/examples/nodejs/examples/pipes/pipe.run.ts +++ b/examples/nodejs/examples/pipes/pipe.run.ts @@ -8,7 +8,7 @@ const langbase = new Langbase({ async function main() { const userMsg = 'Who is an AI Engineer?'; - const response = await langbase.pipe.run({ + const response = await langbase.pipes.run({ messages: [ { role: 'user', diff --git a/examples/nodejs/examples/pipes/pipe.tool.stream.ts b/examples/nodejs/examples/pipes/pipe.tool.stream.ts index 268bfd3..c2ddde3 100644 --- a/examples/nodejs/examples/pipes/pipe.tool.stream.ts +++ b/examples/nodejs/examples/pipes/pipe.tool.stream.ts @@ -8,7 +8,7 @@ const langbase = new Langbase({ async function main() { const userMsg = "What's the weather in SF"; - const response = await langbase.pipe.run({ + const response = await langbase.pipes.run({ messages: [ { role: 'user', diff --git a/examples/nodejs/examples/pipes/pipe.tool.ts b/examples/nodejs/examples/pipes/pipe.tool.ts index 4f1ecc5..3ac020d 100644 --- a/examples/nodejs/examples/pipes/pipe.tool.ts +++ b/examples/nodejs/examples/pipes/pipe.tool.ts @@ -8,7 +8,7 @@ const langbase = new Langbase({ async function main() { const userMsg = "What's the weather in SF"; - const response = await langbase.pipe.run({ + const response = await langbase.pipes.run({ messages: [ { role: 'user', diff --git a/examples/nodejs/examples/pipes/pipe.update.ts b/examples/nodejs/examples/pipes/pipe.update.ts index 039fefc..1f9aad9 100644 --- a/examples/nodejs/examples/pipes/pipe.update.ts +++ b/examples/nodejs/examples/pipes/pipe.update.ts @@ -6,7 +6,7 @@ const langbase = new Langbase({ }); async function main() { - const response = await langbase.pipe.update({ + const response = await langbase.pipes.update({ name: 'summary-pipe', description: 'This is a pipe updated with the SDK', model: 'google:gemini-1.5-flash-8b-latest', diff --git a/examples/nodejs/examples/threads/thread.delete.ts b/examples/nodejs/examples/threads/thread.delete.ts deleted file mode 100644 index 0b40b31..0000000 --- a/examples/nodejs/examples/threads/thread.delete.ts +++ /dev/null @@ -1,22 +0,0 @@ -import 'dotenv/config'; -import {Langbase} from 'langbase'; -import {v4 as uuid} from 'uuid'; - -const langbase = new Langbase({ - apiKey: process.env.LANGBASE_API_KEY!, -}); - -async function main() { - // get thread id here - // we are using a random id for now - const threadId = uuid(); - console.log('Thread id:', threadId); - - const hasThreadDeleted = await langbase.thread.delete({ - threadId, - }); - - console.log('Thread deleted:', hasThreadDeleted); -} - -main(); diff --git a/examples/nodejs/examples/threads/thread.messages.add.ts b/examples/nodejs/examples/threads/thread.messages.add.ts deleted file mode 100644 index 7c9189d..0000000 --- a/examples/nodejs/examples/threads/thread.messages.add.ts +++ /dev/null @@ -1,26 +0,0 @@ -import 'dotenv/config'; -import {Langbase} from 'langbase'; -import {v4 as uuid} from 'uuid'; - -const langbase = new Langbase({ - apiKey: process.env.LANGBASE_API_KEY!, -}); - -async function main() { - const threadId = uuid(); - console.log('Thread id:', threadId); - - const threadMessages = await langbase.thread.messages.add({ - threadId, - messages: [ - { - role: 'user', - content: 'Hi, how are you?', - }, - ], - }); - - console.log('Thread messages:', threadMessages); -} - -main(); diff --git a/examples/nodejs/examples/threads/thread.messages.list.ts b/examples/nodejs/examples/threads/thread.messages.list.ts deleted file mode 100644 index 4dffa3d..0000000 --- a/examples/nodejs/examples/threads/thread.messages.list.ts +++ /dev/null @@ -1,22 +0,0 @@ -import 'dotenv/config'; -import {Langbase} from 'langbase'; -import {v4 as uuid} from 'uuid'; - -const langbase = new Langbase({ - apiKey: process.env.LANGBASE_API_KEY!, -}); - -async function main() { - // get thread id here - // we use a random id for now - const threadId = uuid(); - console.log('Thread id:', threadId); - - const threadMessages = await langbase.thread.messages.list({ - threadId, - }); - - console.log('Thread messages:', threadMessages); -} - -main(); diff --git a/examples/nodejs/examples/tools/crawl.ts b/examples/nodejs/examples/tools/crawl.ts index 0dc5be8..c530912 100644 --- a/examples/nodejs/examples/tools/crawl.ts +++ b/examples/nodejs/examples/tools/crawl.ts @@ -13,10 +13,10 @@ const langbase = new Langbase({ * @link https://spider.cloud/docs/quickstart */ async function main() { - const results = await langbase.tool.crawl({ + const results = await langbase.tools.crawl({ url: ['https://langbase.com', 'https://langbase.com/about'], - max_pages: 1, - api_key: process.env.CRAWL_KEY, + maxPages: 1, + apiKey: process.env.CRAWL_KEY, }); console.log(results); diff --git a/examples/nodejs/examples/tools/web-search.ts b/examples/nodejs/examples/tools/web-search.ts index bbebb89..35c6e73 100644 --- a/examples/nodejs/examples/tools/web-search.ts +++ b/examples/nodejs/examples/tools/web-search.ts @@ -7,7 +7,7 @@ const langbase = new Langbase({ }); async function main() { - const results = await langbase.tool.webSearch({ + const results = await langbase.tools.webSearch({ service: 'exa', totalResults: 2, query: 'What is Langbase?', diff --git a/examples/nodejs/package.json b/examples/nodejs/package.json index 307a6ec..51100f8 100644 --- a/examples/nodejs/package.json +++ b/examples/nodejs/package.json @@ -44,7 +44,7 @@ "license": "UNLICENSED", "dependencies": { "dotenv": "^16.4.5", - "langbase": "^1.1.35", + "langbase": "workspace:*", "uuid": "^11.1.0", "@langbase/cli": "workspace:*" } diff --git a/packages/langbase/src/langbase/langbase.ts b/packages/langbase/src/langbase/langbase.ts index 933a04f..977e174 100644 --- a/packages/langbase/src/langbase/langbase.ts +++ b/packages/langbase/src/langbase/langbase.ts @@ -359,6 +359,21 @@ export class Langbase { private request: Request; private apiKey: string; private baseUrl: string; + public pipes: { + list: () => Promise; + create: (options: PipeCreateOptions) => Promise; + update: (options: PipeUpdateOptions) => Promise; + run: { + (options: RunOptionsStream): Promise; + (options: RunOptions): Promise; + }; + }; + + /** + * @deprecated This method is deprecated and will be removed in a future version. + * + * Please use `langbase.pipes` + */ public pipe: { list: () => Promise; create: (options: PipeCreateOptions) => Promise; @@ -368,7 +383,8 @@ export class Langbase { (options: RunOptions): Promise; }; }; - public memory: { + + public memories: { create: (options: MemoryCreateOptions) => Promise; delete: (options: MemoryDeleteOptions) => Promise; retrieve: ( @@ -383,7 +399,7 @@ export class Langbase { options: MemoryDeleteDocOptions, ) => Promise; upload: (options: MemoryUploadDocOptions) => Promise; - embedding: { + embeddings: { retry: ( options: MemoryRetryDocEmbedOptions, ) => Promise; @@ -391,14 +407,47 @@ export class Langbase { }; }; - public thread: { - messages: { - add: (options: AddMessageOptions) => Promise; - list: (options: ListMessagesOptions) => Promise; + /** + * @deprecated This method is deprecated and will be removed in a future version. + * + * Please use `langbase.memories` + */ + 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; + }; }; - delete: (options: DeleteThreadOptions) => Promise; }; + // public thread: { + // messages: { + // add: (options: AddMessageOptions) => Promise; + // list: (options: ListMessagesOptions) => Promise; + // }; + // delete: (options: DeleteThreadOptions) => Promise; + // }; + + /** + * @deprecated This method is deprecated and will be removed in a future version. + * + * Please use `langbase.tools` + */ public tool: { crawl: (options: ToolCrawlOptions) => Promise; webSearch: ( @@ -406,6 +455,13 @@ export class Langbase { ) => Promise; }; + public tools: { + crawl: (options: ToolCrawlOptions) => Promise; + webSearch: ( + options: ToolWebSearchOptions, + ) => Promise; + }; + public embed: (options: EmbedOptions) => Promise; public chunk: (options: ChunkOptions) => Promise; public parse: (options: ParseOptions) => Promise; @@ -426,6 +482,13 @@ export class Langbase { run: this.runPipe.bind(this), }; + this.pipes = { + 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), @@ -442,6 +505,27 @@ export class Langbase { }, }; + // Initialize memory property with method bindings + this.memories = { + 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), + embeddings: { + retry: this.retryDocEmbed.bind(this), + }, + }, + }; + + this.tools = { + crawl: this.webCrawl.bind(this), + webSearch: this.webSearch.bind(this), + }; + this.tool = { crawl: this.webCrawl.bind(this), webSearch: this.webSearch.bind(this), @@ -450,13 +534,13 @@ export class Langbase { this.embed = this.generateEmbeddings.bind(this); this.chunk = this.chunkDocument.bind(this); this.parse = this.parseDocument.bind(this); - this.thread = { - messages: { - add: this.addMessages.bind(this), - list: this.listMessages.bind(this), - }, - delete: this.deleteThread.bind(this), - }; + // this.thread = { + // messages: { + // add: this.addMessages.bind(this), + // list: this.listMessages.bind(this), + // }, + // delete: this.deleteThread.bind(this), + // }; } private async runPipe( diff --git a/packages/langbase/src/pipes/pipes.ts b/packages/langbase/src/pipes/pipes.ts index f392812..71ffe9c 100644 --- a/packages/langbase/src/pipes/pipes.ts +++ b/packages/langbase/src/pipes/pipes.ts @@ -80,7 +80,7 @@ export class Pipe { /** * @deprecated This method is deprecated and will be removed in a future version. * - * Please use `langbase.pipe.run()` instead + * Please use `langbase.pipes.run()` instead * @see https://langbase.com/docs/sdk/pipe/run */ async generateText(options: GenerateOptions): Promise { @@ -93,7 +93,7 @@ export class Pipe { /** * @deprecated This method is deprecated and will be removed in a future version. * - * Please use `langbase.pipe.run()` instead + * Please use `langbase.pipes.run()` instead * @see https://langbase.com/docs/sdk/pipe/run */ async streamText(options: StreamOptions): Promise { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4d96625..74e59f8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -115,8 +115,8 @@ importers: specifier: ^16.4.5 version: 16.4.7 langbase: - specifier: ^1.1.35 - version: 1.1.35(react@18.3.1)(ws@8.18.0) + specifier: workspace:* + version: link:../../packages/langbase uuid: specifier: ^11.1.0 version: 11.1.0