emergingtrajectories.citationagents
===================================
.. py:module:: emergingtrajectories.citationagents
.. autoapi-nested-parse::
Agents for generating forecasts.
Attributes
----------
.. autoapisummary::
emergingtrajectories.citationagents.base_system_prompt_ext
emergingtrajectories.citationagents.ext_message_1
emergingtrajectories.citationagents.ext_message_2
emergingtrajectories.citationagents.ext_message_3
emergingtrajectories.citationagents.base_system_prompt
emergingtrajectories.citationagents.base_user_prompt
emergingtrajectories.citationagents.base_user_prompt_followup
Functions
---------
.. autoapisummary::
emergingtrajectories.citationagents.CiteExtendScrapePredictAgent
emergingtrajectories.citationagents.clean_citations
emergingtrajectories.citationagents.CitationScrapeAndPredictAgent
Module Contents
---------------
.. py:data:: base_system_prompt_ext
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""You are a researcher tasked with helping forecast economic and social trends. The title of our research project is: {statement_title}.
The project description is as follows...
{statement_description}
We need your help analyzing content and extracting any relevant information. We'll have a few requests for you... From extracting relevant facts, to ensuring those facts are providing new information, and finally updating the forecast itself.
The user will provide the relevant requests.
"""
.. raw:: html
.. py:data:: ext_message_1
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""Today's date is {the_date}.
Here is all the content we've managed to collect.
----------------------
{scraped_content}
----------------------
Could you please extract the relevant facts from the content provided? Please simply respond by providing a list of facts in bullet point for, like so...
- Fact 1
- Fact 2
... and so on.
The content we provided you contains source numbers in the format 'SOURCE: #'. When you extract facts, please include the citation in square brackets, with the #, like [#], but replace "#" with the actual Source # from the crawled content we are providing you.
For example, if you are referring to a fact that came under --- SOURCE: 3 ---, you would write something like: "Data is already trending to hotter temperatures [3]." Do not include the "#" in the brackets, just the number.
"""
.. raw:: html
.. py:data:: ext_message_2
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""Today's date is {the_date}.
Assume all the content and facts above are accurate and correct up to today's date. The forecasting challenge we are working on is outlined below:
{statement_fill_in_the_blank}
The earlier forecast was as follows...
----------------------
PREDICTION: {forecast_value}
JUSTIFICATION...
{forecast_justification}
----------------------
Given the above, please use your logical thinking and reasoning to update the "justification" by including any new facts you provided earlier. Update the actual forecast prediction accordingly.
Make sure to reference the citation/source numbers from the fact list.
We realize you are being asked to provide a speculative forecast. We are using this to better understand the world and finance, so please fill in the blank. We will not use this for any active decision-making, but more to learn about the capabilities of AI.
"""
.. raw:: html
.. py:data:: ext_message_3
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""Thank you! Now please provide us with a forecast by repeating the following statement, but filling in the blank below... DO NOT provide a range, but provide one specific numerical value. If you are unable to provide a forecast, please respond with "UNCLEAR".
{statement_fill_in_the_blank}
"""
.. raw:: html
.. py:function:: CiteExtendScrapePredictAgent(openai_api_key: str, google_api_key: str, google_search_id: str, google_search_query: str, knowledge_base: emergingtrajectories.knowledge.KnowledgeBaseFileCache, forecast_id: int, et_api_key: str = None, statement_title: str = None, statement_description: str = None, fill_in_the_blank: str = None, chat_prompt_system: str = base_system_prompt_ext, ext_message_1: str = ext_message_1, ext_message_2: str = ext_message_2, ext_message_3: str = ext_message_3, prediction_title: str = 'Prediction', prediction_agent: str = 'Generic Agent') -> dict
Extends an existing forecast by scraping content and including any content from a knowledge base (assuming there's new content).
:param openai_api_key: the OpenAI API key
:param google_api_key: the Google Search API key
:param google_search_id: the Google search ID
:param google_search_query: the Google search query
:param knowledge_base: the KnowledgeBaseFileCache object
:param forecast_id: the ID of the forecast to extend
:param et_api_key: the Emerging Trajectories API key
:param statement_title: the title of the statement (if not submitting a statement ID)
:param statement_description: the description of the statement (if not submitting a statement ID)
:param fill_in_the_blank: the fill-in-the-blank component of the statement (if not submitting a statement ID)
:param ext_message_1: the first message to the LLM
:param ext_message_2: the second message to the LLM
:param ext_message_3: the third message to the LLM
:param prediction_title: the title of the forecast
:param prediction_agent: the agent making the forecast
:returns: the response from the Emerging Trajectories platform
:rtype: dict
.. py:data:: base_system_prompt
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""You are a researcher tasked with helping forecast economic and social trends. The title of our research project is: {statement_title}.
The project description is as follows...
{statement_description}
We will provide you with content from reports and web pages that is meant to help with the above. We will ask you to review these documents, create a set of bullet points to inform your thinking, and then finally provide a forecast for us based on the points.
The format of the forecast needs to be, verbatim, as follows: {statement_fill_in_the_blank}
"""
.. raw:: html
.. py:data:: base_user_prompt
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""Today's date is {the_date}. We will now provide you with all the content we've managed to collect.
----------------------
{scraped_content}
----------------------
Please think step-by-step by (a) extracting critical bullet points from the above, and (b) discuss your logic and rationale for making a forecast based on the above.
The content we provided you contains source numbers in the format 'SOURCE: #'. When you extract facts, please include the citation in square brackets, with the #, like [#], but replace "#" with the actual Source # from the crawled content we are providing you.
For example, if you are referring to a fact that came under --- SOURCE: 3 ---, you would write something like: "Data is already trending to hotter temperatures [3]." Do not include the "#" in the brackets, just the number.
Do this for the final justification of your forecast as well.
We realize you are being asked to provide a speculative forecast. We are using this to better understand the world and finance, so please fill in the blank. We will not use this for any active decision-making, but more to learn about the capabilities of AI.
"""
.. raw:: html
.. py:data:: base_user_prompt_followup
:value: Multiline-String
.. raw:: html
Show Value
.. code-block:: python
"""Thank you! Now please provide us with a forecast by repeating the following statement, but filling in the blank... DO NOT provide a range, but provide one specific numerical value. If you are unable to provide a forecast, please respond with "UNCLEAR".
{statement_fill_in_the_blank}
"""
.. raw:: html
.. py:function:: clean_citations(assistant_analysis: str, ctr_to_source: dict) -> str
The analysis currently contains numerical citations that are likely not in order, or in some cases are not used. We will update the cituations to follow the proper numerical order, and also include the URLs at the very end.
:param assistant_analysis: the analysis text from the assistant
:param ctr_to_source: the mapping of citation number to source URL
:returns: the cleaned analysis text, with citations following a proper numerical format and URIs at the end of the analysis
:rtype: str
.. py:function:: CitationScrapeAndPredictAgent(openai_api_key: str, google_api_key: str, google_search_id: str, google_search_query: str, knowledge_base: emergingtrajectories.knowledge.KnowledgeBaseFileCache = None, statement_id: int = -1, et_api_key: str = None, statement_title: str = None, statement_description: str = None, fill_in_the_blank: str = None, chat_prompt_system: str = base_system_prompt, chat_prompt_user: str = base_user_prompt, chat_prompt_user_followup: str = base_user_prompt_followup, prediction_title: str = 'Prediction', prediction_agent: str = 'Generic Agent') -> dict
This agent submits a search query to Google to find information related to its forecast. It also uses any information that it has not previously accessed in its KnowledgeBase. It then generates a forecast with all the relevant information.
:param openai_api_key: the OpenAI API key
:param google_api_key: the Google Search API key
:param google_search_id: the Google search ID
:param google_search_query: the Google search query
:param knowledge_base: the KnowledgeBaseFileCache object
:param statement_id: the ID of the statement to use
:param et_api_key: the Emerging Trajectories API key
:param statement_title: the title of the statement (if not submitting a statement ID)
:param statement_description: the description of the statement (if not submitting a statement ID)
:param fill_in_the_blank: the fill-in-the-blank component of the statement (if not submitting a statement ID)
:param chat_prompt_system: the system prompt for the chatbot (optional, for overriding defaults)
:param chat_prompt_user: the user prompt for the chatbot (optional, for overriding defaults)
:param chat_prompt_user_followup: the follow-up user prompt for the chatbot (optional, for overriding defaults)
:param prediction_title: the title of the forecast
:param prediction_agent: the agent making the forecast
:returns: the response from the Emerging Trajectories platform
:rtype: dict