Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👌 IMPROVE: SDK structure #77

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/nextjs/app/langbase/pipe/run-stream/route.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
6 changes: 3 additions & 3 deletions examples/nextjs/app/langbase/pipe/run/route.ts
Original file line number Diff line number Diff line change
@@ -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',
});
Expand Down
8 changes: 4 additions & 4 deletions examples/nodejs/examples/memory/memory.create.ts
Original file line number Diff line number Diff line change
@@ -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'
});

Expand Down
6 changes: 3 additions & 3 deletions examples/nodejs/examples/memory/memory.delete.ts
Original file line number Diff line number Diff line change
@@ -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',
});

Expand Down
6 changes: 3 additions & 3 deletions examples/nodejs/examples/memory/memory.docs.delete.ts
Original file line number Diff line number Diff line change
@@ -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',
});
Expand Down
8 changes: 4 additions & 4 deletions examples/nodejs/examples/memory/memory.docs.list.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
6 changes: 3 additions & 3 deletions examples/nodejs/examples/memory/memory.docs.retry-embed.ts
Original file line number Diff line number Diff line change
@@ -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',
});
Expand Down
6 changes: 3 additions & 3 deletions examples/nodejs/examples/memory/memory.docs.upload.ts
Original file line number Diff line number Diff line change
@@ -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!,
});

Expand All @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions examples/nodejs/examples/memory/memory.list.ts
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions examples/nodejs/examples/memory/memory.retrieve.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
8 changes: 4 additions & 4 deletions examples/nodejs/examples/pipes/pipe.create.ts
Original file line number Diff line number Diff line change
@@ -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',
});

Expand Down
6 changes: 3 additions & 3 deletions examples/nodejs/examples/pipes/pipe.list.ts
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions examples/nodejs/examples/pipes/pipe.run.stream.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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!,
});

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,
Expand Down
6 changes: 3 additions & 3 deletions examples/nodejs/examples/pipes/pipe.run.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
6 changes: 3 additions & 3 deletions examples/nodejs/examples/pipes/pipe.update.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/langbase/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading
Loading