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?