Skip to content

Commit 809596a

Browse files
committed
👌 IMPROVE: Format
1 parent 284e9a7 commit 809596a

33 files changed

+293
-303
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ To test the changes locally, you can run the following command:
3232

3333
```json
3434
{
35-
"dependencies": {
36-
"langbase": "workspace:*"
37-
},
35+
"dependencies": {
36+
"langbase": "workspace:*"
37+
}
3838
}
3939
```
4040

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ Check our [SDK documentation](https://langbase.com/docs/sdk) for more details.
4040

4141
Check the following examples:
4242

43-
- [Node: Generate Text](https://github.com/LangbaseInc/langbase-sdk/blob/main/examples/nodejs/pipes/pipe.run.ts)
44-
- [Node: Stream Text](https://github.com/LangbaseInc/langbase-sdk/blob/main/examples/nodejs/pipes/pipe.run.stream.ts)
45-
- [Next.js Example](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs)
46-
- TypeScript code
47-
- [React component](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs/components/langbase) to display the response
48-
- [API Route handlers](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs/app/langbase/pipe/run) to send requests to ⌘ Langbase
43+
- [Node: Generate Text](https://github.com/LangbaseInc/langbase-sdk/blob/main/examples/nodejs/pipes/pipe.run.ts)
44+
- [Node: Stream Text](https://github.com/LangbaseInc/langbase-sdk/blob/main/examples/nodejs/pipes/pipe.run.stream.ts)
45+
- [Next.js Example](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs)
46+
- TypeScript code
47+
- [React component](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs/components/langbase) to display the response
48+
- [API Route handlers](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs/app/langbase/pipe/run) to send requests to ⌘ Langbase
4949

5050
### Node.js Example Code
5151

@@ -106,27 +106,27 @@ import {getRunner, Langbase} from 'langbase';
106106

107107
// 1. Initiate the Langbase.
108108
const langbase = new Langbase({
109-
// Make sure you have a .env file with LANGBASE_API_KEY.
110-
apiKey: process.env.LANGBASE_API_KEY!,
109+
// Make sure you have a .env file with LANGBASE_API_KEY.
110+
apiKey: process.env.LANGBASE_API_KEY!,
111111
});
112112

113113
async function main() {
114-
const userMsg = 'Who is an AI Engineer?';
115-
116-
// 2. Run the pipe with a question.
117-
const {stream} = await langbase.pipes.run({
118-
stream: true,
119-
name: 'summary', // pipe name to run
120-
messages: [{role: 'user', content: userMsg}],
121-
});
122-
123-
// 3. Get the runner and listen to the content.
124-
const runner = getRunner(stream);
125-
126-
// 4. Print the response.
127-
runner.on('content', content => {
128-
process.stdout.write(content);
129-
});
114+
const userMsg = 'Who is an AI Engineer?';
115+
116+
// 2. Run the pipe with a question.
117+
const {stream} = await langbase.pipes.run({
118+
stream: true,
119+
name: 'summary', // pipe name to run
120+
messages: [{role: 'user', content: userMsg}],
121+
});
122+
123+
// 3. Get the runner and listen to the content.
124+
const runner = getRunner(stream);
125+
126+
// 4. Print the response.
127+
runner.on('content', content => {
128+
process.stdout.write(content);
129+
});
130130
}
131131

132132
main();

examples/nextjs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# ⌘ Langbase SDK Next.js Example
22

33
- [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
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
77

88
First, run the development server:
99

examples/nextjs/app/langbase/pipe/run/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function POST(req: NextRequest) {
1313
const result = await langbase.pipes.run({
1414
messages: [{role: 'user', content: prompt}],
1515
name: 'summary',
16-
stream: false
16+
stream: false,
1717
});
1818

1919
// 3. Done, return the stream in a readable stream format.

examples/nextjs/components/langbase/chat-advanced.tsx

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
'use client';
2-
import { Button } from '@/components/ui/button';
3-
import { Input } from '@/components/ui/input';
4-
import { Message } from 'langbase';
5-
import { usePipe } from 'langbase/react';
6-
import React, { useCallback } from 'react';
2+
import {Button} from '@/components/ui/button';
3+
import {Input} from '@/components/ui/input';
4+
import {Message} from 'langbase';
5+
import {usePipe} from 'langbase/react';
6+
import React, {useCallback} from 'react';
77

88
const ChatAdvanced: React.FC = () => {
9-
const handleResponse = useCallback(
10-
(message: Message) => {
11-
console.log(
12-
'Received response:',
13-
message.content?.slice(0, 50) + '...',
14-
);
15-
},
16-
[],
17-
);
9+
const handleResponse = useCallback((message: Message) => {
10+
console.log(
11+
'Received response:',
12+
message.content?.slice(0, 50) + '...',
13+
);
14+
}, []);
1815

19-
const handleFinish = useCallback(
20-
(messages: Message[]) => {
21-
console.log(
22-
`Conversation finished. Total messages: ${messages.length}`,
23-
);
24-
},
25-
[],
26-
);
16+
const handleFinish = useCallback((messages: Message[]) => {
17+
console.log(
18+
`Conversation finished. Total messages: ${messages.length}`,
19+
);
20+
}, []);
2721

2822
const handleError = useCallback((error: Error) => {
2923
console.error('An error occurred:', error);
@@ -62,14 +56,14 @@ const ChatAdvanced: React.FC = () => {
6256

6357
const handleRegenerateWithOptions = () => {
6458
regenerate({
65-
headers: { 'Custom-Header': 'Regenerate' },
66-
body: { customOption: 'regenerateValue' },
59+
headers: {'Custom-Header': 'Regenerate'},
60+
body: {customOption: 'regenerateValue'},
6761
});
6862
};
6963

7064
const handleCustomMessage = () => {
7165
sendMessage('This is a custom message', {
72-
data: { context: 'custom context' },
66+
data: {context: 'custom context'},
7367
allowEmptySubmit: false,
7468
});
7569
};
@@ -83,8 +77,9 @@ const ChatAdvanced: React.FC = () => {
8377
{messages.map((m, index) => (
8478
<div
8579
key={index}
86-
className={`p-2 rounded ${m.role === 'user' ? 'bg-indigo-200' : 'bg-gray-100'
87-
}`}
80+
className={`p-2 rounded ${
81+
m.role === 'user' ? 'bg-indigo-200' : 'bg-gray-100'
82+
}`}
8883
>
8984
<strong>{m.role === 'user' ? 'You: ' : 'AI: '}</strong>
9085
{m.content}
@@ -133,7 +128,7 @@ const ChatAdvanced: React.FC = () => {
133128
</div>
134129

135130
<form
136-
onSubmit={e => handleSubmit(e, { allowEmptySubmit: true })}
131+
onSubmit={e => handleSubmit(e, {allowEmptySubmit: true})}
137132
className="flex space-x-2"
138133
>
139134
<Input

examples/nextjs/components/langbase/generate-text.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use client';
22

3-
import { Button } from '@/components/ui/button';
4-
import { Input } from '@/components/ui/input';
5-
import { useState } from 'react';
3+
import {Button} from '@/components/ui/button';
4+
import {Input} from '@/components/ui/input';
5+
import {useState} from 'react';
66

77
export default function GenerateTextExample() {
88
const [prompt, setPrompt] = useState('');
@@ -20,7 +20,7 @@ export default function GenerateTextExample() {
2020
headers: {
2121
'Content-Type': 'application/json',
2222
},
23-
body: JSON.stringify({ prompt }),
23+
body: JSON.stringify({prompt}),
2424
});
2525

2626
if (!response.ok) {

examples/nextjs/components/langbase/run.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use client';
22

3-
import { Button } from '@/components/ui/button';
4-
import { Input } from '@/components/ui/input';
5-
import { useState } from 'react';
3+
import {Button} from '@/components/ui/button';
4+
import {Input} from '@/components/ui/input';
5+
import {useState} from 'react';
66

77
export default function RunNonStreamExample() {
88
const [prompt, setPrompt] = useState('');
@@ -20,7 +20,7 @@ export default function RunNonStreamExample() {
2020
headers: {
2121
'Content-Type': 'application/json',
2222
},
23-
body: JSON.stringify({ prompt }),
23+
body: JSON.stringify({prompt}),
2424
});
2525

2626
if (!response.ok) {

examples/nextjs/components/langbase/stream-text.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use client';
22

3-
import { Button } from '@/components/ui/button';
4-
import { Input } from '@/components/ui/input';
5-
import { fromReadableStream } from 'langbase';
6-
import { useState } from 'react';
3+
import {Button} from '@/components/ui/button';
4+
import {Input} from '@/components/ui/input';
5+
import {fromReadableStream} from 'langbase';
6+
import {useState} from 'react';
77

88
export default function StreamTextExample() {
99
const [prompt, setPrompt] = useState('');
@@ -20,8 +20,8 @@ export default function StreamTextExample() {
2020
try {
2121
const response = await fetch('/langbase/pipe/stream-text', {
2222
method: 'POST',
23-
body: JSON.stringify({ prompt }),
24-
headers: { 'Content-Type': 'text/plain' },
23+
body: JSON.stringify({prompt}),
24+
headers: {'Content-Type': 'text/plain'},
2525
});
2626

2727
if (response.body) {

examples/nodejs/memory/memory.create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const langbase = new Langbase({
88
async function main() {
99
const response = await langbase.memories.create({
1010
name: 'memory-sdk',
11-
embedding_model: 'cohere:embed-multilingual-v3.0'
11+
embedding_model: 'cohere:embed-multilingual-v3.0',
1212
});
1313

1414
console.log(response);

examples/nodejs/memory/memory.retrieve.filters.And.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
22
* Basic example to demonstrate how to retrieve memories with filters.
3-
*
3+
*
44
* - And: This filter is used to retrieve memories that match all the filters.
55
* - Eq: This filter is used to retrieve memories that match the exact value.
6-
*
6+
*
77
* In this example, we retrieve memories with the following filters:
88
* - company: Langbase
99
* - category: docs
10-
*
10+
*
1111
* We expect to get all chunks of memory from the Langbase Docs memory that have the company Langbase and the category docs.
12-
*
12+
*
1313
*/
1414

1515
import 'dotenv/config';
@@ -22,16 +22,19 @@ const langbase = new Langbase({
2222
async function main() {
2323
const response = await langbase.memories.retrieve({
2424
memory: [
25-
{
26-
name: "langbase-docs",
27-
filters: ["And", [
28-
["company", "Eq", "Langbase"],
29-
["category", "Eq", "docs"]
30-
]]
31-
},
25+
{
26+
name: 'langbase-docs',
27+
filters: [
28+
'And',
29+
[
30+
['company', 'Eq', 'Langbase'],
31+
['category', 'Eq', 'docs'],
32+
],
33+
],
34+
},
3235
],
33-
query: "What are pipes in Langbase Docs?",
34-
topK: 5
36+
query: 'What are pipes in Langbase Docs?',
37+
topK: 5,
3538
});
3639

3740
console.log(response);

0 commit comments

Comments
 (0)