From 2cd48b8046874930cb1684ee22650433430a04b0 Mon Sep 17 00:00:00 2001 From: ElishaKay Date: Tue, 22 Oct 2024 15:52:27 +0300 Subject: [PATCH 01/12] custom-websocket.py --- tests/custom-websocket.py | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/custom-websocket.py diff --git a/tests/custom-websocket.py b/tests/custom-websocket.py new file mode 100644 index 000000000..e5fbf4559 --- /dev/null +++ b/tests/custom-websocket.py @@ -0,0 +1,45 @@ +from typing import Dict, Any +import asyncio +from gpt_researcher import GPTResearcher + +class CustomWebSocket: + """A custom WebSocket class to handle JSON data.""" + def __init__(self): + self.logs = [] # Initialize logs to store data + + async def send_json(self, data: Dict[str, Any]) -> None: + """Send JSON data and log it.""" + self.logs.append(data) # Append data to logs + print(f"My custom Log: {data}") # For demonstration, print the log + +async def run(): + # Define the necessary parameters with sample values + + query = "What happened in the latest burning man floods?" + report_type = "research_report" # Type of report to generate + report_source = "online" # Could specify source like 'online', 'books', etc. + tone = "informative" # Tone of the report ('informative', 'casual', etc.) + config_path = None # Path to a config file, if needed + headers = {"Authorization": "Bearer YOUR_API_TOKEN"} # Any necessary headers for API calls + + # Initialize researcher with a custom WebSocket + custom_websocket = CustomWebSocket() + + researcher = GPTResearcher( + query=query, + report_type=report_type, + report_source=report_source, + tone=tone, + config_path=config_path, + websocket=custom_websocket, + headers=headers + ) + + await researcher.conduct_research() # Conduct the research + report = await researcher.write_report() # Write the research report + + return report + +# Run the asynchronous function using asyncio +if __name__ == "__main__": + asyncio.run(run()) \ No newline at end of file From bac91b6711e8f45dd7aab2e3599ea9ca2274d533 Mon Sep 17 00:00:00 2001 From: ElishaKay Date: Tue, 22 Oct 2024 17:30:04 +0300 Subject: [PATCH 02/12] logs handler --- tests/{custom-websocket.py => gptr-logs-handler.py} | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) rename tests/{custom-websocket.py => gptr-logs-handler.py} (90%) diff --git a/tests/custom-websocket.py b/tests/gptr-logs-handler.py similarity index 90% rename from tests/custom-websocket.py rename to tests/gptr-logs-handler.py index e5fbf4559..6d8d50fac 100644 --- a/tests/custom-websocket.py +++ b/tests/gptr-logs-handler.py @@ -20,7 +20,6 @@ async def run(): report_source = "online" # Could specify source like 'online', 'books', etc. tone = "informative" # Tone of the report ('informative', 'casual', etc.) config_path = None # Path to a config file, if needed - headers = {"Authorization": "Bearer YOUR_API_TOKEN"} # Any necessary headers for API calls # Initialize researcher with a custom WebSocket custom_websocket = CustomWebSocket() @@ -31,8 +30,7 @@ async def run(): report_source=report_source, tone=tone, config_path=config_path, - websocket=custom_websocket, - headers=headers + websocket=custom_websocket ) await researcher.conduct_research() # Conduct the research From 4f4f86b9da130b434269a194529bfe2a281bdd9e Mon Sep 17 00:00:00 2001 From: ElishaKay Date: Tue, 22 Oct 2024 17:35:57 +0300 Subject: [PATCH 03/12] handling logs docs --- docs/docs/examples/handling-logs.md | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 docs/docs/examples/handling-logs.md diff --git a/docs/docs/examples/handling-logs.md b/docs/docs/examples/handling-logs.md new file mode 100644 index 000000000..d91ce4923 --- /dev/null +++ b/docs/docs/examples/handling-logs.md @@ -0,0 +1,49 @@ +# Handling logs of the GPTR Research Task + +Here is a snippet of code to help you: + +```python +from typing import Dict, Any +import asyncio +from gpt_researcher import GPTResearcher + +class CustomWebSocket: + """A custom WebSocket class to handle JSON data.""" + def __init__(self): + self.logs = [] # Initialize logs to store data + + async def send_json(self, data: Dict[str, Any]) -> None: + """Send JSON data and log it.""" + self.logs.append(data) # Append data to logs + print(f"My custom Log: {data}") # For demonstration, print the log + +async def run(): + # Define the necessary parameters with sample values + + query = "What happened in the latest burning man floods?" + report_type = "research_report" # Type of report to generate + report_source = "online" # Could specify source like 'online', 'books', etc. + tone = "informative" # Tone of the report ('informative', 'casual', etc.) + config_path = None # Path to a config file, if needed + + # Initialize researcher with a custom WebSocket + custom_websocket = CustomWebSocket() + + researcher = GPTResearcher( + query=query, + report_type=report_type, + report_source=report_source, + tone=tone, + config_path=config_path, + websocket=custom_websocket + ) + + await researcher.conduct_research() # Conduct the research + report = await researcher.write_report() # Write the research report + + return report + +# Run the asynchronous function using asyncio +if __name__ == "__main__": + asyncio.run(run()) +``` \ No newline at end of file From 9e517751e173ac1c557c958019e62aeeb5e80298 Mon Sep 17 00:00:00 2001 From: ElishaKay Date: Tue, 22 Oct 2024 17:42:33 +0300 Subject: [PATCH 04/12] better naming for example --- docs/docs/examples/handling-logs.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/docs/examples/handling-logs.md b/docs/docs/examples/handling-logs.md index d91ce4923..b10dc9831 100644 --- a/docs/docs/examples/handling-logs.md +++ b/docs/docs/examples/handling-logs.md @@ -7,8 +7,8 @@ from typing import Dict, Any import asyncio from gpt_researcher import GPTResearcher -class CustomWebSocket: - """A custom WebSocket class to handle JSON data.""" +class CustomLogsHandler: + """A custom Logs handler class to handle JSON data.""" def __init__(self): self.logs = [] # Initialize logs to store data @@ -27,7 +27,7 @@ async def run(): config_path = None # Path to a config file, if needed # Initialize researcher with a custom WebSocket - custom_websocket = CustomWebSocket() + custom_logs_handler = CustomLogsHandler() researcher = GPTResearcher( query=query, @@ -35,7 +35,7 @@ async def run(): report_source=report_source, tone=tone, config_path=config_path, - websocket=custom_websocket + websocket=custom_logs_handler ) await researcher.conduct_research() # Conduct the research From cdf6196c3609d34a4aeeccc8138b1de013f1bc6f Mon Sep 17 00:00:00 2001 From: ElishaKay Date: Tue, 22 Oct 2024 17:45:17 +0300 Subject: [PATCH 05/12] consistent naming --- tests/gptr-logs-handler.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/gptr-logs-handler.py b/tests/gptr-logs-handler.py index 6d8d50fac..db84af0a1 100644 --- a/tests/gptr-logs-handler.py +++ b/tests/gptr-logs-handler.py @@ -2,8 +2,8 @@ import asyncio from gpt_researcher import GPTResearcher -class CustomWebSocket: - """A custom WebSocket class to handle JSON data.""" +class CustomLogsHandler: + """A custom Logs handler class to handle JSON data.""" def __init__(self): self.logs = [] # Initialize logs to store data @@ -14,15 +14,15 @@ async def send_json(self, data: Dict[str, Any]) -> None: async def run(): # Define the necessary parameters with sample values - + query = "What happened in the latest burning man floods?" report_type = "research_report" # Type of report to generate report_source = "online" # Could specify source like 'online', 'books', etc. tone = "informative" # Tone of the report ('informative', 'casual', etc.) config_path = None # Path to a config file, if needed - + # Initialize researcher with a custom WebSocket - custom_websocket = CustomWebSocket() + custom_logs_handler = CustomLogsHandler() researcher = GPTResearcher( query=query, @@ -30,7 +30,7 @@ async def run(): report_source=report_source, tone=tone, config_path=config_path, - websocket=custom_websocket + websocket=custom_logs_handler ) await researcher.conduct_research() # Conduct the research @@ -40,4 +40,4 @@ async def run(): # Run the asynchronous function using asyncio if __name__ == "__main__": - asyncio.run(run()) \ No newline at end of file + asyncio.run(run()) From 18eca5e7454f73aba7d427ce08201214f217cad7 Mon Sep 17 00:00:00 2001 From: ElishaKay Date: Wed, 23 Oct 2024 09:15:58 +0300 Subject: [PATCH 06/12] testing your llm variables --- tests/test-your-llm.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/test-your-llm.py diff --git a/tests/test-your-llm.py b/tests/test-your-llm.py new file mode 100644 index 000000000..9cc0164ef --- /dev/null +++ b/tests/test-your-llm.py @@ -0,0 +1,31 @@ +import asyncio +from gpt_researcher.utils.llm import get_llm +from gpt_researcher import GPTResearcher +from dotenv import load_dotenv +load_dotenv() + +async def main(): + + # Example usage of get_llm function + llm_provider = "openai" + model = "gpt-3.5-turbo" + temperature = 0.7 + max_tokens = 1000 + + llm = get_llm(llm_provider, model=model, temperature=temperature, max_tokens=max_tokens) + print(f"LLM Provider: {llm_provider}, Model: {model}, Temperature: {temperature}, Max Tokens: {max_tokens}") + print('llm: ',llm) + await test_llm(llm=llm) + + +async def test_llm(llm): + # Test the connection with a simple query + messages = [{"role": "user", "content": "sup?"}] + try: + response = await llm.get_chat_response(messages, stream=False) + print("LLM response:", response) + except Exception as e: + print(f"Error: {e}") + +# Run the async function +asyncio.run(main()) \ No newline at end of file From 09087fefce52dd2b7dbfdfbccd7d200460ad3944 Mon Sep 17 00:00:00 2001 From: ElishaKay Date: Wed, 23 Oct 2024 09:16:53 +0300 Subject: [PATCH 07/12] docs upgrades --- .../gptr/handling-logs-as-they-stream.md} | 21 +++++++++-- .../gpt-researcher/llms/testing-your-llm.md | 37 +++++++++++++++++++ docs/sidebars.js | 4 +- 3 files changed, 58 insertions(+), 4 deletions(-) rename docs/docs/{examples/handling-logs.md => gpt-researcher/gptr/handling-logs-as-they-stream.md} (63%) create mode 100644 docs/docs/gpt-researcher/llms/testing-your-llm.md diff --git a/docs/docs/examples/handling-logs.md b/docs/docs/gpt-researcher/gptr/handling-logs-as-they-stream.md similarity index 63% rename from docs/docs/examples/handling-logs.md rename to docs/docs/gpt-researcher/gptr/handling-logs-as-they-stream.md index b10dc9831..aa6700dcd 100644 --- a/docs/docs/examples/handling-logs.md +++ b/docs/docs/gpt-researcher/gptr/handling-logs-as-they-stream.md @@ -1,6 +1,6 @@ -# Handling logs of the GPTR Research Task +# Handling Streaming Logs -Here is a snippet of code to help you: +Here is a snippet of code to help you handle the streaming logs of your Research tasks. ```python from typing import Dict, Any @@ -46,4 +46,19 @@ async def run(): # Run the asynchronous function using asyncio if __name__ == "__main__": asyncio.run(run()) -``` \ No newline at end of file +``` + +The data from the research process will be logged and stored in the `CustomLogsHandler` instance. You can customize the logging behavior as needed for your application. + +Here's a sample of the output: + +``` +{ + "type": "logs", + "content": "added_source_url", + "output": "✅ Added source url to research: https://www.npr.org/2023/09/28/1202110410/how-rumors-and-conspiracy-theories-got-in-the-way-of-mauis-fire-recovery\n", + "metadata": "https://www.npr.org/2023/09/28/1202110410/how-rumors-and-conspiracy-theories-got-in-the-way-of-mauis-fire-recovery" +} +``` + +The `metadata` field will include whatever metadata is relevant to the log entry. Let the script above run to completion for the full logs output of a given research task. \ No newline at end of file diff --git a/docs/docs/gpt-researcher/llms/testing-your-llm.md b/docs/docs/gpt-researcher/llms/testing-your-llm.md new file mode 100644 index 000000000..9f713d750 --- /dev/null +++ b/docs/docs/gpt-researcher/llms/testing-your-llm.md @@ -0,0 +1,37 @@ +# Testing your LLM + +Here is a snippet of code to help you verify that your LLM-related environment variables are set up correctly. + +```python +import asyncio +from gpt_researcher.utils.llm import get_llm +from gpt_researcher import GPTResearcher +from dotenv import load_dotenv +load_dotenv() + +async def main(): + + # Example usage of get_llm function + llm_provider = "openai" + model = "gpt-3.5-turbo" + temperature = 0.7 + max_tokens = 1000 + + llm = get_llm(llm_provider, model=model, temperature=temperature, max_tokens=max_tokens) + print(f"LLM Provider: {llm_provider}, Model: {model}, Temperature: {temperature}, Max Tokens: {max_tokens}") + print('llm: ',llm) + await test_llm(llm=llm) + + +async def test_llm(llm): + # Test the connection with a simple query + messages = [{"role": "user", "content": "sup?"}] + try: + response = await llm.get_chat_response(messages, stream=False) + print("LLM response:", response) + except Exception as e: + print(f"Error: {e}") + +# Run the async function +asyncio.run(main()) +``` \ No newline at end of file diff --git a/docs/sidebars.js b/docs/sidebars.js index 9c5377c11..8c698b9a2 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -36,6 +36,7 @@ 'gpt-researcher/gptr/example', 'gpt-researcher/gptr/config', 'gpt-researcher/gptr/scraping', + 'gpt-researcher/gptr/handling-logs-as-they-stream', 'gpt-researcher/gptr/querying-the-backend', 'gpt-researcher/gptr/automated-tests', 'gpt-researcher/gptr/troubleshooting', @@ -70,7 +71,8 @@ collapsed: true, items: [ 'gpt-researcher/llms/llms', - 'gpt-researcher/llms/running-with-ollama' + 'gpt-researcher/llms/running-with-ollama', + 'gpt-researcher/llms/testing-your-llm' ] }, { From 9f6217aeb6b5f9621813ac734a2f08b46f9fb70d Mon Sep 17 00:00:00 2001 From: ElishaKay Date: Wed, 23 Oct 2024 09:54:08 +0300 Subject: [PATCH 08/12] test get_retrievers function --- tests/test-your-retriever.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/test-your-retriever.py diff --git a/tests/test-your-retriever.py b/tests/test-your-retriever.py new file mode 100644 index 000000000..289a609d0 --- /dev/null +++ b/tests/test-your-retriever.py @@ -0,0 +1,22 @@ +import os +from dotenv import load_dotenv +from gpt_researcher.config.config import Config +from gpt_researcher.actions.retriever import get_retrievers + +# Load environment variables from .env file +load_dotenv() + +def test_retriever_configuration(): + # Initialize the Config object + config = Config() + + # Retrieve the retrievers based on the current configuration + retrievers = get_retrievers({}, config) + + # Print the retriever classes + print("Configured Retrievers:") + for retriever in retrievers: + print(retriever.__name__) + +if __name__ == "__main__": + test_retriever_configuration() \ No newline at end of file From 3b956b20eda2c8bda653600c2d3e0c3e637ae381 Mon Sep 17 00:00:00 2001 From: ElishaKay Date: Wed, 23 Oct 2024 11:21:01 +0300 Subject: [PATCH 09/12] test_your_retriever --- tests/test-your-retriever.py | 43 +++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/tests/test-your-retriever.py b/tests/test-your-retriever.py index 289a609d0..3e0c85ce0 100644 --- a/tests/test-your-retriever.py +++ b/tests/test-your-retriever.py @@ -1,22 +1,49 @@ -import os +import asyncio from dotenv import load_dotenv from gpt_researcher.config.config import Config from gpt_researcher.actions.retriever import get_retrievers - +from gpt_researcher.skills.researcher import ResearchConductor +import pprint # Load environment variables from .env file load_dotenv() -def test_retriever_configuration(): +async def test_scrape_data_by_query(): # Initialize the Config object config = Config() # Retrieve the retrievers based on the current configuration retrievers = get_retrievers({}, config) + print("Retrievers:", retrievers) + + # Create a mock researcher object with necessary attributes + class MockResearcher: + def init(self): + self.retrievers = retrievers + self.cfg = config + self.verbose = True + self.websocket = None + self.scraper_manager = None # Mock or implement scraper manager + self.vector_store = None # Mock or implement vector store + + researcher = MockResearcher() + research_conductor = ResearchConductor(researcher) + # print('research_conductor',dir(research_conductor)) + # print('MockResearcher',dir(researcher)) + # Define a sub-query to test + sub_query = "design patterns for autonomous ai agents" + + # Iterate through all retrievers + for retriever_class in retrievers: + # Instantiate the retriever with the sub-query + retriever = retriever_class(sub_query) + + # Perform the search using the current retriever + search_results = await asyncio.to_thread( + retriever.search, max_results=10 + ) - # Print the retriever classes - print("Configured Retrievers:") - for retriever in retrievers: - print(retriever.__name__) + print("\033[35mSearch results:\033[0m") + pprint.pprint(search_results, indent=4, width=80) if __name__ == "__main__": - test_retriever_configuration() \ No newline at end of file + asyncio.run(test_scrape_data_by_query()) \ No newline at end of file From 2c2816b33652068ac9f8a873399c91d365280eee Mon Sep 17 00:00:00 2001 From: ElishaKay Date: Wed, 23 Oct 2024 11:29:21 +0300 Subject: [PATCH 10/12] testing your retriever docs --- .../search-engines/test-your-retriever.md | 68 +++++++++++++++++++ docs/sidebars.js | 1 + 2 files changed, 69 insertions(+) create mode 100644 docs/docs/gpt-researcher/search-engines/test-your-retriever.md diff --git a/docs/docs/gpt-researcher/search-engines/test-your-retriever.md b/docs/docs/gpt-researcher/search-engines/test-your-retriever.md new file mode 100644 index 000000000..432888208 --- /dev/null +++ b/docs/docs/gpt-researcher/search-engines/test-your-retriever.md @@ -0,0 +1,68 @@ +# Testing your Retriever + +To test your retriever, you can use the following code snippet. The script will search for a sub-query and display the search results. + +```python +import asyncio +from dotenv import load_dotenv +from gpt_researcher.config.config import Config +from gpt_researcher.actions.retriever import get_retrievers +from gpt_researcher.skills.researcher import ResearchConductor +import pprint +# Load environment variables from .env file +load_dotenv() + +async def test_scrape_data_by_query(): + # Initialize the Config object + config = Config() + + # Retrieve the retrievers based on the current configuration + retrievers = get_retrievers({}, config) + print("Retrievers:", retrievers) + + # Create a mock researcher object with necessary attributes + class MockResearcher: + def init(self): + self.retrievers = retrievers + self.cfg = config + self.verbose = True + self.websocket = None + self.scraper_manager = None # Mock or implement scraper manager + self.vector_store = None # Mock or implement vector store + + researcher = MockResearcher() + research_conductor = ResearchConductor(researcher) + # print('research_conductor',dir(research_conductor)) + # print('MockResearcher',dir(researcher)) + # Define a sub-query to test + sub_query = "design patterns for autonomous ai agents" + + # Iterate through all retrievers + for retriever_class in retrievers: + # Instantiate the retriever with the sub-query + retriever = retriever_class(sub_query) + + # Perform the search using the current retriever + search_results = await asyncio.to_thread( + retriever.search, max_results=10 + ) + + print("\033[35mSearch results:\033[0m") + pprint.pprint(search_results, indent=4, width=80) + +if __name__ == "__main__": + asyncio.run(test_scrape_data_by_query()) +``` + +The output of the search results will include the title, body, and href of each search result. For example: + +```json +[{ + "body": "Jun 5, 2024 ... Three AI Design Patterns of Autonomous " + "Agents. Overview of the Three Patterns. Three notable AI " + "design patterns for autonomous agents include:.", + "href": "https://accredianpublication.medium.com/building-smarter-systems-the-role-of-agentic-design-patterns-in-genai-13617492f5df", + "title": "Building Smarter Systems: The Role of Agentic Design " + "Patterns in ..."}, + ...] +``` \ No newline at end of file diff --git a/docs/sidebars.js b/docs/sidebars.js index 8c698b9a2..17747a9b5 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -82,6 +82,7 @@ collapsed: true, items: [ 'gpt-researcher/search-engines/retrievers', + 'gpt-researcher/search-engines/test-your-retriever' ] }, { From 8ee0c9ec0718b7a7afa3f954486a36504e6751d6 Mon Sep 17 00:00:00 2001 From: ElishaKay Date: Wed, 23 Oct 2024 11:48:10 +0300 Subject: [PATCH 11/12] general llm test based on config --- .../gpt-researcher/llms/testing-your-llm.md | 33 ++++++++----------- tests/test-openai-llm.py | 31 +++++++++++++++++ tests/test-your-llm.py | 33 ++++++++----------- 3 files changed, 57 insertions(+), 40 deletions(-) create mode 100644 tests/test-openai-llm.py diff --git a/docs/docs/gpt-researcher/llms/testing-your-llm.md b/docs/docs/gpt-researcher/llms/testing-your-llm.md index 9f713d750..2980be953 100644 --- a/docs/docs/gpt-researcher/llms/testing-your-llm.md +++ b/docs/docs/gpt-researcher/llms/testing-your-llm.md @@ -3,34 +3,27 @@ Here is a snippet of code to help you verify that your LLM-related environment variables are set up correctly. ```python +from gpt_researcher.config.config import Config +from gpt_researcher.utils.llm import create_chat_completion import asyncio -from gpt_researcher.utils.llm import get_llm -from gpt_researcher import GPTResearcher from dotenv import load_dotenv load_dotenv() async def main(): + cfg = Config() - # Example usage of get_llm function - llm_provider = "openai" - model = "gpt-3.5-turbo" - temperature = 0.7 - max_tokens = 1000 - - llm = get_llm(llm_provider, model=model, temperature=temperature, max_tokens=max_tokens) - print(f"LLM Provider: {llm_provider}, Model: {model}, Temperature: {temperature}, Max Tokens: {max_tokens}") - print('llm: ',llm) - await test_llm(llm=llm) - - -async def test_llm(llm): - # Test the connection with a simple query - messages = [{"role": "user", "content": "sup?"}] try: - response = await llm.get_chat_response(messages, stream=False) - print("LLM response:", response) + report = await create_chat_completion( + model=cfg.smart_llm_model, + messages = [{"role": "user", "content": "sup?"}], + temperature=0.35, + llm_provider=cfg.smart_llm_provider, + stream=True, + max_tokens=cfg.smart_token_limit, + llm_kwargs=cfg.llm_kwargs + ) except Exception as e: - print(f"Error: {e}") + print(f"Error in calling LLM: {e}") # Run the async function asyncio.run(main()) diff --git a/tests/test-openai-llm.py b/tests/test-openai-llm.py new file mode 100644 index 000000000..9cc0164ef --- /dev/null +++ b/tests/test-openai-llm.py @@ -0,0 +1,31 @@ +import asyncio +from gpt_researcher.utils.llm import get_llm +from gpt_researcher import GPTResearcher +from dotenv import load_dotenv +load_dotenv() + +async def main(): + + # Example usage of get_llm function + llm_provider = "openai" + model = "gpt-3.5-turbo" + temperature = 0.7 + max_tokens = 1000 + + llm = get_llm(llm_provider, model=model, temperature=temperature, max_tokens=max_tokens) + print(f"LLM Provider: {llm_provider}, Model: {model}, Temperature: {temperature}, Max Tokens: {max_tokens}") + print('llm: ',llm) + await test_llm(llm=llm) + + +async def test_llm(llm): + # Test the connection with a simple query + messages = [{"role": "user", "content": "sup?"}] + try: + response = await llm.get_chat_response(messages, stream=False) + print("LLM response:", response) + except Exception as e: + print(f"Error: {e}") + +# Run the async function +asyncio.run(main()) \ No newline at end of file diff --git a/tests/test-your-llm.py b/tests/test-your-llm.py index 9cc0164ef..02a153747 100644 --- a/tests/test-your-llm.py +++ b/tests/test-your-llm.py @@ -1,31 +1,24 @@ +from gpt_researcher.config.config import Config +from gpt_researcher.utils.llm import create_chat_completion import asyncio -from gpt_researcher.utils.llm import get_llm -from gpt_researcher import GPTResearcher from dotenv import load_dotenv load_dotenv() async def main(): + cfg = Config() - # Example usage of get_llm function - llm_provider = "openai" - model = "gpt-3.5-turbo" - temperature = 0.7 - max_tokens = 1000 - - llm = get_llm(llm_provider, model=model, temperature=temperature, max_tokens=max_tokens) - print(f"LLM Provider: {llm_provider}, Model: {model}, Temperature: {temperature}, Max Tokens: {max_tokens}") - print('llm: ',llm) - await test_llm(llm=llm) - - -async def test_llm(llm): - # Test the connection with a simple query - messages = [{"role": "user", "content": "sup?"}] try: - response = await llm.get_chat_response(messages, stream=False) - print("LLM response:", response) + report = await create_chat_completion( + model=cfg.smart_llm_model, + messages = [{"role": "user", "content": "sup?"}], + temperature=0.35, + llm_provider=cfg.smart_llm_provider, + stream=True, + max_tokens=cfg.smart_token_limit, + llm_kwargs=cfg.llm_kwargs + ) except Exception as e: - print(f"Error: {e}") + print(f"Error in calling LLM: {e}") # Run the async function asyncio.run(main()) \ No newline at end of file From b9d2ceaee242eac7946651e68c628c67df2b9be8 Mon Sep 17 00:00:00 2001 From: ElishaKay Date: Wed, 23 Oct 2024 12:17:19 +0300 Subject: [PATCH 12/12] handling logs --- docs/docs/gpt-researcher/gptr/handling-logs-as-they-stream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/gpt-researcher/gptr/handling-logs-as-they-stream.md b/docs/docs/gpt-researcher/gptr/handling-logs-as-they-stream.md index aa6700dcd..22a9964d1 100644 --- a/docs/docs/gpt-researcher/gptr/handling-logs-as-they-stream.md +++ b/docs/docs/gpt-researcher/gptr/handling-logs-as-they-stream.md @@ -1,4 +1,4 @@ -# Handling Streaming Logs +# Handling Logs Here is a snippet of code to help you handle the streaming logs of your Research tasks.