hihumanzone / Gemini-Discord-Bot

A Discord bot leveraging Google Gemini. Has image recognition, conversation engagement, and content understanding.
https://gemini-discord-bot.vercel.app
MIT License
36 stars 14 forks source link

web search errors #9

Open lima12 opened 3 hours ago

lima12 commented 3 hours ago

step to replicate:

  1. ask the bot to perform websearch
  2. look at console error while performing web search: Error: Failed to perform the search request: getaddrinfo ENOTFOUND search.neuranet-ai.com

image

lima12 commented 3 hours ago

https://neuranet-ai.com/ well look like they shutting down

lima12 commented 3 hours ago

Here a temp fix for this issue. Here what you need:

async function performSearch(query) {
  const apiKey = 'replace-this'; 
  const cx = 'replace-this-too';
  const url = `https://www.googleapis.com/customsearch/v1?q=${encodeURIComponent(query)}&key=${apiKey}&cx=${cx}`;

  try {
    const response = await axios.get(url);
    const entries = response.data.items; 

    if (Array.isArray(entries)) {
      const resultObject = entries.slice(0, 5).map((entry, index) => {
        const title = entry.title;
        const result = entry.snippet;
        const url = entry.link;

        return {
          [`result_${index + 1}`]: { title, result, url }
        };
      });

      const note = {
        "Note": "Search results provide only an overview and do not offer sufficiently detailed information. Please continue by using the Search Website tool and search websites to find relevant information about the topic."
      };

      const finalResult = JSON.stringify(
        resultObject.reduce((acc, curr) => Object.assign(acc, curr), note),
        null,
        2
      );

      /*console.log(finalResult); //For debug purpose only!*/
      return finalResult;

    } else {
      console.error('Entries is not an array:', entries);
      throw new Error('Unexpected response format');
    }
  } catch (error) {
    console.error('Request failed:', error.response?.data || error.message);
    throw new Error(`Failed to perform the search request: ${error.message}`);
  }
}

This isn't official solution! im just a scripty pasta dude.