Skip to content

Commit

Permalink
renamed add_additional_sources to complement_source_urls
Browse files Browse the repository at this point in the history
  • Loading branch information
ElishaKay committed Nov 12, 2024
1 parent 0d6ca2c commit 7119920
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/docs/gpt-researcher/context/tailored-research.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ The GPT Researcher package allows you to tailor the research to your needs such

You can specify the sources you want the GPT Researcher to research on by providing a list of URLs. The GPT Researcher will then conduct research on the provided sources via `source_urls`.

If you want GPT Researcher to perform additional research outside of the URLs you provided, i.e., conduct research on various other websites that it finds suitable for the query/sub-query, you can set the parameter `add_additional_sources` as `True`. Default value of `False` will only scour the websites you provide via `source_urls`.
If you want GPT Researcher to perform additional research outside of the URLs you provided, i.e., conduct research on various other websites that it finds suitable for the query/sub-query, you can set the parameter `complement_source_urls` as `True`. Default value of `False` will only scour the websites you provide via `source_urls`.


```python
from gpt_researcher import GPTResearcher
import asyncio

async def get_report(query: str, report_type: str, sources: list) -> str:
researcher = GPTResearcher(query=query, report_type=report_type, source_urls=sources, add_additional_sources=False)
researcher = GPTResearcher(query=query, report_type=report_type, source_urls=sources, complement_source_urls=False)
await researcher.conduct_research()
report = await researcher.write_report()
return report
Expand Down
4 changes: 2 additions & 2 deletions gpt_researcher/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
report_source: str = ReportSource.Web.value,
tone: Tone = Tone.Objective,
source_urls=None,
add_additional_sources=False,
complement_source_urls=False,
documents=None,
vector_store=None,
vector_store_filter=None,
Expand All @@ -58,7 +58,7 @@ def __init__(
self.max_subtopics = max_subtopics
self.tone = tone if isinstance(tone, Tone) else Tone.Objective
self.source_urls = source_urls
self.add_additional_sources: bool = add_additional_sources
self.complement_source_urls: bool = complement_source_urls
self.research_sources = [] # The list of scraped sources including title, content and images
self.research_images = [] # The list of selected research images
self.documents = documents
Expand Down
4 changes: 2 additions & 2 deletions gpt_researcher/skills/researcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ async def conduct_research(self):
f"🧐 I was unable to find relevant context in the provided sources...",
self.websocket,
)
# If add_additional_sources parameter is set, more resources can be gathered to create additional context using default web search
if self.researcher.add_additional_sources:
# If complement_source_urls parameter is set, more resources can be gathered to create additional context using default web search
if self.researcher.complement_source_urls:
additional_research = await self.__get_context_by_search(self.researcher.query)
self.context += ' '.join(additional_research)

Expand Down
18 changes: 9 additions & 9 deletions tests/research_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Hi! The following test cases are for the new parameter `add_additional_sources` and fix on the functional error with `source_urls` in GPTResearcher class.
Hi! The following test cases are for the new parameter `complement_source_urls` and fix on the functional error with `source_urls` in GPTResearcher class.
The source_urls parameter was resetting each time in conduct_research function causing gptr to forget the given links. Now, that has been fixed and a new parameter is introduced.
This parameter named will `add_additional_sources` allow GPTR to research on sources other than the provided sources via source_urls if set to True.
This parameter named will `complement_source_urls` allow GPTR to research on sources other than the provided sources via source_urls if set to True.
Default is False, i.e., no additional research will be conducted on newer sources.
"""

Expand Down Expand Up @@ -37,7 +37,7 @@ async def get_report(query: str, report_type: str, sources: list) -> str:
custom_logs_handler = CustomLogsHandler()
researcher = GPTResearcher(query=query,
report_type=report_type,
add_additional_sources=False,
complement_source_urls=False,
websocket=custom_logs_handler)
await researcher.conduct_research()
report = await researcher.write_report()
Expand Down Expand Up @@ -78,13 +78,13 @@ async def get_report(query: str, report_type: str, sources: list) -> str:



#### Test case 3 (Suggested solution - add_additional_sources parameter allows GPTR to scour more of the web and not restrict to source_urls)
#### Test case 3 (Suggested solution - complement_source_urls parameter allows GPTR to scour more of the web and not restrict to source_urls)

# from gpt_researcher.agent import GPTResearcher # Ensure this path is correct
# import asyncio

# async def get_report(query: str, report_type: str, sources: list) -> str:
# researcher = GPTResearcher(query=query, report_type=report_type, source_urls=sources, add_additional_sources=True)
# researcher = GPTResearcher(query=query, report_type=report_type, source_urls=sources, complement_source_urls=True)
# await researcher.conduct_research()
# report = await researcher.write_report()
# return report, researcher
Expand All @@ -97,17 +97,17 @@ async def get_report(query: str, report_type: str, sources: list) -> str:
# report, researcher = asyncio.run(get_report(query, report_type, sources))
# print(report)

# print(f"\nLength of the context = {len(researcher.get_research_context())}") # Must say Non-zero value because the query is UNRELATED to the contents of the page, but the add_additional_sources is set which should make gptr do default web search to gather contexts
# print(f"\nLength of the context = {len(researcher.get_research_context())}") # Must say Non-zero value because the query is UNRELATED to the contents of the page, but the complement_source_urls is set which should make gptr do default web search to gather contexts



# #### Test case 4 (Furthermore, GPTR will create more context in addition to source_urls if the add_additional_sources parameter is set allowing for a larger research scope)
# #### Test case 4 (Furthermore, GPTR will create more context in addition to source_urls if the complement_source_urls parameter is set allowing for a larger research scope)

# from gpt_researcher.agent import GPTResearcher # Ensure this path is correct
# import asyncio

# async def get_report(query: str, report_type: str, sources: list) -> str:
# researcher = GPTResearcher(query=query, report_type=report_type, source_urls=sources, add_additional_sources=True)
# researcher = GPTResearcher(query=query, report_type=report_type, source_urls=sources, complement_source_urls=True)
# await researcher.conduct_research()
# report = await researcher.write_report()
# return report, researcher
Expand All @@ -120,4 +120,4 @@ async def get_report(query: str, report_type: str, sources: list) -> str:
# report, researcher = asyncio.run(get_report(query, report_type, sources))
# print(report)

# print(f"\nLength of the context = {len(researcher.get_research_context())}") # Must say Non-zero value because the query is related to the contents of the page, and additionally the add_additional_sources is set which should make gptr do default web search to gather more contexts!
# print(f"\nLength of the context = {len(researcher.get_research_context())}") # Must say Non-zero value because the query is related to the contents of the page, and additionally the complement_source_urls is set which should make gptr do default web search to gather more contexts!

0 comments on commit 7119920

Please sign in to comment.