-
Notifications
You must be signed in to change notification settings - Fork 27
Implement base auto resolver #221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lbeuk
wants to merge
16
commits into
Metaculus:main
Choose a base branch
from
lbeuk:feat/auto-resolver
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
46550cc
Basic skeleton of a forecast resolver
576de9b
Asyncio has been part of the standard library for awhile, removing fr…
40f1246
Updated lock file for removing asyncio
7e0551c
Stashing changes for creating perplexity auto resolver
85149aa
Geting more detailed logs on failure
9465ed8
Pushing a report
09f3fd8
Commiting updates from yesterday
lbeuk c5605b1
Added a tui
lbeuk a9abc1b
Added a comment to __init__.py in the tui to indicate that it should …
lbeuk c8bff86
Merge branch 'main' into feat/auto-resolver
lbeuk 77e77f3
Updates for the weekend, integrated asknews
lbeuk 588340b
Addeding latest report
lbeuk 6154eb2
Added a resolver for annulled/ambiguous specificity, also fixed some …
lbeuk e9dbf00
Final commit for now
lbeuk 77496d3
Merge remote-tracking branch 'origin/main' into feat/auto-resolver
lbeuk 7d426c4
Removing old reports
lbeuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
forecasting_tools/agents_and_tools/auto_resolver/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| from typing import Optional | ||
| import os | ||
| from forecasting_tools.data_models.questions import ( | ||
| BinaryResolution, NumericResolution, DateResolution, MultipleChoiceResolution, ResolutionType | ||
| ) | ||
| from forecasting_tools import ( | ||
| MetaculusQuestion, BinaryQuestion, MultipleChoiceQuestion, | ||
| NumericQuestion, DateQuestion, MetaculusClient | ||
| ) | ||
| from abc import ABC, abstractmethod | ||
|
|
||
| class AutoResolver(ABC): | ||
| """ | ||
| Auto resolvers are provided a metaculus question, and return a resolution if it was able to | ||
| conclusively resolve a question. | ||
|
|
||
| It should be noted that "ambiguous" and "annulled" resolutions | ||
| ARE conclusive (as they are a final resolution). An inconclusive, or null, resolution, means | ||
| that the deciding event or deadline has not occured, or there is presently not enough | ||
| information for the resolver to come to a conclusion. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| async def resolve_question(self, question: MetaculusQuestion) -> Optional[ResolutionType]: | ||
| raise NotImplementedError() | ||
|
|
||
| def get_last_resolution_metadata(self) -> dict | None: | ||
| """ | ||
| Returns metadata from the last resolution attempt, such as chain of thought or key evidence. | ||
|
|
||
| Subclasses should override this to provide additional context about how the resolution | ||
| was determined. | ||
|
|
||
| Returns: | ||
| dict with metadata fields (e.g., 'key_evidence', 'reasoning', etc.) or None | ||
| """ | ||
| return None | ||
|
|
||
| class CommunityForecastResolver(AutoResolver): | ||
| """ | ||
| Checks if the community forecast has reached a consensus. This only works on binary forecasts | ||
| at the minute. | ||
|
|
||
| This should not be used alone, as there can be extremely slim chanced theoretical questions | ||
| (i.e. what is the chance that a meteor hits the earth in the next year) that have not resolved. | ||
|
|
||
| This is also unable to determine if a question should resolve as annulled or ambiguous. | ||
| """ | ||
|
|
||
| def __init__(self, binary_threshold: float = 1, mc_threshold: float = 1): | ||
| self.binary_theshold = binary_threshold | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: |
||
| self.mc_threshold = mc_threshold | ||
|
|
||
| @abstractmethod | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: remove this. |
||
| async def resolve_question(self, question: MetaculusQuestion) -> Optional[ResolutionType]: | ||
| # Update the question | ||
| question = MetaculusClient.get_question_by_post_id(question.id_of_post) | ||
| if isinstance(question, BinaryQuestion): | ||
| return self._resolve_binary_question(question) | ||
| else: | ||
| return NotImplemented | ||
|
|
||
|
|
||
| def _resolve_binary_question(self, question: BinaryQuestion) -> Optional[BinaryResolution]: | ||
| if question.community_prediction_at_access_time is None or type(self.binary_theshold) is not int and type(self.binary_theshold) is not float: | ||
| return None | ||
| if self.binary_theshold + question.community_prediction_at_access_time >= 100: | ||
| return True | ||
| elif question.community_prediction_at_access_time - self.binary_theshold <= 0: | ||
| return False | ||
| else: | ||
| return None | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, is this class actually used anywhere?