Skip to content

Commit

Permalink
Squash 4 commits into one
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii committed Oct 31, 2024
1 parent 4b3d1c0 commit 5742f8f
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 226 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/python_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

env:
MANIFOLD_API_KEY: ${{ secrets.MANIFOLD_API_KEY }}
SERP_API_KEY: ${{ secrets.SERP_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
BET_FROM_PRIVATE_KEY: ${{ secrets.BET_FROM_PRIVATE_KEY }}
GRAPH_API_KEY: ${{ secrets.GRAPH_API_KEY }}
Expand Down Expand Up @@ -38,7 +37,6 @@ jobs:
- name: Extract environment variables for Docker container
run: |
echo "MANIFOLD_API_KEY=${{ secrets.MANIFOLD_API_KEY }}" >> .env
echo "SERP_API_KEY=${{ secrets.SERP_API_KEY }}" >> .env
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env
echo "BET_FROM_PRIVATE_KEY=${{ secrets.BET_FROM_PRIVATE_KEY }}" >> .env
echo "GRAPH_API_KEY=${{ secrets.GRAPH_API_KEY }}" >> .env
Expand All @@ -58,8 +56,6 @@ jobs:
env:
RUN_PAID_TESTS: "1"
if: github.event_name == 'workflow_dispatch'
# TODO: Remove once the environment variables are fixed in the new repository.
continue-on-error: true

test-build-image:
runs-on: ubuntu-latest
Expand Down
316 changes: 186 additions & 130 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion prediction_market_agent/agents/invalid_agent/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class InvalidAgent(DeployableTraderAgent):

def verify_market(self, market_type: MarketType, market: AgentMarket) -> bool:
if self.have_bet_on_market_since(
market, since=self.same_market_trade_interval.get(market=market)
market, since=self.same_market_trade_interval.get(market)
):
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
get_langfuse_langchain_config,
observe,
)
from prediction_market_agent_tooling.tools.tavily.tavily_search import tavily_search
from prediction_market_agent_tooling.tools.utils import utcnow
from pydantic import BaseModel

from prediction_market_agent.tools.web_scrape.basic_summary import _summary
from prediction_market_agent.tools.web_scrape.markdown import web_scrape
from prediction_market_agent.tools.web_search.tavily import web_search
from prediction_market_agent.utils import APIKeys, completion_str_to_json


Expand Down Expand Up @@ -220,7 +220,7 @@ def get_known_outcome(model: str, question: str, max_tries: int) -> KnownOutcome
).content
).strip('"')
logger.debug(f"Searching web for the search query '{search_query}'")
search_results = web_search(query=search_query, max_results=5)
search_results = tavily_search(query=search_query, max_results=5).results
if not search_results:
raise ValueError("No search results found.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from prediction_market_agent_tooling.tools.betting_strategies.kelly_criterion import (
get_kelly_bet_simplified,
)
from prediction_market_agent_tooling.tools.tavily.tavily_storage import TavilyStorage
from prediction_market_agent_tooling.tools.utils import utcnow

from prediction_market_agent.agents.microchain_agent.utils import (
Expand Down Expand Up @@ -139,7 +138,6 @@ def __call__(self, market_id: str) -> str:
model=self.model,
openai_api_key=self.keys.openai_api_key,
tavily_api_key=self.keys.tavily_api_key,
tavily_storage=TavilyStorage(agent_id=self.__class__.__name__),
)
prediction = prophet_make_prediction(
market_question=question,
Expand Down
6 changes: 0 additions & 6 deletions prediction_market_agent/agents/prophet_agent/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from prediction_market_agent_tooling.loggers import logger
from prediction_market_agent_tooling.markets.agent_market import AgentMarket
from prediction_market_agent_tooling.markets.data_models import ProbabilisticAnswer
from prediction_market_agent_tooling.tools.tavily.tavily_storage import TavilyStorage
from prediction_prophet.benchmark.agents import (
EmbeddingModel,
OlasAgent,
Expand Down Expand Up @@ -53,7 +52,6 @@ def load(self) -> None:
self.agent = PredictionProphetAgent(
model="gpt-4o-2024-08-06",
include_reasoning=True,
tavily_storage=TavilyStorage(agent_id=self.__class__.__name__),
logger=logger,
)

Expand All @@ -74,7 +72,6 @@ def load(self) -> None:
self.agent = PredictionProphetAgent(
model="gpt-4-0125-preview",
include_reasoning=True,
tavily_storage=TavilyStorage(agent_id=self.__class__.__name__),
logger=logger,
)

Expand All @@ -95,7 +92,6 @@ def load(self) -> None:
self.agent = PredictionProphetAgent(
model="gpt-4-turbo-2024-04-09",
include_reasoning=True,
tavily_storage=TavilyStorage(agent_id=self.__class__.__name__),
logger=logger,
)

Expand Down Expand Up @@ -138,7 +134,6 @@ def load(self) -> None:
research_temperature=1.0,
prediction_temperature=1.0,
include_reasoning=True,
tavily_storage=TavilyStorage(agent_id=self.__class__.__name__),
logger=logger,
)

Expand All @@ -162,6 +157,5 @@ def load(self) -> None:
research_temperature=1.0,
prediction_temperature=1.0,
include_reasoning=True,
tavily_storage=TavilyStorage(agent_id=self.__class__.__name__),
logger=logger,
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
)
from prediction_market_agent_tooling.tools.langfuse_ import langfuse_context, observe
from prediction_market_agent_tooling.tools.parallelism import par_generator, par_map
from prediction_market_agent_tooling.tools.tavily.tavily_storage import TavilyStorage
from prediction_market_agent_tooling.tools.utils import (
LLM_SUPER_LOW_TEMPERATURE,
DatetimeUTC,
Expand Down Expand Up @@ -467,9 +466,6 @@ def generate_prediction_for_one_outcome(
model=model,
openai_api_key=api_keys.openai_api_key,
tavily_api_key=api_keys.tavily_api_key,
tavily_storage=TavilyStorage(
agent_id=ThinkThoroughlyWithPredictionProphetResearch.identifier
),
)
prediction = prophet_make_prediction(
market_question=scenario,
Expand Down Expand Up @@ -509,7 +505,6 @@ def generate_final_decision(
model=self.model,
openai_api_key=api_keys.openai_api_key,
tavily_api_key=api_keys.tavily_api_key,
tavily_storage=TavilyStorage(agent_id=self.identifier),
).report
)
return super().generate_final_decision(
Expand Down
3 changes: 0 additions & 3 deletions prediction_market_agent/tools/prediction_prophet/research.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from prediction_market_agent_tooling.loggers import logger
from prediction_market_agent_tooling.tools.tavily.tavily_storage import TavilyStorage
from prediction_prophet.benchmark.agents import ( # noqa: F401 # Just to make it available for the user of research.
_make_prediction as prophet_make_prediction,
)
Expand All @@ -13,7 +12,6 @@ def prophet_research(
model: str,
openai_api_key: SecretStr,
tavily_api_key: SecretStr,
tavily_storage: TavilyStorage | None,
initial_subqueries_limit: int = 20,
subqueries_limit: int = 4,
max_results_per_search: int = 5,
Expand Down Expand Up @@ -41,6 +39,5 @@ def prophet_research(
min_scraped_sites=min_scraped_sites,
openai_api_key=openai_api_key,
tavily_api_key=tavily_api_key,
tavily_storage=tavily_storage,
logger=logger,
)
6 changes: 4 additions & 2 deletions prediction_market_agent/tools/web_scrape/markdown.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from datetime import timedelta

import requests
import tenacity
from bs4 import BeautifulSoup
from markdownify import markdownify
from prediction_market_agent_tooling.loggers import logger
from prediction_market_agent_tooling.tools.cache import persistent_inmemory_cache
from prediction_market_agent_tooling.tools.caches.db_cache import db_cache
from prediction_market_agent_tooling.tools.langfuse_ import observe
from requests import Response


@tenacity.retry(
stop=tenacity.stop_after_attempt(3), wait=tenacity.wait_fixed(1), reraise=True
)
@persistent_inmemory_cache
def fetch_html(url: str, timeout: int) -> Response:
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:107.0) Gecko/20100101 Firefox/107.0"
Expand All @@ -21,6 +22,7 @@ def fetch_html(url: str, timeout: int) -> Response:


@observe()
@db_cache(max_age=timedelta(days=1))
def web_scrape(url: str, timeout: int = 10) -> str:
"""
Taken from agentcoinorg/predictionprophet
Expand Down
24 changes: 5 additions & 19 deletions prediction_market_agent/tools/web_search/google.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import serpapi
from prediction_market_agent_tooling.tools.google import search_google

from prediction_market_agent import utils


def google_search(query: str) -> list[str]:
params = {
"q": query,
"api_key": utils.APIKeys().serp_api_key.get_secret_value(),
"num": 4,
}
search = serpapi.GoogleSearch(params)
urls = [result["link"] for result in search.get_dict()["organic_results"]]
return urls


google_search_schema = {
search_google_schema = {
"type": "function",
"function": {
"name": "google_search",
"name": "search_google",
"parameters": {
"type": "object",
"properties": {
Expand All @@ -35,5 +21,5 @@ def google_search(query: str) -> list[str]:

class GoogleSearchTool:
def __init__(self) -> None:
self.fn = google_search
self.schema = google_search_schema
self.fn = search_google
self.schema = search_google_schema
40 changes: 0 additions & 40 deletions prediction_market_agent/tools/web_search/tavily.py

This file was deleted.

7 changes: 0 additions & 7 deletions prediction_market_agent/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class DBKeys(BaseSettings):

class APIKeys(APIKeysBase):
# Don't get fooled! Serper and Serp are two different services.
SERP_API_KEY: t.Optional[SecretStr] = None
SERPER_API_KEY: t.Optional[SecretStr] = None
OPENAI_API_KEY: t.Optional[SecretStr] = None
REPLICATE_API_KEY: t.Optional[SecretStr] = None
Expand All @@ -33,12 +32,6 @@ class APIKeys(APIKeysBase):
PINATA_API_SECRET: t.Optional[SecretStr] = None
TELEGRAM_BOT_KEY: t.Optional[SecretStr] = None

@property
def serp_api_key(self) -> SecretStr:
return check_not_none(
self.SERP_API_KEY, "SERP_API_KEY missing in the environment."
)

@property
def serper_api_key(self) -> SecretStr:
return check_not_none(
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ numexpr = "*"
pyautogen = "^0.2.32"
flaml = "^2.2.0,<2.3.0" # Bug in newer version, because they started importing xgboost, without requiring it as a dependency.
beautifulsoup4 = "*"
serpapi = "*"
google-search-results = "*"
pytest = "*"
llama-index = "~0.9.0"
Expand All @@ -35,7 +34,7 @@ poetry = "^1.7.1"
poetry-plugin-export = "^1.6.0"
functions-framework = "^3.5.0"
cron-validator = "^1.0.8"
prediction-market-agent-tooling = { version = "^0.55.1", extras = ["langchain", "google"] }
prediction-market-agent-tooling = { version = "^0.56.0.dev112", extras = ["langchain", "google"] }
pydantic-settings = "^2.1.0"
autoflake = "^2.2.1"
isort = "^5.13.2"
Expand All @@ -52,7 +51,7 @@ tweepy = "^4.14.0"
langchain-pinecone = "^0.1.1"
pinatapy-vourhey = "^0.2.0"
plotly = "^5.22.0"
prediction-prophet = { git = "https://github.com/agentcoinorg/predictionprophet.git", branch = "main" }
prediction-prophet = { git = "https://github.com/agentcoinorg/predictionprophet.git", branch = "peter/latest-pmat-cache" }
transformers = "^4.43.3"
openfactverification-kongzii = "^0.2.0"

Expand Down
4 changes: 3 additions & 1 deletion scripts/benchmark_ofv_resolver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pandas as pd
import typer
from prediction_market_agent_tooling.tools.cache import persistent_inmemory_cache
from prediction_market_agent_tooling.tools.caches.inmemory_cache import (
persistent_inmemory_cache,
)

from prediction_market_agent.agents.ofvchallenger_agent.ofv_resolver import (
ofv_answer_binary_question,
Expand Down
4 changes: 3 additions & 1 deletion scripts/llm_randomness.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from langchain.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.tools.cache import persistent_inmemory_cache
from prediction_market_agent_tooling.tools.caches.inmemory_cache import (
persistent_inmemory_cache,
)
from prediction_market_agent_tooling.tools.utils import LLM_SUPER_LOW_TEMPERATURE


Expand Down

0 comments on commit 5742f8f

Please sign in to comment.