Skip to content

Commit

Permalink
Add OpenAI functions agent prompt customization example (langchain-ai…
Browse files Browse the repository at this point in the history
…#2015)

* Cleanup

* Adds OpenAI functions custom prompt example

* Fix link
  • Loading branch information
jacoblee93 authored Jul 19, 2023
1 parent b14f2f1 commit 4b3111b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ Must be used with an [OpenAI Functions](https://platform.openai.com/docs/guides/
This agent also supports `StructuredTool`s with more complex input schemas.

<CodeBlock language="typescript">{Example}</CodeBlock>

## Prompt customization

You can pass in a custom string to be used as the system message of the prompt as follows:

import CustomPromptExample from "@examples/agents/openai_custom_prompt.ts";

<CodeBlock language="typescript">{CustomPromptExample}</CodeBlock>
22 changes: 22 additions & 0 deletions examples/src/agents/openai_custom_prompt.ts
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!

0 comments on commit 4b3111b

Please sign in to comment.