-
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
TypeError: getDefaultAgent is not a function #5816
Comments
Also opened an issue at openai/openai-node#903 |
To resolve the "TypeError: getDefaultAgent is not a function" error when using Instead, use one of the available agent creation functions such as import { createOpenAIToolsAgent } from 'langchain/src/agents/openai_tools/index.js';
const agent = await createOpenAIToolsAgent({
llm: new ChatOpenAI({
temperature: 0,
modelName: "gpt-3.5-turbo-1106",
}),
tools: [
// your tools here
],
prompt: await pull<ChatPromptTemplate>("hwchase17/openai-tools-agent"),
streamRunnable: true,
}); Make sure to replace |
Here's the full code:
|
To resolve the "TypeError: getDefaultAgent is not a function" error, you should use the import './config/datadog.js';
import express from 'express';
import { ChatOpenAI } from "@langchain/openai";
import { PromptTemplate } from "@langchain/core/prompts";
import { JsonOutputParser } from "@langchain/core/output_parsers";
import dotenv from "dotenv";
import { createOpenAIFunctionsAgent, AgentExecutor } from "langchain/agents";
import { pull } from "langchain/hub";
import { AIMessage, HumanMessage } from "@langchain/core/messages";
dotenv.config();
const app = express();
const prompt = await pull<PromptTemplate>("hwchase17/openai-functions-agent");
const llm = new ChatOpenAI({
modelName: "gpt-4o",
verbose: true,
apiKey: process.env.OPENAI_API_KEY,
});
const agent = await createOpenAIFunctionsAgent({
llm,
tools: [], // Define your tools here
prompt,
});
const agentExecutor = new AgentExecutor({
agent,
tools: [], // Define your tools here
});
const result = await agentExecutor.invoke({
input: "Return a JSON object with a 'text' field containing a joke",
});
console.log(result);
app.listen(process.env.PORT || 3000); Make sure to replace |
@guidev const openAiApiUrl = "https://api.openai.com/v1/chat/completions";
const response = await fetch(openAiApiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${appConfig.openAiKey}`,
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [...messages],
max_tokens: 256,
}),
}); |
Checked other resources
Example Code
git clone https://github.com/guidev/nonworking/tree/node20
npm run start
Error Message and Stack Trace (if applicable)
Description
When using openai-node with langchain and datadog, ESM, I get the following error:
System Info
The text was updated successfully, but these errors were encountered: