Created
April 12, 2024 19:42
-
-
Save SebastianStehle/6f9c79c580fa33a553c1ff1c81ee4fa7 to your computer and use it in GitHub Desktop.
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
import { AgentExecutor, createOpenAIToolsAgent } from "langchain/agents"; | |
import { pull } from "langchain/hub"; | |
import { ChatOpenAI } from "@langchain/openai"; | |
import type { ChatPromptTemplate } from "@langchain/core/prompts"; | |
import { DallEAPIWrapper } from "@langchain/openai"; | |
// 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/openai-tools-agent | |
const prompt = await pull<ChatPromptTemplate>("hwchase17/openai-tools-agent"); | |
const tool = new DallEAPIWrapper({ | |
n: 1, // Default | |
model: "dall-e-3", // Default | |
apiKey: openAIKey, | |
}); | |
const tools = [tool]; | |
const llm = new ChatOpenAI({ | |
model: "gpt-3.5-turbo-1106", | |
temperature: 0, | |
openAIApiKey: openAIKey, | |
}); | |
const agent = await createOpenAIToolsAgent({ | |
llm, | |
tools, | |
prompt, | |
}); | |
const agentExecutor = new AgentExecutor({ | |
agent, | |
tools, | |
}); | |
const result = await agentExecutor.invoke({ | |
input: "Create the image of a dog", | |
}); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment