Skip to content

Commit fcd2062

Browse files
committed
📖 DOC: Lingo
1 parent ccffaaf commit fcd2062

6 files changed

Lines changed: 105 additions & 93 deletions

File tree

examples/everything/package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"private": true,
3-
"name": "everything",
4-
"version": "0.0.0",
5-
"description": "Everything example",
6-
"type": "module",
7-
"main": "index.js",
8-
"scripts": {
9-
"test": "npx tsx index.ts",
10-
"generate-text": "npx tsx generate-text.ts",
11-
"stream-text": "npx tsx stream-text.ts"
12-
},
13-
"keywords": [],
14-
"author": "Ahmad Awais <me@AhmadAwais.com> (https://twitter.com/MrAhmadAwais)",
15-
"license": "UNLICENSED",
16-
"dependencies": {
17-
"dotenv": "^16.4.5",
18-
"langbase": "^0.2.0"
19-
}
2+
"private": true,
3+
"name": "everything",
4+
"version": "0.0.0",
5+
"description": "Everything example",
6+
"type": "module",
7+
"main": "index.js",
8+
"scripts": {
9+
"test": "npx tsx index.ts",
10+
"generate-text": "npx tsx generate-text.ts",
11+
"stream-text": "npx tsx stream-text.ts"
12+
},
13+
"keywords": [],
14+
"author": "Ahmad Awais <me@AhmadAwais.com> (https://twitter.com/MrAhmadAwais)",
15+
"license": "UNLICENSED",
16+
"dependencies": {
17+
"dotenv": "^16.4.5",
18+
"langbase": "^0.2.3"
19+
}
2020
}

examples/nextjs/README.md

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
1+
# ⌘ Langbase SDK Next.js Example
22

3-
## Getting Started
3+
- [Next.js Example](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs)
4+
- TypeScript code
5+
- [React component](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs/components/langbase) to display the response
6+
- [API Route handlers](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs/app/api/langbase/pipe) to send requests to ⌘ Langbase
47

58
First, run the development server:
69

@@ -15,22 +18,3 @@ bun dev
1518
```
1619

1720
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18-
19-
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20-
21-
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
22-
23-
## Learn More
24-
25-
To learn more about Next.js, take a look at the following resources:
26-
27-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29-
30-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
31-
32-
## Deploy on Vercel
33-
34-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35-
36-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

examples/nextjs/package.json

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
{
2-
"name": "nextjs",
3-
"version": "0.0.0",
4-
"private": true,
5-
"scripts": {
6-
"dev": "next dev",
7-
"build": "next build",
8-
"start": "next start",
9-
"lint": "next lint"
10-
},
11-
"dependencies": {
12-
"@radix-ui/react-slot": "^1.1.0",
13-
"class-variance-authority": "^0.7.0",
14-
"clsx": "^2.1.1",
15-
"langbase": "^0.2.0",
16-
"lucide-react": "^0.416.0",
17-
"mxcn": "^2.0.0",
18-
"next": "14.2.5",
19-
"openai": "^4.53.0",
20-
"react": "^18",
21-
"react-dom": "^18",
22-
"tailwind-merge": "^2.4.0",
23-
"tailwindcss-animate": "^1.0.7"
24-
},
25-
"devDependencies": {
26-
"@types/node": "^20",
27-
"@types/react": "^18",
28-
"@types/react-dom": "^18",
29-
"eslint": "^8",
30-
"eslint-config-next": "14.2.5",
31-
"mini-css-extract-plugin": "^2.9.0",
32-
"postcss": "^8",
33-
"tailwindcss": "^3.4.1",
34-
"typescript": "^5"
35-
}
2+
"name": "nextjs",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "next build",
8+
"start": "next start",
9+
"lint": "next lint"
10+
},
11+
"dependencies": {
12+
"@radix-ui/react-slot": "^1.1.0",
13+
"class-variance-authority": "^0.7.0",
14+
"clsx": "^2.1.1",
15+
"langbase": "^0.2.3",
16+
"lucide-react": "^0.416.0",
17+
"mxcn": "^2.0.0",
18+
"next": "14.2.5",
19+
"openai": "^4.53.0",
20+
"react": "^18",
21+
"react-dom": "^18",
22+
"tailwind-merge": "^2.4.0",
23+
"tailwindcss-animate": "^1.0.7"
24+
},
25+
"devDependencies": {
26+
"@types/node": "^20",
27+
"@types/react": "^18",
28+
"@types/react-dom": "^18",
29+
"eslint": "^8",
30+
"eslint-config-next": "14.2.5",
31+
"mini-css-extract-plugin": "^2.9.0",
32+
"postcss": "^8",
33+
"tailwindcss": "^3.4.1",
34+
"typescript": "^5"
35+
}
3636
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"type-check": "turbo type-check",
1414
"version-packages": "changeset version && pnpm clean-examples && pnpm install --no-frozen-lockfile",
1515
"clean": "turbo clean",
16-
"xclean": "turbo clean && rm -rf node_modules",
16+
"clean-all": "turbo clean && rm -rf node_modules",
1717
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
1818
"release": "turbo clean && turbo build && changeset publish",
1919
"releaseDocs": "turbo build --filter=docs^... && changeset publish",

packages/langbase/readme.md

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,48 @@ yarn add langbase
2626

2727
### Usage
2828

29-
You can `generateText` or `streamText` based on the type of a pipe.
29+
You can [`generateText`](https://langbase.com/docs/langbase-sdk/generate-text) or [`streamText`](https://langbase.com/docs/langbase-sdk/stream-text) based on the type of a pipe.
3030

31-
Check our [SDK documentation](https://langbase.com/docs) for more details.
31+
Check our [SDK documentation](https://langbase.com/docs/langbase-sdk/overview) for more details.
3232

3333
### Example projects
3434

3535
Check the following examples:
36+
3637
- [Node: Generate Text](https://github.com/LangbaseInc/langbase-sdk/blob/main/examples/everything/generate-text.ts)
3738
- [Node: Stream Text](https://github.com/LangbaseInc/langbase-sdk/blob/main/examples/everything/stream-text.ts)
3839
- [Next.js Example](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs)
3940
- TypeScript code
4041
- [React component](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs/components/langbase) to display the response
4142
- [API Route handlers](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs/app/api/langbase/pipe) to send requests to ⌘ Langbase
4243

43-
### Demo code:
44+
### Node.js Example Code
45+
46+
47+
## Node.js Examples
48+
49+
### Add a `.env` file with your Pipe API key
50+
51+
```bash
52+
# Add your Pipe API key here.
53+
LANGBASE_PIPE_API_KEY="pipe_12345`"
54+
```
55+
56+
---
57+
58+
### Generate text [`generateText()`](https://langbase.com/docs/langbase-sdk/generate-text)
4459
45-
```TypeScript
60+
For more check the API reference of [`generateText()`](https://langbase.com/docs/langbase-sdk/generate-text)
61+
62+
```ts
4663
import 'dotenv/config';
4764
import {Pipe} from 'langbase';
4865
49-
// STREAM: OFF
50-
console.log('STREAM-OFF: generateText()');
51-
5266
// 1. Initiate the Pipe.
5367
const pipe = new Pipe({
5468
// Make sure you have a .env file with any pipe you wanna use.
5569
// As a demo we're using a pipe that has less wordy responses.
56-
apiKey: process.env.PIPE_LESS_WORDY!,
70+
apiKey: process.env.LANGBASE_PIPE_API_KEY!,
5771
});
5872
5973
// 3. Generate the text by asking a question.
@@ -63,12 +77,24 @@ const result = await pipe.generateText({
6377
6478
// 4. Done: You got the generated completion.
6579
console.log(result.completion);
80+
```
6681
67-
// ======= OR ======== //
82+
---
6883
69-
// STREAM: ON
70-
console.log('');
71-
console.log('STREAM-ON: streamText()');
84+
### Stream text [`streamText()`](https://langbase.com/docs/langbase-sdk/stream-text)
85+
86+
For more check the API reference of [`streamText()`](https://langbase.com/docs/langbase-sdk/stream-text)
87+
88+
```ts
89+
import 'dotenv/config';
90+
import {Pipe} from 'langbase';
91+
92+
// 1. Initiate the Pipe.
93+
const pipe = new Pipe({
94+
// Make sure you have a .env file with any pipe you wanna use.
95+
// As a demo we're using a pipe that has less wordy responses.
96+
apiKey: process.env.LANGBASE_PIPE_API_KEY!,
97+
});
7298
7399
// 2. Generate a stream by asking a question
74100
const stream = await pipe.streamText({
@@ -84,3 +110,5 @@ for await (const chunk of stream) {
84110
process.stdout.write(textPart);
85111
}
86112
```
113+
114+
Check out [more examples in the docs](https://langbase.com/docs/langbase-sdk/examples) →

pnpm-lock.yaml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)