-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'dotenv/config'; | ||
import {Langbase} from 'langbase'; | ||
|
||
const langbase = new Langbase({ | ||
apiKey: process.env.LANGBASE_API_KEY!, | ||
}); | ||
|
||
async function main() { | ||
// Message 1: Tell something to the LLM. | ||
const response1 = await langbase.pipe.run({ | ||
name: 'summary', | ||
messages: [{role: 'user', content: 'My company is called Langbase'}], | ||
}); | ||
|
||
console.log(response1.completion); | ||
|
||
// 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({ | ||
name: 'summary', | ||
threadId: response1.threadId!, | ||
messages: [{role: 'user', content: 'Tell me the name of my company?'}], | ||
}); | ||
|
||
console.log(response2.completion); | ||
// You'll see any LLM will know the company is `Langbase` | ||
// since it's the same chat thread. This is how you can | ||
// continue a conversation in the same thread. | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'dotenv/config'; | ||
import {Langbase, getRunner} from 'langbase'; | ||
|
||
const langbase = new Langbase({ | ||
apiKey: process.env.LANGBASE_API_KEY!, | ||
}); | ||
|
||
// Message 1: Tell something to the LLM. | ||
const response1 = await langbase.pipe.run({ | ||
name: 'summary', | ||
stream: true, | ||
messages: [{role: 'user', content: 'My company is called Langbase'}], | ||
}); | ||
|
||
const runner1 = getRunner(response1.stream); | ||
|
||
runner1.on('content', content => { | ||
process.stdout.write(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({ | ||
name: 'summary', | ||
stream: true, | ||
threadId: response1.threadId!, | ||
messages: [{role: 'user', content: 'Tell me the name of my company?'}], | ||
}); | ||
|
||
const runner2 = getRunner(response2.stream); | ||
|
||
runner2.on('content', content => { | ||
process.stdout.write(content); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters