Skip to content
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

Idea/Question: Initial idea for allowing OpenAI default tools #14329

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

abierbaum
Copy link

@abierbaum abierbaum commented Apr 1, 2025

Summary

I am trying to come up with a way to allow the LmChatOpenAi node to make use of the OpenAI built-in web_search_preview tool. I believe this would allow the models to have similar web search and research capabilities to what is exposed through Chat GPT when using the web search functionality.

Note: This PR does not work, it is just to show the idea of what I was thinking and get feedback from someone else that understands the code better. It does allow configuring the setting, but it seems to break something in lang-chain.

The error I get is:

Tools Agent requires Chat Model which supports Tools calling

So I think something about calling the bind_tools method this way is returning a new object that doesn't have the correct state to be used later.

Related Linear tickets, Github issues, and Community forum posts

Addresses the question I posed here: https://community.n8n.io/t/any-way-to-use-openai-chat-model-with-default-open-ai-tool-web-search-preview/95318

Details

I would like to use the OpenAI Chat Model with the default tool provided by OpenAI for web searches: web_search_preview

As I understand it, this would allow the requests to the Open AI Chat Model to use web search’s to supplement the response similar to what is shown on the ChatGPT site.

The OpenAI documentation shows how to use this through their API: https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses

import OpenAI from "openai";
const client = new OpenAI();

const response = await client.responses.create({
    model: "gpt-4o",
    tools: [ { type: "web_search_preview" } ],
    input: "What was a positive news story from today?",
});

I looked into LangChain and it appears that this is supported in their API as well as a pass through. See: ChatOpenAI | 🦜️🔗 LangChain

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4o-mini")

tool = {"type": "web_search_preview"}
llm_with_tools = llm.bind_tools([tool])

response = llm_with_tools.invoke("What was a positive news story from today?")

So I tracked down the n8n node code to see if there was any way to pass this in through a configuration. From what I can tell there is not. See:

const model = new ChatOpenAI({
			openAIApiKey: credentials.apiKey as string,
			modelName,
			...options,
			timeout: options.timeout ?? 60000,
			maxRetries: options.maxRetries ?? 2,
			configuration,
			callbacks: [new N8nLlmTracing(this)],
			modelKwargs,
			onFailedAttempt: makeN8nLlmFailedAttemptHandler(this, openAiFailedAttemptHandler),
});

I think it should be pretty easy for someone that knows the codebase well to add another option to allow passing in the names of some default tools or something similar. Unfortunately I don’t know n8n well enough to run it in development or how all of this works. But I thought I would ask here to see if I am missing something or if anyone that does know would be willing to give it a try.

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@n8n-assistant n8n-assistant bot added community Authored by a community member in linear Issue or PR has been created in Linear for internal review labels Apr 1, 2025
@Joffcom
Copy link
Member

Joffcom commented Apr 1, 2025

Hey @abierbaum,

Thanks for the PR, We have created "GHC-1421" as the internal reference to get this reviewed.

One of us will be in touch if there are any changes needed, in most cases this is normally within a couple of weeks but it depends on the current workload of the team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Authored by a community member in linear Issue or PR has been created in Linear for internal review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants