Skip to content

Commit

Permalink
MRKL prompt fix, integration test (#1138)
Browse files Browse the repository at this point in the history
* MRKL prompt fix, integration test

* Lint and format

---------

Co-authored-by: Jacob Lee <jacob@autocode.com>
  • Loading branch information
jacoblee93 and Jacob Lee authored May 6, 2023
1 parent 7c59816 commit 13a37bc
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/docs/modules/agents/tools/webbrowser.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import CodeBlock from "@theme/CodeBlock";
The Webbrowser Tool gives your agent the ability to visit a website and extract information. It is described to the agent as

```
useful for when you need to find something on or summarize a webpage. input should be a comma seperated list of "valid URL including protocol","what you want to find on the page or empty string for a summary".
useful for when you need to find something on or summarize a webpage. input should be a comma separated list of "valid URL including protocol","what you want to find on the page or empty string for a summary".
```

It exposes two modes of operation:
Expand Down
4 changes: 3 additions & 1 deletion examples/src/agents/custom_llm_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import { SerpAPI, Tool } from "langchain/tools";
import { Calculator } from "langchain/tools/calculator";

const PREFIX = `Answer the following questions as best you can. You have access to the following tools:`;
const formatInstructions = (toolNames: string) => `Use the following format:
const formatInstructions = (
toolNames: string
) => `Use the following format in your response:
Question: the input question you must answer
Thought: you should always think about what to do
Expand Down
4 changes: 3 additions & 1 deletion examples/src/agents/custom_llm_agent_chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import { SerpAPI, Tool } from "langchain/tools";
import { Calculator } from "langchain/tools/calculator";

const PREFIX = `Answer the following questions as best you can. You have access to the following tools:`;
const formatInstructions = (toolNames: string) => `Use the following format:
const formatInstructions = (
toolNames: string
) => `Use the following format in your response:
Question: the input question you must answer
Thought: you should always think about what to do
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/agents/mrkl/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const PREFIX = `Answer the following questions as best you can. You have access to the following tools:`;
export const FORMAT_INSTRUCTIONS = `Use the following format:
export const FORMAT_INSTRUCTIONS = `Use the following format in your response:
Question: the input question you must answer
Thought: you should always think about what to do
Expand Down
62 changes: 62 additions & 0 deletions langchain/src/agents/tests/mrkl_agent.int.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* eslint-disable no-process-env */
import { ChatOpenAI } from "../../chat_models/openai.js";
import { SerpAPI } from "../../tools/serpapi.js";
import { Calculator } from "../../tools/calculator.js";
import { initializeAgentExecutorWithOptions } from "../initialize.js";
import { DynamicTool } from "../../tools/dynamic.js";

test("Run agent locally with GPT-3.5", async () => {
const model = new ChatOpenAI({ temperature: 0, modelName: "gpt-3.5-turbo" });
const tools = [
new SerpAPI(undefined, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
new DynamicTool({
name: "foo",
description: "Some other tool that does foo",
func: async () => "bar",
}),
];

const executor = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "zero-shot-react-description",
});

const input = `What is the weather like in Washington DC?`;
console.log(`Executing with input "${input}"...`);

const result = await executor.call({ input });

console.log(`Got output ${result.output}`);
});

test("Run agent locally with GPT-4", async () => {
const model = new ChatOpenAI({ temperature: 0, modelName: "gpt-4" });
const tools = [
new SerpAPI(undefined, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
new DynamicTool({
name: "foo",
description: "Some other tool that does foo",
func: async () => "bar",
}),
];

const executor = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "zero-shot-react-description",
});

const input = `What is the weather like in Washington DC?`;
console.log(`Executing with input "${input}"...`);

const result = await executor.call({ input });

console.log(`Got output ${result.output}`);
});
2 changes: 1 addition & 1 deletion langchain/src/tools/webbrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,5 @@ export class WebBrowser extends Tool {

name = "web-browser";

description = `useful for when you need to find something on or summarize a webpage. input should be a comma seperated list of "ONE valid http URL including protocol","what you want to find on the page or empty string for a summary".`;
description = `useful for when you need to find something on or summarize a webpage. input should be a comma separated list of "ONE valid http URL including protocol","what you want to find on the page or empty string for a summary".`;
}

1 comment on commit 13a37bc

@vercel
Copy link

@vercel vercel bot commented on 13a37bc May 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.