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

Add streamlit demo for all deployable agents #85

Merged
merged 8 commits into from
Apr 18, 2024
Merged

Conversation

kongzii
Copy link
Contributor

@kongzii kongzii commented Apr 17, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced the Known Outcome Agent with minimum liquidity settings and improved market selection logging.
    • Improved API key management and error handling across various agent functions.
    • Introduced a new Streamlit app for simulating prediction market agents, enhancing user interaction and visualization.
    • Streamlined API key usage in web search functionalities.
  • Refactor

    • Updated import statements for better modularity and clarity in agent scripts.
  • Documentation

    • Improved logging messages across multiple modules to enhance debugging and user feedback.

Copy link
Contributor

coderabbitai bot commented Apr 17, 2024

Walkthrough

The recent updates aim to enhance the prediction market agent software by improving functionality and reliability. Changes include enhanced logging, better error handling, and the integration of API keys for secure interactions with external services. A significant addition is the Streamlit app, providing a user-friendly interface for simulating agent behaviors in prediction markets. These updates streamline operations and enhance the overall user experience.

Changes

File Path Change Summary
mypy.ini Added scripts/ directory to mypy check list.
.../known_outcome_agent/ Updated DeployableKnownOutcomeAgent with min_liquidity attribute for market selection logic. Improved logging with market URLs. Enhanced API key handling and error logging.
.../think_thoroughly_agent/ Updated imports, added detailed logging, and improved error handling.
.../tools/streamlit_utils.py Added functionality to integrate Streamlit with Loguru for logging.
.../tools/web_scrape/basic_summary.py Updated _summary function to include api_key parameter for ChatOpenAI instantiation.
.../tools/web_search/tavily.py Streamlined API key access in web_search function by using APIKeys.
scripts/agent_app.py Introduced a Streamlit app for simulating prediction market agent decisions, including market and agent selection functionalities and simulation of betting decisions.

Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e0685fe and b0b34a4.
Files selected for processing (2)
  • prediction_market_agent/agents/think_thoroughly_agent/deploy.py (2 hunks)
  • scripts/agent_app.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • scripts/agent_app.py
Additional comments not posted (2)
prediction_market_agent/agents/think_thoroughly_agent/deploy.py (2)

30-33: Logging addition approved.

The added logging statement in the pick_markets method enhances transparency by providing detailed information when a market is too saturated to bet on. This is a valuable addition for monitoring and debugging purposes.


27-36: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [36-44]

Method answer_binary_market approved.

The method answer_binary_market is logically sound and properly handles unexpected cases using should_not_happen(). This ensures robustness and reliability in the agent's decision-making process.


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.

# 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 market_is_saturated(market=market):
logger.info(
f"Skipping market {market.id=} {market.question=}, because it is already saturated."
f"Skipping market {market.url} with the question '{market.question}', because it is already saturated."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just trying to make log messages more human friendly

@@ -17,7 +17,8 @@


class DeployableKnownOutcomeAgent(DeployableAgent):
model = "gpt-4-turbo-preview"
model = "gpt-4-1106-preview"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed to change this, see the summarize_if_required function below. Lmk if I did wrong 🙈

Copy link
Contributor

Choose a reason for hiding this comment

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

oops, my bad!



@st.cache_resource
def add_sink_to_logger() -> None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we call this at the top of streamlit application, any logged messages will show in Streamlit

@@ -0,0 +1,100 @@
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is similar to the one in the EVO repository, but here, I used the DeployableAgent class instead of benchmark ones.

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

llm = ChatOpenAI(
temperature=0,
model="gpt-3.5-turbo-0125",
api_key=APIKeys().openai_api_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.

Tip

Codebase Verification

The search results from the rg command provide numerous instances where the APIKeys class is used across various files in the codebase. However, none of these instances include comments or documentation specifically addressing the thread safety of the APIKeys class or its methods, such as get_secret_value().

Given the absence of explicit information on thread safety in the provided context, and considering the typical concerns around thread safety in scenarios involving shared resources (like API keys), it's prudent to recommend further investigation or implementation of thread safety mechanisms if the _summary method is indeed expected to be called concurrently.

Conclusion

The review comment concerning the thread safety of APIKeys().openai_api_key.get_secret_value() in a concurrent environment stands as a valid concern due to the lack of explicit thread safety guarantees in the provided code snippets and usage contexts. It is advisable to ensure that appropriate thread safety measures are implemented if concurrent access is expected.

Analysis chain

Ensure that APIKeys().openai_api_key.get_secret_value() is thread-safe if _summary is expected to be called concurrently.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for any documentation or comments in the codebase regarding thread safety of APIKeys class.
rg "APIKeys" --context 5

Length of output: 31018

"""
PYTHONPATH=. streamlit run scripts/agent_app.py

Tip: if you specify PYTHONPATH=., streamlit will watch for the changes in all files, isntead of just this one.
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct the typo in "instead" in the tip comment.

- isntead
+ instead

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Tip: if you specify PYTHONPATH=., streamlit will watch for the changes in all files, isntead of just this one.
Tip: if you specify PYTHONPATH=., streamlit will watch for the changes in all files, instead of just this one.

@kongzii kongzii merged commit eb01089 into main Apr 18, 2024
6 checks passed
@kongzii kongzii deleted the peter/streamlit branch April 18, 2024 15:27
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