-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs[minor]: Replace deprecated code examples with LCEL & AgentExecutor #6149
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7d6c2f8
adding v0.2 langchainjs support replaced ZeroShotAgent with createRea…
Srijan-D 366599c
Using the LangChain Expression Language (LCEL) instead of LLMChain de…
Srijan-D d608211
fixing farmat ci check
Srijan-D 23997ca
Merge branch 'main' into main
bracesproul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { LLMChain } from "langchain/chains"; | ||
import { ChatOpenAI } from "@langchain/openai"; | ||
import { ZeroShotAgent, AgentExecutor } from "langchain/agents"; | ||
import { | ||
ChatPromptTemplate, | ||
SystemMessagePromptTemplate, | ||
HumanMessagePromptTemplate, | ||
} from "@langchain/core/prompts"; | ||
import { AgentExecutor, createReactAgent } from "langchain/agents"; | ||
import { pull } from "langchain/hub"; | ||
import type { PromptTemplate } from "@langchain/core/prompts"; | ||
|
||
import { OpenAI } from "@langchain/openai"; | ||
|
||
import { SerpAPI } from "@langchain/community/tools/serpapi"; | ||
|
||
|
||
export const run = async () => { | ||
// Define the tools the agent will have access to. | ||
const tools = [ | ||
new SerpAPI(process.env.SERPAPI_API_KEY, { | ||
location: "Austin,Texas,United States", | ||
|
@@ -17,36 +17,29 @@ export const run = async () => { | |
}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey there! I noticed that this PR introduces a new external HTTP request to pull the prompt template. I've flagged this change for your review to ensure it aligns with our project's requirements. Let me know if you have any questions or need further clarification! |
||
]; | ||
|
||
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:`, | ||
suffix: `Begin! Remember to speak as a pirate when giving your final answer. Use lots of "Args"`, | ||
}); | ||
|
||
const chatPrompt = ChatPromptTemplate.fromMessages([ | ||
new SystemMessagePromptTemplate(prompt), | ||
HumanMessagePromptTemplate.fromTemplate(`{input} | ||
|
||
This was your previous work (but I haven't seen any of it! I only see what you return as final answer): | ||
{agent_scratchpad}`), | ||
]); | ||
// Get the prompt to use - you can modify this! | ||
// If you want to see the prompt in full, you can at: | ||
// https://smith.langchain.com/hub/hwchase17/react | ||
const prompt = await pull<PromptTemplate>("hwchase17/react"); | ||
|
||
const chat = new ChatOpenAI({}); | ||
|
||
const llmChain = new LLMChain({ | ||
prompt: chatPrompt, | ||
llm: chat, | ||
const llm = new OpenAI({ | ||
temperature: 0, | ||
}); | ||
|
||
const agent = new ZeroShotAgent({ | ||
llmChain, | ||
allowedTools: tools.map((tool) => tool.name), | ||
const agent = await createReactAgent({ | ||
llm, | ||
tools, | ||
prompt, | ||
}); | ||
|
||
const executor = AgentExecutor.fromAgentAndTools({ agent, tools }); | ||
const agentExecutor = new AgentExecutor({ | ||
agent, | ||
tools, | ||
}); | ||
|
||
const response = await executor.invoke({ | ||
input: "How many people live in canada as of 2023?", | ||
const result = await agentExecutor.invoke({ | ||
input: "what is LangChain?", | ||
}); | ||
|
||
console.log(response); | ||
console.log(result); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey team, I've flagged a change in the PR that accesses an environment variable using
process.env
. Please review this to ensure it aligns with our security and configuration best practices.