forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into nc/test-exports-cf
- Loading branch information
Showing
9 changed files
with
131 additions
and
119 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
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
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
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
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
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
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
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,38 @@ | ||
import { CallbackManager } from "langchain/callbacks"; | ||
import { ChatOpenAI } from "langchain/chat_models"; | ||
import { HumanChatMessage } from "langchain/schema"; | ||
|
||
export const run = async () => { | ||
const chat = new ChatOpenAI({ | ||
streaming: true, | ||
callbackManager: CallbackManager.fromHandlers({ | ||
async handleLLMNewToken(token: string) { | ||
process.stdout.write(token); | ||
}, | ||
}), | ||
}); | ||
|
||
await chat.call([ | ||
new HumanChatMessage("Write me a song about sparkling water."), | ||
]); | ||
/* | ||
Verse 1: | ||
Bubbles rise, crisp and clear | ||
Refreshing taste that brings us cheer | ||
Sparkling water, so light and pure | ||
Quenches our thirst, it's always secure | ||
Chorus: | ||
Sparkling water, oh how we love | ||
Its fizzy bubbles and grace above | ||
It's the perfect drink, anytime, anyplace | ||
Refreshing as it gives us a taste | ||
Verse 2: | ||
From morning brunch to evening feast | ||
It's the perfect drink for a treat | ||
A sip of it brings a smile so bright | ||
Our thirst is quenched in just one sip so light | ||
... | ||
*/ | ||
}; |
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,37 @@ | ||
import { CallbackManager } from "langchain/callbacks"; | ||
import { OpenAI } from "langchain/llms"; | ||
|
||
export const run = async () => { | ||
// To enable streaming, we pass in `streaming: true` to the LLM constructor. | ||
// Additionally, we pass in a `CallbackManager` with a handler set up for the `handleLLMNewToken` event. | ||
const chat = new OpenAI({ | ||
streaming: true, | ||
callbackManager: CallbackManager.fromHandlers({ | ||
async handleLLMNewToken(token: string) { | ||
process.stdout.write(token); | ||
}, | ||
}), | ||
}); | ||
|
||
await chat.call("Write me a song about sparkling water."); | ||
/* | ||
Verse 1 | ||
Crystal clear and made with care | ||
Sparkling water on my lips, so refreshing in the air | ||
Fizzy bubbles, light and sweet | ||
My favorite beverage I can’t help but repeat | ||
Chorus | ||
A toast to sparkling water, I’m feeling so alive | ||
Let’s take a sip, and let’s take a drive | ||
A toast to sparkling water, it’s the best I’ve had in my life | ||
It’s the best way to start off the night | ||
Verse 2 | ||
It’s the perfect drink to quench my thirst | ||
It’s the best way to stay hydrated, it’s the first | ||
A few ice cubes, a splash of lime | ||
It will make any day feel sublime | ||
... | ||
*/ | ||
}; |