Skip to content

Commit

Permalink
fix: serpapi use hg and lg to set region and language
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobrosenthal committed Apr 13, 2023
1 parent 3e247e4 commit 7ebeaad
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/docs/getting-started/guide-chat.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ And finally, we can use the AgentExecutor to run an agent:
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
];
// Create the agent from the chat model and the tools
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/getting-started/guide-llm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ const model = new OpenAI({ temperature: 0 });
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/modules/agents/executor/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const model = new OpenAI({ temperature: 0 });
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/modules/agents/tools/agents_with_vectorstores.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Now you can construct and using the tool just as you would any other!
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
qaTool,
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/production/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down Expand Up @@ -63,6 +65,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down Expand Up @@ -103,6 +107,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
2 changes: 2 additions & 0 deletions examples/src/agents/chat_convo_with_tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
2 changes: 2 additions & 0 deletions examples/src/agents/chat_mrkl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
2 changes: 2 additions & 0 deletions examples/src/agents/chat_mrkl_with_tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
4 changes: 4 additions & 0 deletions examples/src/agents/concurrent_mrkl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down Expand Up @@ -55,6 +57,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
2 changes: 2 additions & 0 deletions examples/src/agents/custom_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
2 changes: 2 additions & 0 deletions examples/src/agents/custom_llm_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
2 changes: 2 additions & 0 deletions examples/src/agents/custom_llm_agent_chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
2 changes: 2 additions & 0 deletions examples/src/agents/load_from_hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
2 changes: 2 additions & 0 deletions examples/src/agents/mrkl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
2 changes: 2 additions & 0 deletions examples/src/agents/mrkl_with_tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
2 changes: 2 additions & 0 deletions examples/src/chat/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
];

Expand Down
2 changes: 2 additions & 0 deletions examples/src/chat/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export const run = async () => {
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
];
// Create the agent from the chat model and the tools
Expand Down
12 changes: 10 additions & 2 deletions langchain/src/agents/tests/agent.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ 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(undefined, { location: "Austin,Texas,United States" }),
new SerpAPI(undefined, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
const agent = await loadAgent(
Expand All @@ -31,7 +35,11 @@ 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(undefined, { location: "Austin,Texas,United States" }),
new SerpAPI(undefined, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];

Expand Down
4 changes: 3 additions & 1 deletion langchain/src/callbacks/tests/langchain_tracer.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ test.skip("Test Traced Agent with concurrency (skipped until we fix concurrency)
process.env.LANGCHAIN_HANDLER = "langchain";
const model = new OpenAI({ temperature: 0 });
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
new SerpAPI(undefined, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];
Expand Down
11 changes: 5 additions & 6 deletions langchain/src/tools/serpapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { Tool } from "./base.js";
* when used in `jest` tests. Part of the issue seems to be that the `serpapi`
* package imports a wasm module to use instead of native `fetch`, which we
* don't want anyway.
*
* NOTE: you must provide location, gl and hl or your region and language will
* may not match your location, and will not be deterministic.
*/

// Copied over from `serpapi` package
Expand Down Expand Up @@ -43,12 +46,8 @@ interface GoogleParameters extends BaseParameters {
q: string;
/**
* Location
* Parameter defines from where you want the search to originate. Serpapi advises
* that if you do not provide a location, any location from around the world might
* be used including a different region and language. Location can be a canonical
* name (e.g., "Austin,Texas,United States") or the location id
* (e.g., "585069efee19ad271e9c9b36") If several locations match the location
* requested, we'll pick the most popular one. Head to the
* Parameter defines from where you want the search to originate. If several
* locations match the location requested, we'll pick the most popular one. Head to
* [/locations.json API](https://serpapi.com/locations-api) if you need more
* precise control. location and uule parameters can't be used together. Avoid
* utilizing location when setting the location outside the U.S. when using Google
Expand Down

0 comments on commit 7ebeaad

Please sign in to comment.