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.
Add OpenAI functions agent prompt customization example (langchain-ai…
…#2015) * Cleanup * Adds OpenAI functions custom prompt example * Fix link
- Loading branch information
1 parent
b14f2f1
commit 4b3111b
Showing
2 changed files
with
30 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
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,22 @@ | ||
import { initializeAgentExecutorWithOptions } from "langchain/agents"; | ||
import { ChatOpenAI } from "langchain/chat_models/openai"; | ||
import { SerpAPI } from "langchain/tools"; | ||
import { Calculator } from "langchain/tools/calculator"; | ||
|
||
const tools = [new Calculator(), new SerpAPI()]; | ||
const chat = new ChatOpenAI({ modelName: "gpt-4", temperature: 0 }); | ||
const prefix = | ||
"You are a helpful AI assistant. However, all final response to the user must be in pirate dialect."; | ||
|
||
const executor = await initializeAgentExecutorWithOptions(tools, chat, { | ||
agentType: "openai-functions", | ||
verbose: true, | ||
agentArgs: { | ||
prefix, | ||
}, | ||
}); | ||
|
||
const result = await executor.run("What is the weather in New York?"); | ||
console.log(result); | ||
|
||
// Arr matey, in New York, it be feelin' like 75 degrees, with a gentle breeze blowin' from the northwest at 3 knots. The air be 77% full o' water, and the clouds be coverin' 35% of the sky. There be no rain in sight, yarr! |