Share feedback, ideas and get community help

Updated 2 months ago

Function is not being called - Two days stuck :/

At a glance

The community member is using the OpenAI block with chatCompletion and wants to create a function to perform web searches like on chatgpt.com. They tried a simple code that returns a string, and it worked, but when they tried a code to make a web search, OpenAI is not calling the function. The community member provided the function code, which uses the Google Custom Search API, and mentioned that the URL directly on Chrome works, so the API keys are correct. However, the bot returns empty. A comment from another community member suggests that there may be limitations on scripts executed on the server, as per the Typebot documentation.

Useful resources
I'm using the OpenAI block with chatCompletion.

I want a function so OpenAI can perform web searches as it does on chatgpt.com

I tried a simple code that returns a string, function was called perfectly.

But when I tried a code to make a web search (below) openAI is not calling the function.

On the block, I'm inserting:
  • Create Chat Completion
  • User message: use function GoogleSearch to give me the latest news
  • Function name: GoogleSearch
  • Function description: Make searches on Google
  • Function parameters:
    • string
    • name search
    • description: Search text to make the Google Search
  • Function code:
const API_KEY = 'my key'
const SEARCH_ENGINE_ID = 'mykey'

if (search) {
const url = https://customsearch.googleapis.com/customsearch/v1?key=${API_KEY}&cx=${SEARCH_ENGINE_ID}&q=${encodeURIComponent(busca)}&num=1
return fetch(url)
.then(response => response.json())
.then(data => {
if (data.items && data.items.length > 0) {
return data.items[0].title + "\n" + data.items[0].snippet
}
return "Nenhum resultado encontrado"
})
} else {
return "Nenhum termo de busca fornecido"
}


The URL directly on Chrome works (so my keys are correct).

The bot returns empty.

Two days stuck here :/

Can anyone help me?
Add a reply
Sign up and join the conversation on Discord