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

Implement PredictProbabilityForQuestion function for microchain agent #75

Merged
merged 27 commits into from
Apr 16, 2024

Conversation

evangriffiths
Copy link
Contributor

@evangriffiths evangriffiths commented Apr 12, 2024

Two new Functions for microchain agent:

  • PredictProbabilityForQuestion that calls the mech-client. However, from experimentation this is not very reliable. Currently it fails with timeout ~50% of the time. So while this is being debugged...
  • PredictProbabilityForQuestionLocal that calls the mech function's python directly. This pulls in the mech repo as a git submodule.

Summary by CodeRabbit

  • New Features
    • Introduced new prediction functionalities in the market agent, including local and external tool interactions for enhanced probability predictions.
    • Added a new prediction agent with capabilities to generate research reports and utilize OpenAI models for market analysis.
  • Bug Fixes
    • Increased the number of iterations in the prediction agent's run method for improved output accuracy.
  • Documentation
    • Updated project dependencies and configurations in pyproject.toml and GitHub CI workflows.
  • Refactor
    • Streamlined import statements and removed redundant code across various modules.
  • Chores
    • Updated .gitignore to exclude specific files and added essential libraries to the project setup.

Copy link
Contributor

coderabbitai bot commented Apr 12, 2024

Walkthrough

The latest update brings significant enhancements to the prediction_market_agent project, focusing on integrating external tools for improved probability predictions, managing temporary files, and refining agent functionalities. These changes include the addition of new classes and functions for handling predictions locally and via external interactions, as well as updates to dependencies and configurations to support these new features.

Changes

File(s) Change Summary
.gitignore Added acn_cert.txt to ignore list.
prediction_market_agent/.../functions.py, prediction_market_agent/.../utils.py Enhanced prediction capabilities and added utility functions for file management.
prediction_market_agent/agents/known_outcome_agent/known_outcome_agent.py, prediction_market_agent/utils.py Streamlined imports and centralized JSON handling functionality.
prediction_market_agent/.../prediction_with_research_report.py Introduced advanced prediction functionalities using web-based research.
pyproject.toml Updated dependencies and source configurations.
tests/agents/microchain/test_functions.py Added tests for new prediction functionalities.
.gitmodules, mypy.ini, .github/workflows/python_ci.yaml Configured submodule, type checking exclusions, and CI workflow adjustments to accommodate new changes.
prediction_market_agent/.../microchain_agent.py Increased iterations in the agent.run() method for expanded processing.

Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 55ad3d7 and 59604f8.
Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
Files selected for processing (2)
  • prediction_market_agent/agents/microchain_agent/functions.py (4 hunks)
  • pyproject.toml (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • prediction_market_agent/agents/microchain_agent/functions.py
  • pyproject.toml

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

pyproject.toml Outdated
pydantic-settings = "^2.1.0"
autoflake = "^2.2.1"
isort = "^5.13.2"
markdownify = "^0.11.6"
tavily-python = "^0.3.1"
# TODO remove when PR is merged
microchain-python = {git = "https://github.com/evangriffiths/microchain.git", rev = "evan/token-tracker"}
types-requests = "2.31.0.0"
crewai = {version = "0.11.0", extras = ["tools"]}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

crewai conflict with mech-client deps

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this will also be reverted back to v0.28 once PMAT adds mech-client as dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Latest crewai is also incompatible with mech-client, so either need to downgrade crewai, upgrade the deps of mech-client/its deps, or make our own client!

Copy link
Contributor

Choose a reason for hiding this comment

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

mech-client is super very strictly versioned. if they do this in other repos as well then it's even worse 🙈 I think
it's worth a try to replace these == (exact version) with ^ (any newer version except for the versions with breaking changes).

Maybe there still will be some conflicts but a lot less, at least hopefully.

https://github.com/valory-xyz/mech-client/blob/main/pyproject.toml#L27

Screenshot by Dropbox Capture

Copy link
Contributor Author

@evangriffiths evangriffiths Apr 16, 2024

Choose a reason for hiding this comment

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

Unfortunately doesn't help 😞

The conflicts come from further down the dependency tree

So there's strictness to fix first in https://github.com/valory-xyz/open-aea and then in the mech-client repo

pyproject.toml Outdated Show resolved Hide resolved
def __call__(self, question: str) -> float:
private_key = APIKeys().bet_from_private_key.get_secret_value()
with saved_str_to_tmpfile(private_key) as tmpfile_path:
response = interact(
Copy link
Contributor

Choose a reason for hiding this comment

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

This costs money to run. Should we do some kind of balance check here to see if the agent has enough funds? Otherwise this will throw an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. I don't think there's a way to query the cost of a mech call, so I've hard-coded it here.

I tried playing around with the value here that sets the cost of the mech call, and it fails for anything <0.01xDai, and works for anything >=.

Uploading Screenshot 2024-04-15 at 11.37.29.png…

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

pydantic-settings = "^2.1.0"
autoflake = "^2.2.1"
isort = "^5.13.2"
markdownify = "^0.11.6"
tavily-python = "^0.3.1"
# TODO remove when PR is merged
microchain-python = {git = "https://github.com/evangriffiths/microchain.git", rev = "evan/token-tracker"}
setuptools = "^69.5.1"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Required by mech-client, although not a dependency. Will make a PR against the aea repo, but for now adding here

    from aea.crypto.plugin import load_all_plugins
  File "/Users/evan/dev/prediction-market-agent/.venv/lib/python3.10/site-packages/aea/crypto/plugin.py", line 26, in <module>
    from pkg_resources import EntryPoint, WorkingSet
ModuleNotFoundError: No module named 'pkg_resources'

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

prediction_market_agent/utils.py Show resolved Hide resolved
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

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

@@ -141,26 +140,6 @@ def has_known_result(self) -> bool:
"""


def completion_str_to_json(completion: str) -> dict[str, t.Any]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to prediction_market_agent/utils.py

pyproject.toml Outdated
pydantic-settings = "^2.1.0"
autoflake = "^2.2.1"
isort = "^5.13.2"
markdownify = "^0.11.6"
tavily-python = "^0.3.1"
# TODO remove when PR is merged
microchain-python = {git = "https://github.com/evangriffiths/microchain.git", rev = "evan/token-tracker"}
setuptools = "^69.5.1"
jsonschema = "4.3.3"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here

@evangriffiths evangriffiths changed the title Implement PredictPropabilityForQuestion function for microchain agent Implement PredictProbabilityForQuestion function for microchain agent Apr 16, 2024
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: 2

question = self.market_type.market_class.get_binary_market(
id=market_id
).question
private_key = APIKeys().bet_from_private_key.get_secret_value()
Copy link
Contributor

Choose a reason for hiding this comment

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

Storing private keys temporarily in files can be risky. Consider using more secure methods to handle private keys, such as using environment variables or secure vault solutions.

- uses: ./.github/actions/python_prepare
- name: Run pytest
run: poetry run pytest
run: poetry run pytest tests
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't pick up the tests from inside the mech submodule

"tavily": tavily_api_key,
},
}
response = prediction_with_research_report.run(**kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why **kwargs and not just

 prediction_with_research_report.run(
  tool="prediction-with-research-conservative",
  prompt=question,
  api_keys={
                "openai": openai_api_key,
                "tavily": tavily_api_key,
            },
)

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Une bonne recommandation!

Copy link
Contributor

@kongzii kongzii left a comment

Choose a reason for hiding this comment

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

So because the mech calling over the internet doesn't work very well, this adds it as a submodule and use directly?

@evangriffiths
Copy link
Contributor Author

So because the mech calling over the internet doesn't work very well, this adds it as a submodule and use directly?

Yes, that's right. I have yet to debug why it's unreliable.

@evangriffiths evangriffiths merged commit 2b69016 into main Apr 16, 2024
6 checks passed
@evangriffiths evangriffiths deleted the evan/implement-PredictPropabilityForQuestion branch April 16, 2024 09:59
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.

3 participants