Public
Edited
Aug 29, 2023
2 stars
Insert cell
Insert cell
viewof openAIApiKey = {
// Probably not the best idea to store a key in localStorage, but I do this for convenience...I'm leaving this here for any other lazy people like me!
let defaultValue = null
let keyDefined = false
try {
defaultValue = localStorage.GPT_API_key
keyDefined = defaultValue != null
} catch (e) {}
return Inputs.password({label: "GPT Key", submit: true, value: defaultValue, width: 640, password: true, required: !keyDefined})
}
Insert cell
viewof serpApiKey = {
// Probably not the best idea to store a key in localStorage, but I do this for convenience...I'm leaving this here for any other lazy people like me!
let defaultValueSerp = null
let keyDefinedSerp = false
try {
defaultValueSerp = localStorage.SERP_API_key
keyDefinedSerp = defaultValueSerp != null
} catch (e) {}
return Inputs.password({label: "Serp API Key", submit: true, value: defaultValueSerp, width: 640, password: true, required: !keyDefinedSerp})
}
Insert cell
tools = import("https://esm.sh/langchain/tools");
Insert cell
agents = import("https://esm.sh/langchain/agents");
Insert cell
initializeAgentExecutorWithOptions = agents.initializeAgentExecutorWithOptions
Insert cell
SerpAPI = tools.SerpAPI
Insert cell
calculator = await import("https://cdn.jsdelivr.net/npm/langchain@0.0.134/tools/calculator.js/+esm")
Insert cell
Calculator = calculator.Calculator
Insert cell
langchain = import("https://esm.sh/langchain/chat_models/openai");
Insert cell
ChatOpenAI = langchain.ChatOpenAI
Insert cell
Experimental = import("https://cdn.jsdelivr.net/npm/langchain@0.0.134/experimental/plan_and_execute.js/+esm")
Insert cell
Insert cell
Insert cell
tool = [new Calculator(), new SerpAPI({apiKey: serpApiKey})];
Insert cell

model = new ChatOpenAI({
temperature: 0,
modelName: "gpt-4",
verbose: true,
openAIApiKey: openAIApiKey
});

Insert cell
executor = await initializeAgentExecutorWithOptions(tool, model, {
agentType: "chat-zero-shot-react-description",
returnIntermediateSteps: true,
});

Insert cell
input = `Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?`;
Insert cell
result = await executor.call({ input });
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more