OpenInterpreter / 01

The #1 open-source voice interface for desktop, mobile, and ESP32 chips.
https://01.openinterpreter.com/
GNU Affero General Public License v3.0
4.99k stars 534 forks source link

JSONDecodeError when attempting to get data from the web #240

Open contractorwolf opened 7 months ago

contractorwolf commented 7 months ago

Describe the bug I have the latest version of the server and am running the build-it-yourself device but it seems to have a LOT of trouble trying to grab new data from the web. It can answer basic historical questions and stuff that i would expect chatGPT to have already built into the model. But when i try to get new data, by asking questions like: "what is the weather going to be like tomorrow in charlotte, nc? it seems to have issues. If i am looking at the console on the machine that is running the server it seems to hit this error over and over until it runs out of tokens:

  JSONDecodeError                           Traceback (most recent call last)                                                      
  Cell In[71], line 6                                                                                                              
        4 pass                                                                                                                     
        5 print('##active_line3##')                                                                                                
  ----> 6 search_results = computer.browser.search('Ankylosaurus')                                                                 
        7 print('##active_line4##')                                                                                                
        8 search_results                                                                                                           

  File ~/miniconda3/envs/01/lib/python3.10/site-packages/interpreter/core/computer/browser/browser.py:16, in Browser.search(self,  
  query)                                                                                                                           
        9 """                                                                                                                      
       10 Searches the web for the specified query and returns the results.                                                        
       11 """                                                                                                                      
       12 response = requests.get(                                                                                                 
       13     f'{self.computer.api_base.strip("/")}/browser/search',                                                               
       14     params={"query": query},                                                                                             
       15 )                                                                                                                        
  ---> 16 return response.json()["result"]                                                                                         

  File ~/miniconda3/envs/01/lib/python3.10/site-packages/requests/models.py:975, in Response.json(self, **kwargs)                  
      971     return complexjson.loads(self.text, **kwargs)                                                                        
      972 except JSONDecodeError as e:                                                                                             
      973     # Catch JSON-related errors and raise as requests.JSONDecodeError                                                    
      974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError                                                   
  --> 975     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)                                                                   

  JSONDecodeError: Expecting value: line 2 column 1 (char 1)  

It seems to try a bunch of ways to get the information but always has issues and eventually gives up and apologizes.

Expected behavior I would expect it to be able to retrieve data from the web

Screenshots

Screenshot 2024-04-14 at 5 23 07 PM

Desktop (please complete the following information):

fspacheco commented 7 months ago

I have the same problem: computer.api_base points to https://api.openinterpreter.com/v0/ that is broken. For the moment, I added an alternative search using Google in interpreter/core/computer/browser/browser.py

import requests

class Browser:
    def __init__(self, computer):
        self.computer = computer

    def search(self, query):
        """
        Searches the web for the specified query and returns the results.
        """
        try:
            response = requests.get(
                f'{self.computer.api_base.strip("/")}/browser/search',
                params={"query": query},
            )
            return response.json()["result"]
        except:
            try:
                print("Error in OI API. Trying with Google search")
                import googlesearch
                import json
                response = googlesearch.search(query, tld="com", num=1, stop=1, pause=1)
                for r in response:
                    json_response = json.dumps({'result':r})
                return json_response
            except:
                print("Error in Google search")