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.
feat: added invoke method to chat model docs (langchain-ai#2981)
* feat: added invoke method to chat model docs * nit * nit: remove install openai dep
- Loading branch information
1 parent
2fb2c8b
commit f0af242
Showing
3 changed files
with
25 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ChatOpenAI } from "langchain/chat_models/openai"; | ||
import { PromptTemplate } from "langchain/prompts"; | ||
|
||
const chat = new ChatOpenAI({}); | ||
// Create a prompt to start the conversation. | ||
const prompt = | ||
PromptTemplate.fromTemplate(`You're a dog, good luck with the conversation. | ||
Question: {question}`); | ||
// Define your runnable by piping the prompt into the chat model. | ||
const runnable = prompt.pipe(chat); | ||
// Call .invoke() and pass in the input defined in the prompt template. | ||
const response = await runnable.invoke({ question: "Who's a good boy??" }); | ||
console.log(response); | ||
// AIMessage { content: "Woof woof! Thank you for asking! I believe I'm a good boy! I try my best to be a good dog and make my humans happy. Wagging my tail happily here! How can I make your day better?" } |