40 likes
·
22.2K reads
12 comments
Great article. 1) langchain/llms is now langchain/llms/openai 2) The 2nd example when introducing the prompt templates, there's a missing "await" on "const res = await prompt.format..." — without which Open AI returns {res: Promise {<pending>}} as the returned value.
Also, Calculator moved, so it's now two lines: import { SerpAPI } from "langchain/tools"; import { Calculator } from "langchain/tools/calculator";
Thanks for this. Very concise and to the point.
Jefe Blaize - Thanks for the help on the calculator. I couldn't find that one.
Also, there is a change to the initializeAgentExecutor
. Replace it with initializeAgentExecutorWithOptions
. The full line should be:
const executor = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "zero-shot-react-description",
});
because of the way the agentType needs to be passed now.
Hope this helps someone.
Found this quite useful, thanks tho!
I am getting "throw new Error("(Azure) OpenAI API key not found"); ^ Error: (Azure) OpenAI API key not found" how to resolve this
EDIT: issue is solved by passing the path of your config.env file inside config CODE BELOW:
BEFORE: import * as dotenv from "dotenv"; dotenv.config();
AFTER: import dotenv from "dotenv"; dotenv.config({ path: "./config.env" });
also carefully check for any spaces in after the = sign in your env file. eg: ENV_VAR<space>=<space>ENV_VALUE just delete those spaces.
//Pass the "temperature" parameter which controls the RANDOMNESS of the model's output. A lower temperature will result in more predictable output, while a higher temperature will result in more random output. The temperature parameter is set between 0 and 1, with 0 being the most predictable and 1 being the most random
const model = new OpenAI({
temperature: 0,
openAIApiKey: process.env.OPENAI_API_KEY,
});
//Create a list of the instatiated tools
const tools = [new SerpAPI(process.env.SERPAPI_API_KEY), new Calculator()];
Don't forget to add your OPENAI_API_KEY and SERPAPI_API_KEY from your .env file
hi your "copy " button on code snippets is not really usefull as it copy " $ npm init es6 -y " with the $ instead of just "npm init es6 -y"
[WARN] Importing from 'langchain/llms' is deprecated. Import from eg. 'langchain/llms/openai' instead. See js.langchain.com/docs/getting-started/inst… for upgrade instructions.
in //Import the PromptTemplate module import { PromptTemplate } from "langchain/prompts";
export const run = async () => { //Create the template. The template is actually a "parameterized prompt". A "parameterized prompt" is a prompt in which the input parameter names are used and the parameter values are supplied from external input const template = "What is a good name for a company that makes {product}?";
//Instantiate "PromptTemplate" passing the prompt template string initialized above and a list of variable names the final prompt template will expect const prompt = new PromptTemplate({ template, inputVariables: ["product"] });
//Create a new prompt from the combination of the template and input variables. Pass the value for the variable name that was sent in the "inputVariables" list passed to "PromptTemplate" initialization call const res = prompt.format({ product: "colorful socks" }); console.log({ res }); };
run();
it should be const res = await prompt.format({ product: "colorful socks" }); , with await otherwise, res = Promise <pending>
src/app.ts:9:21 - error TS2305: Module '"langchain/tools"' has no exported member 'Calculator'.
9 import { SerpAPI, Calculator } from "langchain/tools";
'initializeAgentExecutor' is deprecated
according to js.langchain.com/docs/modules/agents/execu…
should be import { Calculator } from "langchain/tools/calculator";
and import { initializeAgentExecutorWithOptions } from "langchain/agents"; ...
const executor = await initializeAgentExecutorWithOptions(tools, model, { agentType: "zero-shot-react-description", verbose: true, });