emergingtrajectories.utils ========================== .. py:module:: emergingtrajectories.utils Attributes ---------- .. autoapisummary:: emergingtrajectories.utils._extract_prediction_prompt emergingtrajectories.utils._extract_prediction_prompt_error Classes ------- .. autoapisummary:: emergingtrajectories.utils.UtilityHelper Functions --------- .. autoapisummary:: emergingtrajectories.utils.is_numeric emergingtrajectories.utils.run_forecast Module Contents --------------- .. py:data:: _extract_prediction_prompt :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """You are helping a researcher with a data extraction exercise. You will be provided with a prediction statement and a broader piece of text. Your objective is to extract the specific numerical prediction and provide it as a response. DO NOT qualify your response in any way. For example, suppose you have the following... |||---||| PREDICTION STATEMENT: please predict the probability that the price of Bitcoin will exceed $100,000 by the end of 2024. TEXT: The probability that bitcoin will exceed $100,000 by the end of 2024 is 0.37. |||---||| In the case above, your response would simply be "0.37". The actual metrics (i.e., prediction) might be provided with formatting. For example... |||---||| PREDICTION STATEMENT: The probability that Boeing's (NYSE:BA) share price at the close of markets on or before March 1, 2024 will be $220.00 USD or higher is _____ (value between 0.00 and 1.00). TEXT: The probability that Boeing's (NYSE:BA) share price at the close of markets on or before March 1, 2024, will be $220.00 USD or higher is **0.65**. |||---||| In this case, ignore the asterisks or instructions ("value between 0.00 and 1.00") and provide the correct response, which is 0.65. The user will provide you with a PREDICTION STATEMENT and TEXT and you need to answer like the above. On the extremely rare occasion that the TEXT does not have a proper numerical prediction or you are unable to extract it, simply respond with "UNCLEAR". """ .. raw:: html
.. py:data:: _extract_prediction_prompt_error :value: 'UNCLEAR' .. py:function:: is_numeric(string: str) -> bool Checks whether the 'string' passed as an argument can be converted into a numeric value. :param string: the string in question :returns: Boolean value; True if the string can be converted into a numeric value, False otherwise. .. py:function:: run_forecast(function_to_call, n, *args, **kwargs) .. py:class:: UtilityHelper(api_key, model='gpt-4-0125-preview') Bases: :py:obj:`object` The UtilityHelper class is used to extract predictions from text messages. :param api_key: the OpenAI API key :param model: the OpenAI model to use for the extraction process .. py:attribute:: api_key .. py:attribute:: model :value: 'gpt-4-0125-preview' .. py:method:: extract_prediction(response: str, statement_challenge: str) -> float Extracts the prediction value from the response to a statement challenge. :param response: the response to the statement challenge (i.e., what was predicted by another LLM) :param statement_challenge: the statement challenge -- what is being predicted :returns: The extracted prediction value as a float. Raises an exception if the prediction cannot be extracted.