Skip to content

Commit

Permalink
chore: serpapi use default location
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobrosenthal committed Apr 12, 2023
1 parent e15d56c commit 968c232
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 22 deletions.
6 changes: 5 additions & 1 deletion docs/docs/getting-started/guide-chat.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ And finally, we can use the AgentExecutor to run an agent:

```typescript
// Define the list of tools the agent can use
const tools = [new SerpAPI()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
];
// Create the agent from the chat model and the tools
const agent = ChatAgent.fromLLMAndTools(new ChatOpenAI(), tools);
// Create an executor, which calls to the agent until an answer is found
Expand Down
7 changes: 6 additions & 1 deletion docs/docs/getting-started/guide-llm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ import { SerpAPI } from "langchain/tools";
import { Calculator } from "langchain/tools/calculator";
const model = new OpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];
const executor = await initializeAgentExecutor(
tools,
Expand Down
7 changes: 6 additions & 1 deletion docs/docs/modules/agents/executor/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ import { SerpAPI } from "langchain/tools";
import { Calculator } from "langchain/tools/calculator";

const model = new OpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const executor = await initializeAgentExecutor(
tools,
Expand Down
8 changes: 7 additions & 1 deletion docs/docs/modules/agents/tools/agents_with_vectorstores.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ const qaTool = new ChainTool({
Now you can construct and using the tool just as you would any other!

```typescript
const tools = [new SerpAPI(), new Calculator(), qaTool];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
qaTool,
];

const executor = await initializeAgentExecutor(
tools,
Expand Down
21 changes: 18 additions & 3 deletions docs/docs/production/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import process from "process";
export const run = async () => {
process.env.LANGCHAIN_HANDLER = "langchain";
const model = new OpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const executor = await initializeAgentExecutor(
tools,
Expand Down Expand Up @@ -55,7 +60,12 @@ import {
export const run = async () => {
process.env.LANGCHAIN_HANDLER = "langchain";
const model = new OpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const executor = await initializeAgentExecutor(
tools,
Expand Down Expand Up @@ -90,7 +100,12 @@ export const run = async () => {
callbackManager.addHandler(new LangChainTracer());

const model = new OpenAI({ temperature: 0, callbackManager });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];
for (const tool of tools) {
tool.callbackManager = callbackManager;
}
Expand Down
7 changes: 6 additions & 1 deletion examples/src/agents/chat_convo_with_tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { BufferMemory } from "langchain/memory";
export const run = async () => {
process.env.LANGCHAIN_HANDLER = "langchain";
const model = new ChatOpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const executor = await initializeAgentExecutor(
tools,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/agents/chat_mrkl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { Calculator } from "langchain/tools/calculator";

export const run = async () => {
const model = new ChatOpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const executor = await initializeAgentExecutor(
tools,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/agents/chat_mrkl_with_tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { Calculator } from "langchain/tools/calculator";
export const run = async () => {
process.env.LANGCHAIN_HANDLER = "langchain";
const model = new ChatOpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const executor = await initializeAgentExecutor(
tools,
Expand Down
14 changes: 12 additions & 2 deletions examples/src/agents/concurrent_mrkl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import {
export const run = async () => {
process.env.LANGCHAIN_HANDLER = "langchain";
const model = new OpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const executor = await initializeAgentExecutor(
tools,
Expand Down Expand Up @@ -47,7 +52,12 @@ export const run = async () => {
callbackManager.addHandler(new LangChainTracer());

const model = new OpenAI({ temperature: 0, callbackManager });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];
for (const tool of tools) {
tool.callbackManager = callbackManager;
}
Expand Down
7 changes: 6 additions & 1 deletion examples/src/agents/custom_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { LLMChain } from "langchain/chains";

export const run = async () => {
const model = new OpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const prefix = `Answer the following questions as best you can, but speaking as a pirate might speak. You have access to the following tools:`;
const suffix = `Begin! Remember to speak as a pirate when giving your final answer. Use lots of "Args"
Expand Down
7 changes: 6 additions & 1 deletion examples/src/agents/custom_llm_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ class CustomOutputParser extends AgentActionOutputParser {

export const run = async () => {
const model = new OpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const llmChain = new LLMChain({
prompt: new CustomPromptTemplate({
Expand Down
7 changes: 6 additions & 1 deletion examples/src/agents/custom_llm_agent_chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ class CustomOutputParser extends AgentActionOutputParser {

export const run = async () => {
const model = new ChatOpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const llmChain = new LLMChain({
prompt: new CustomPromptTemplate({
Expand Down
7 changes: 6 additions & 1 deletion examples/src/agents/load_from_hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { Calculator } from "langchain/tools/calculator";

export const run = async () => {
const model = new OpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const agent = await loadAgent(
"lc://agents/zero-shot-react-description/agent.json",
Expand Down
7 changes: 6 additions & 1 deletion examples/src/agents/mrkl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { Calculator } from "langchain/tools/calculator";

export const run = async () => {
const model = new OpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const executor = await initializeAgentExecutor(
tools,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/agents/mrkl_with_tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import process from "process";
export const run = async () => {
process.env.LANGCHAIN_HANDLER = "langchain";
const model = new OpenAI({ temperature: 0 });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
new Calculator(),
];

const executor = await initializeAgentExecutor(
tools,
Expand Down
6 changes: 5 additions & 1 deletion examples/src/chat/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
} from "langchain/prompts";

export const run = async () => {
const tools = [new SerpAPI()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
];

const prompt = ZeroShotAgent.createPrompt(tools, {
prefix: `Answer the following questions as best you can, but speaking as a pirate might speak. You have access to the following tools:`,
Expand Down
6 changes: 5 additions & 1 deletion examples/src/chat/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ export const run = async () => {
// other abilities, such as search, or a calculator

// Define the list of tools the agent can use
const tools = [new SerpAPI()];
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
}),
];
// Create the agent from the chat model and the tools
const agent = ChatAgent.fromLLMAndTools(new ChatOpenAI(), tools);
// Create an executor, which calls to the agent until an answer is found
Expand Down
10 changes: 8 additions & 2 deletions langchain/src/agents/tests/agent.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { initializeAgentExecutor } from "../initialize.js";

test("Run agent from hub", async () => {
const model = new OpenAI({ temperature: 0, modelName: "text-babbage-001" });
const tools: Tool[] = [new SerpAPI(), new Calculator()];
const tools: Tool[] = [
new SerpAPI(undefined, { location: "Austin,Texas,United States" }),
new Calculator(),
];
const agent = await loadAgent(
"lc://agents/zero-shot-react-description/agent.json",
{ llm: model, tools }
Expand All @@ -27,7 +30,10 @@ test("Run agent from hub", async () => {

test("Run agent locally", async () => {
const model = new OpenAI({ temperature: 0, modelName: "text-babbage-001" });
const tools = [new SerpAPI(), new Calculator()];
const tools = [
new SerpAPI(undefined, { location: "Austin,Texas,United States" }),
new Calculator(),
];

const executor = await initializeAgentExecutor(
tools,
Expand Down

0 comments on commit 968c232

Please sign in to comment.