emergingtrajectories.recursiveagent =================================== .. py:module:: emergingtrajectories.recursiveagent .. autoapi-nested-parse:: x(t+1) = x(t) + z ... where x(t) is the current observation about the world ... z is the set of scenarios that will impact x in the future (i.e., x(t+1)) This is influenced by Yann LeCun's world modeling approach discussion: https://www.linkedin.com/feed/update/urn:li:activity:7165738293223931904/ We are aiming to eventually build some sort of a fact base system. Until then, however, we will be passing information directly through to the agent here. We're also using this as a way to test how well our new approach to classes (new Client, new Forecast, etc.) will work, so we can plug and play different types of agents here. Note that this approach will *not* test new knowledge bases *yet*. Attributes ---------- .. autoapisummary:: emergingtrajectories.recursiveagent.base_system_prompt emergingtrajectories.recursiveagent.base_user_prompt emergingtrajectories.recursiveagent.base_user_prompt_followup Classes ------- .. autoapisummary:: emergingtrajectories.recursiveagent.ETClient emergingtrajectories.recursiveagent.RecursiveForecastingAgent Functions --------- .. autoapisummary:: emergingtrajectories.recursiveagent.clean_citations Module Contents --------------- .. py:class:: ETClient(api_key: str) Bases: :py:obj:`object` .. py:attribute:: base_url :value: 'https://emergingtrajectories.com/a/api/v0.2/' .. py:attribute:: api_key .. py:method:: get_statement(statement_id: int) -> emergingtrajectories.Statement Returns a given statement from the platform. Includes title, description, deadline, and fill-in-the-blank. :param statement_id: the ID of the statement to retrieve :returns: the statement from the platform :rtype: Statement .. py:method:: get_forecast(forecast_id: int) -> emergingtrajectories.Forecast Returns a given forecast from the platform. :param forecast_id: the ID of the statement to retrieve :returns: the forecast from the platform :rtype: Forecast .. py:method:: add_facts_to_factbase(fact_db_slug: str, url: str, facts: list[str]) -> bool Adds a list of facts to a factbase on the Emerging Trajectories website. :param fact_db_slug: the slug of the fact database to add the fact to. :param url: the URL of the fact. :param facts: the facts to add (a list of strings). Reutnr: bool: True if successful, False otherwise. .. py:method:: add_fact_to_factbase(fact_db_slug: str, url: str, fact: str) -> bool Adds a fact to a factbase on the Emerging Trajectories website. :param fact_db_slug: the slug of the fact database to add the fact to. :param url: the URL of the fact. :param fact: the fact to add. Reutnr: bool: True if successful, False otherwise. .. py:method:: add_content_to_factbase(fact_db_slug: str, url: str, content: str, topic: str) -> bool Sends content to the Emerging Trajectories website and extract facts from it. :param fact_db_slug: the slug of the fact database to add the content to. :param url: the URL of the content. Note: we do not actually crawl this, we assume the content passed is the right conent. :param content: the content to extract facts from. :param topic: the topic of the content. :returns: True if successful, False otherwise. :rtype: bool .. 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: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:class:: RecursiveForecastingAgent(client: ETClient, chatbot: phasellm.llms.ChatBot, google_api_key: str, google_search_id: str, google_search_query: str, knowledge_base: emergingtrajectories.knowledge.KnowledgeBaseFileCache) Bases: :py:obj:`object` .. py:attribute:: google_api_key .. py:attribute:: google_search_id .. py:attribute:: google_search_query .. py:attribute:: knowledge_base .. py:attribute:: client .. py:attribute:: chatbot .. py:method:: setChatBot(chatbot) .. py:method:: getChatBot() .. py:method:: create_forecast(statement: emergingtrajectories.Statement, openai_api_key, et_api_key, facts=None) Options for taking in x(t) or z... 1) x(t) and z are strings... An array of facts. 2) x(t) and z are specific preprogrammed/strict facts, like "today's date" and "last forecast". 3) Facts are "Fact Objects" that have specific string representations. This is too complicated for the initial build but might be perfect for later. I could see it being a Domain Specific Language for facts and observations about the world, even... .. py:method:: extend_forecast(forecast: emergingtrajectories.Forecast)