Comments (9)
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.
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.
Same issue appeared with me also
from gpt-researcher.
Same issue appeared with me also
@omkamal Did you find any workaround?
from gpt-researcher.
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.
@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.
For example, what was your query? It seems not relevant to the detailed report but to generating sub queries.
from gpt-researcher.
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.
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.
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)
- Support for different Embeddings other than OpenAI HOT 2
- Can't run - needs exa-py HOT 2
- Output style issues + did not manage to locate a library called 'gobject-2.0-0' HOT 8
- "FileNotFoundError: [Errno 2] No such file or directory" with particular prompts HOT 2
- multi-agents module seems to be using gpt-4o no matter what is specified as "model" in task.json HOT 1
- BUG: Crash due to inconsistent arguments passed to GPTResearcher() constructor HOT 1
- UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f50e' in position 0: character maps to <undefined> HOT 5
- TypeError in Config class initialization and ensure proper type handling and directory validation. Solution Provided! HOT 1
- Research across multiple sources HOT 2
- Error with new tone feature when doing a research HOT 6
- Docker buildx to linux/amd64 from Mac M1 throws "system lacks support for the sse3 instruction set" HOT 2
- How to use own .env file? HOT 3
- KeyError: 'Objective (impartial and unbiased presentation of facts and findings)' HOT 2
- raise ImportError( ImportError: lxml.html.clean module is now a separate project lxml_html_clean. Install lxml[html_clean] or lxml_html_clean directly. HOT 1
- ERROR: Exception in ASGI application when running with Ollama. HOT 5
- Researcher using links from previous calls HOT 4
- gpt-researcher 0.8.0 pip package no longer works with anthropic models HOT 7
- context_length_exceeded HOT 2
- TypeError: the JSON object must be str, bytes or bytearray, not coroutine HOT 5
- Visualization issues :graph.get_graph(xray=1).draw_mermaid_png() HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gpt-researcher.