diff --git a/prediction_market_agent/agents/known_outcome_agent/deploy.py b/prediction_market_agent/agents/known_outcome_agent/deploy.py index d364ed31..bbc0992e 100644 --- a/prediction_market_agent/agents/known_outcome_agent/deploy.py +++ b/prediction_market_agent/agents/known_outcome_agent/deploy.py @@ -17,6 +17,7 @@ from prediction_market_agent.agents.known_outcome_agent.known_outcome_agent import ( Result, get_known_outcome, + has_question_event_happened_in_the_past, ) @@ -36,7 +37,11 @@ def pick_markets(self, markets: list[AgentMarket]) -> list[AgentMarket]: # Assume very high probability markets are already known, and have # been correctly bet on, and therefore the value of betting on them # is low. - if not market_is_saturated(market=market): + if not market_is_saturated( + market=market + ) and has_question_event_happened_in_the_past( + model=self.model, question=market.question + ): answer = get_known_outcome( model=self.model, question=market.question, diff --git a/prediction_market_agent/agents/known_outcome_agent/known_outcome_agent.py b/prediction_market_agent/agents/known_outcome_agent/known_outcome_agent.py index 983d5bf9..e933e31b 100644 --- a/prediction_market_agent/agents/known_outcome_agent/known_outcome_agent.py +++ b/prediction_market_agent/agents/known_outcome_agent/known_outcome_agent.py @@ -5,6 +5,7 @@ from langchain.prompts import ChatPromptTemplate from langchain_openai import ChatOpenAI +from prediction_market_agent_tooling.tools.utils import utcnow from pydantic import BaseModel from prediction_market_agent.tools.web_scrape.basic_summary import _summary @@ -42,6 +43,22 @@ def has_known_outcome(self) -> bool: return self.result is not Result.UNKNOWN +HAS_QUESTION_HAPPENED_IN_THE_PAST_PROMPT = """ +The current date is {date_str}. Your goal is to assert if a QUESTION references an event that is already finished (according to the current date and time) or if it will still take place in a later date. + +For example, you should return 1 if given the event "Will Bitcoin have reached the price of $100 by 30 March 2023?", since the event ends on a data prior to the current date. + +Your answer MUST be an integer and follow the logic below: +- If the event is already finished, return 1 +- If the event has not yet finished, return 0 +- If you are not sure, return -1 + +Answer with the single 1, 0 or -1 only, and nothing else. + +[QUESTION] +"{question}" +""" + GENERATE_SEARCH_QUERY_PROMPT = """ The current date is {date_str}. You are trying to determine whether the answer to the following question has a definite answer. Generate a web search query @@ -138,6 +155,29 @@ def summarize_if_required(content: str, model: str, question: str) -> str: return content +def has_question_event_happened_in_the_past(model: str, question: str) -> bool: + """Asks the model if the event referenced by the question has finished (given the + current date) (returning 1), if the event has not yet finished (returning 0) or + if it cannot be sure (returning -1).""" + date_str = utcnow().strftime("%Y-%m-%d %H:%M:%S %Z") + llm = ChatOpenAI(model=model, temperature=0.0) + prompt = ChatPromptTemplate.from_template( + template=HAS_QUESTION_HAPPENED_IN_THE_PAST_PROMPT + ).format_messages( + date_str=date_str, + question=question, + ) + answer = str(llm.invoke(prompt).content) + try: + parsed_answer = int(answer) + if parsed_answer == 1: + return True + except Exception as e: + print("Exception occured, cannot assert if title happened in the past. ", e) + + return False + + def get_known_outcome(model: str, question: str, max_tries: int) -> Answer: """ In a loop, perform web search and scrape to find if the answer to the