Code Monkey home page Code Monkey logo

Comments (9)

omkamal avatar omkamal commented on August 16, 2024 1

I just tried installing it on Ubuntu instead of MacOs, and it worked fine.

So it seems to be an issue with MacOS

from gpt-researcher.

boriside avatar boriside commented on August 16, 2024 1

Thank you, I did something similar, but for me the rest of the code failed with an empty object so I left it like: sub_queries = []

from gpt-researcher.

omkamal avatar omkamal commented on August 16, 2024

Same issue appeared with me also

from gpt-researcher.

kaziu007 avatar kaziu007 commented on August 16, 2024

Same issue appeared with me also

@omkamal Did you find any workaround?

from gpt-researcher.

assafelovic avatar assafelovic commented on August 16, 2024

This looks like an issue with calling OpenAI which does not return a valid list of subqueries. It would help to get your full example to better investigate @kaziu007

from gpt-researcher.

kaziu007 avatar kaziu007 commented on August 16, 2024

@assafelovic what exactly I shall share to provide you with more details? The issue is occurring once in a while only for detailed reports. While it happens it tends to repeat for next runs with different queries.

from gpt-researcher.

assafelovic avatar assafelovic commented on August 16, 2024

For example, what was your query? It seems not relevant to the detailed report but to generating sub queries.

from gpt-researcher.

boriside avatar boriside commented on August 16, 2024

I got the same multiple times. Query can be for example: tell me about nike
In this case I picked detailed research.

from gpt-researcher.

Lego4005 avatar Lego4005 commented on August 16, 2024

I modified the gpt_researcher/master/functions.py file and it hasn't happened since

Modifications Made
Error Handling: Introduced a try and except block specifically to catch json.JSONDecodeError. This type of error occurs when json.loads() tries to parse a string that isn’t valid JSON. By catching this error, the application can handle it gracefully instead of crashing.

Logging: Added a print statement before the JSON parsing occurs. This logs the raw response received from the create_chat_completion call. If there is an error with the JSON format, you can see exactly what the data looked like right before the failure. Additionally, if an error is caught, another print statement logs the error along with the problematic data.

Response Handling: If the JSON parsing fails, instead of letting the application crash, we set sub_queries to a default value (an empty list in this case). This allows the application to continue operating even if the data isn’t as expected.

I put the full file in a txt if you need the whole thing. Also commented out the original code.

functions.txt

import asyncio
import json
from fastapi import HTTPException

import markdown

from gpt_researcher.master.prompts import *
from gpt_researcher.scraper.scraper import Scraper
from gpt_researcher.utils.llm import *

# ... [other parts of your code] ...

async def get_sub_queries(query: str, agent_role_prompt: str, cfg, parent_query: str, report_type: str):
    """
    Gets the sub queries
    Args:
        query: original query
        agent_role_prompt: agent role prompt
        cfg: Config
        parent_query: Parent query for context
        report_type: Type of the report to generate

    Returns:
        sub_queries: List of sub queries

    """
    max_research_iterations = cfg.max_iterations if cfg.max_iterations else 1
    response = await create_chat_completion(
        model=cfg.smart_llm_model,
        messages=[
            {"role": "system", "content": f"{agent_role_prompt}"},
            {"role": "user", "content": generate_search_queries_prompt(query, parent_query, report_type, max_iterations=max_research_iterations)}],
        temperature=0,
        llm_provider=cfg.llm_provider
    )
    
    # Log the response for debugging purposes
    print(f"Response received from create_chat_completion: {response}")
    
    # Initialize sub_queries to None or a default value
    sub_queries = None
    
    # Try to parse the JSON, and handle exceptions if parsing fails
    try:
        sub_queries = json.loads(response)
    except json.JSONDecodeError as e:
        # Logging the error
        print(f"JSON decoding failed: {e} - Response content: {response}")
        # You can also use a logging library here if you prefer.
        
        # Optionally, raise an HTTPException for FastAPI to return a HTTP 400 response to the client
        # raise HTTPException(status_code=400, detail="Invalid response format received.")
        
        # If the function must not raise an exception, set sub_queries to a default or empty value
        sub_queries = []  # or {} or None, depending on how your code expects to handle this
    
    return sub_queries

# ... [rest of your code] ...

from gpt-researcher.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.