-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration[minor]: Llama Cpp streaming (#3394)
* Got streaming working in LLM & Chat * Linted streaming and added docs. * Small fixes * Update llama_cpp.mdx --------- Co-authored-by: jacoblee93 <[email protected]>
- Loading branch information
1 parent
ed51ace
commit aef5627
Showing
11 changed files
with
178 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ChatLlamaCpp } from "langchain/chat_models/llama_cpp"; | ||
|
||
const llamaPath = "/Replace/with/path/to/your/model/gguf-llama2-q4_0.bin"; | ||
|
||
const model = new ChatLlamaCpp({ modelPath: llamaPath, temperature: 0.7 }); | ||
|
||
const stream = await model.stream([ | ||
["human", "Tell me a short story about a happy Llama."], | ||
]); | ||
|
||
for await (const chunk of stream) { | ||
console.log(chunk.content); | ||
} | ||
|
||
/* | ||
Once | ||
upon | ||
a | ||
time | ||
, | ||
in | ||
a | ||
green | ||
and | ||
sunny | ||
field | ||
... | ||
*/ |
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,30 @@ | ||
import { LlamaCpp } from "langchain/llms/llama_cpp"; | ||
|
||
const llamaPath = "/Replace/with/path/to/your/model/gguf-llama2-q4_0.bin"; | ||
|
||
const model = new LlamaCpp({ modelPath: llamaPath, temperature: 0.7 }); | ||
|
||
const prompt = "Tell me a short story about a happy Llama."; | ||
|
||
const stream = await model.stream(prompt); | ||
|
||
for await (const chunk of stream) { | ||
console.log(chunk); | ||
} | ||
|
||
/* | ||
Once | ||
upon | ||
a | ||
time | ||
, | ||
in | ||
the | ||
rolling | ||
hills | ||
of | ||
Peru | ||
... | ||
*/ |
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
aef5627
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
langchainjs-docs – ./docs/core_docs/
langchainjs-docs-ruddy.vercel.app
langchainjs-docs-langchain.vercel.app
langchainjs-docs-git-main-langchain.vercel.app
js.langchain.com