Skip to content
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

Bump PMAT #525

Merged
merged 4 commits into from
Oct 21, 2024
Merged

Bump PMAT #525

merged 4 commits into from
Oct 21, 2024

Conversation

kongzii
Copy link
Contributor

@kongzii kongzii commented Oct 21, 2024

No description provided.

Copy link
Contributor

coderabbitai bot commented Oct 21, 2024

Walkthrough

The pull request introduces several modifications across multiple files in the prediction_market_agent module. Key changes include the restructuring of import statements for TavilyStorage, enhancing error handling in various classes, and the addition of new agent classes in the deploy.py file. The think_thoroughly_agent.py file sees the introduction of new functionalities and methods, particularly focusing on improved error management and scenario generation. Overall, the changes aim to refine code organization and functionality without altering existing logic significantly.

Changes

File Change Summary
prediction_market_agent/agents/microchain_agent/market_functions.py - Updated import path for TavilyStorage.
- Minor adjustment in PredictProbabilityForQuestion.__call__ method for error handling.
- Added account balance checks in BuyTokens and SellTokens classes.
- Enhanced description in GetResolvedBetsWithOutcomes class.
prediction_market_agent/agents/prophet_agent/deploy.py - Updated import path for TavilyStorage.
- Added six new agent classes extending DeployableTraderAgentER, each with specific configurations.
- Error handling added in answer_binary_market method.
prediction_market_agent/agents/think_thoroughly_agent/think_thoroughly_agent.py - Updated import path for TavilyStorage.
- Added TavilySearchResultsThatWillThrow class with _run and _arun methods for error handling.
- Enhanced ThinkThoroughlyBase with new methods for managing scenarios.
- Introduced two subclasses with distinct prediction logic.
prediction_market_agent/tools/prediction_prophet/research.py - Updated import path for TavilyStorage.
- No changes to the prophet_research function's logic or functionality.

Possibly related PRs

Suggested reviewers

  • evangriffiths

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@evangriffiths evangriffiths self-requested a review October 21, 2024 14:02
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (6)
prediction_market_agent/agents/microchain_agent/market_functions.py (1)

Line range hint 380-384: LGTM: Improved clarity in GetResolvedBetsWithOutcomes description

The updated description for the GetResolvedBetsWithOutcomes class now clearly specifies the time frame for looking back at resolved bets. This change enhances clarity for users by providing context for the n_days parameter.

Consider adding a brief explanation of what "resolved bets" means in this context to further improve clarity for users who might be unfamiliar with the term.

prediction_market_agent/agents/prophet_agent/deploy.py (2)

Line range hint 39-46: Refactor duplicate code in the load methods

The load methods in DeployablePredictionProphetGPT4oAgent, DeployablePredictionProphetGPT4TurboPreviewAgent, and DeployablePredictionProphetGPT4TurboFinalAgent contain similar code with minor differences in model names and parameters. To enhance maintainability and reduce code duplication, consider refactoring these methods to utilize a shared helper method or pass parameters to a common constructor.

Here is an example of how you might refactor the code:

class DeployableTraderAgentER(DeployableTraderAgent):
    # ... existing code ...

    def initialize_agent(
        self,
        model_name: str,
        max_bet_amount: int,
        max_price_impact: float | None,
    ) -> None:
        self.agent = PredictionProphetAgent(
            model=model_name,
            include_reasoning=True,
            tavily_storage=TavilyStorage(agent_id=self.__class__.__name__),
            logger=logger,
        )
        self.betting_strategy = KellyBettingStrategy(
            max_bet_amount=max_bet_amount,
            max_price_impact=max_price_impact,
        )

class DeployablePredictionProphetGPT4oAgent(DeployableTraderAgentER):
    bet_on_n_markets_per_run = 20

    def load(self) -> None:
        super().load()
        self.initialize_agent(
            model_name="gpt-4o-2024-08-06",
            max_bet_amount=5,
            max_price_impact=0.7,
        )

# Apply similar changes in the other subclasses

Also applies to: 56-63, 73-80


Line range hint 35-35: Inconsistent setting of bet_on_n_markets_per_run across agents

The bet_on_n_markets_per_run attribute is set to 20 in DeployablePredictionProphetGPT4oAgent but is not defined in other agent classes. To maintain consistency and clarity, consider defining bet_on_n_markets_per_run for all agent subclasses or documenting why it differs among agents.

Also applies to: 51-51, 67-67, 83-83

prediction_market_agent/agents/think_thoroughly_agent/think_thoroughly_agent.py (3)

Line range hint 172-184: Typo in method name: 'get_hypohetical_scenarios' should be 'get_hypothetical_scenarios'

The method name get_hypohetical_scenarios is misspelled. Correcting it to get_hypothetical_scenarios improves code readability and prevents potential confusion.

Apply this diff to correct the method name:

-def get_hypohetical_scenarios(self, question: str) -> Scenarios:
+def get_hypothetical_scenarios(self, question: str) -> Scenarios:

Also, update all references to this method accordingly:

-            hypothetical_scenarios = self.get_hypohetical_scenarios(question)
+            hypothetical_scenarios = self.get_hypothetical_scenarios(question)

Line range hint 469-470: Typographical error in comment: 'pickable' should be 'pickleable'

In the comment, the word 'pickable' should be 'pickleable' to correctly refer to the ability of an object to be serialized using the pickle module.

Apply this diff to fix the typographical error:

-# Needs to be a normal function outside of class, because `lambda` and `self` aren't pickable for processpool executor,
+# Needs to be a normal function outside of class, because `lambda` and `self` aren't pickleable for processpool executor,

Line range hint 410-415: Avoid catching broad exceptions

Catching all exceptions with a bare except Exception can mask unexpected errors and make debugging difficult. It's better to catch specific exceptions that are anticipated.

Specify the exceptions you expect, for example:

-        except Exception as e:
+        except (APIError, HTTPError, SomeSpecificException) as e:

Replace SomeSpecificException with any other specific exception types you expect might occur.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9d772d6 and 9d093d1.

⛔ Files ignored due to path filters (2)
  • poetry.lock is excluded by !**/*.lock, !**/*.lock
  • pyproject.toml is excluded by !**/*.toml
📒 Files selected for processing (4)
  • prediction_market_agent/agents/microchain_agent/market_functions.py (1 hunks)
  • prediction_market_agent/agents/prophet_agent/deploy.py (1 hunks)
  • prediction_market_agent/agents/think_thoroughly_agent/think_thoroughly_agent.py (1 hunks)
  • prediction_market_agent/tools/prediction_prophet/research.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • prediction_market_agent/tools/prediction_prophet/research.py
🧰 Additional context used
🔇 Additional comments (5)
prediction_market_agent/agents/microchain_agent/market_functions.py (4)

19-19: LGTM: Import statement update for TavilyStorage

The change in the import statement for TavilyStorage aligns with similar updates in other files, reflecting a broader restructuring of the module organization. This modification improves code organization and potentially reduces import complexity.


Line range hint 132-133: LGTM: Improved error handling in PredictProbabilityForQuestion

The addition of a check for prediction.outcome_prediction being None and raising a ValueError in such cases is a valuable improvement. This change enhances error handling by ensuring that a failed prediction is explicitly communicated, preventing silent failures and improving the overall robustness of the code.


Line range hint 220-226: LGTM: Enhanced transaction reliability in BuyTokens and SellTokens

The additions to the BuyTokens and SellTokens classes improve the reliability of token transactions:

  1. The account balance check prevents transactions that would fail due to insufficient funds.
  2. The withdraw_wxdai_to_xdai_to_keep_balance call for OMEN markets ensures proper token balance management.

These changes enhance the overall consistency and reliability of token transactions across different market types.

Also applies to: 321-325


Line range hint 1-424: Overall assessment: Improvements in error handling, reliability, and documentation

The changes in this file consistently enhance the code quality through:

  1. Improved error handling in the PredictProbabilityForQuestion class.
  2. Enhanced transaction reliability in the BuyTokens and SellTokens classes.
  3. Better documentation in the GetResolvedBetsWithOutcomes class.
  4. Consistent import restructuring.

These modifications align with best practices and contribute to a more robust and maintainable codebase.

prediction_market_agent/agents/prophet_agent/deploy.py (1)

Line range hint 70-74: Ensure handling of max_price_impact when set to None

In DeployablePredictionProphetGPT4TurboFinalAgent, the get_betting_strategy method sets max_price_impact to None:

def get_betting_strategy(self, market: AgentMarket) -> BettingStrategy:
    return KellyBettingStrategy(max_bet_amount=5, max_price_impact=None)

Please confirm that setting max_price_impact to None is intentional and that the KellyBettingStrategy and any downstream code can handle a None value without causing errors or unintended behavior.

from prediction_market_agent_tooling.tools.tavily_storage.tavily_models import (
TavilyStorage,
)
from prediction_market_agent_tooling.tools.tavily.tavily_storage import TavilyStorage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Invalid Import Path: prediction_market_agent_tooling.tools.tavily.tavily_storage Does Not Exist

The module prediction_market_agent_tooling.tools.tavily.tavily_storage does not exist, and TavilyStorage is not defined within it. Please verify and correct the import path or ensure that the tavily_storage module is created with the appropriate definition of TavilyStorage.

  • File Affected: prediction_market_agent/agents/prophet_agent/deploy.py
🔗 Analysis chain

Verify the updated import path for TavilyStorage

Ensure that the module prediction_market_agent_tooling.tools.tavily.tavily_storage exists and that TavilyStorage is correctly defined within it. This change reflects a module reorganization; verify that all references to TavilyStorage are updated accordingly throughout the codebase.

Run the following script to confirm the existence of TavilyStorage in the new import path:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that TavilyStorage is accessible from the new import path.

# Test: Search for the definition of TavilyStorage in the codebase.
rg -A 5 'class TavilyStorage'

# Expected: Should find the class definition of TavilyStorage in the correct module file.

Length of output: 31


Script:

#!/bin/bash
# Description: Search for any definition of TavilyStorage in the codebase.

ast-grep --pattern $'$_ TavilyStorage($_)' --language python

Length of output: 250


Script:

#!/bin/bash
# Description: Verify the existence of the module path prediction_market_agent_tooling.tools.tavily.tavily_storage.

fd 'tavily_storage.py' .

Length of output: 24


Script:

#!/bin/bash
# Description: Corrected search for any definition of TavilyStorage in the codebase.

ast-grep --pattern $'$_ TavilyStorage($_)' --lang python

Length of output: 500


Script:

#!/bin/bash
# Description: Enhanced search for files related to tavily_storage in the codebase.

fd -i 'tavily_storage' .

Length of output: 24


Script:

#!/bin/bash
# Description: Search for any references to TavilyStorage in the codebase.

rg 'TavilyStorage'

Length of output: 1806


Script:

#!/bin/bash
# Description: List all files in the tavily directory to verify the existence of tavily_storage.py.

ls prediction_market_agent_tooling/tools/tavily/

Length of output: 143


Script:

#!/bin/bash
# Description: Search for any definitions of TavilyStorage (class, function, variable) in the codebase.

rg '^\s*(class|def)\s+TavilyStorage\b' --context 2

Length of output: 52


Script:

#!/bin/bash
# Description: Verify the directory structure for the TavilyStorage import path.

ls prediction_market_agent_tooling/tools/tavily/

Length of output: 143

@kongzii kongzii merged commit 4d888e7 into main Oct 21, 2024
9 checks passed
@kongzii kongzii deleted the peter/bump branch October 21, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants