Skip to content

Commit

Permalink
Merge pull request #32 from gnosis/evan/tidy
Browse files Browse the repository at this point in the history
Update PMAT version and remove broken tests
  • Loading branch information
evangriffiths authored Mar 18, 2024
2 parents a337485 + 46d0dda commit 5c9fa13
Show file tree
Hide file tree
Showing 9 changed files with 867 additions and 1,131 deletions.
10 changes: 5 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from decimal import Decimal

import typer
from prediction_market_agent_tooling.markets.markets import (
MarketType,
get_binary_markets,
)
from prediction_market_agent_tooling.markets.agent_market import SortBy
from prediction_market_agent_tooling.markets.markets import MARKET_TYPE_MAP, MarketType
from prediction_market_agent_tooling.tools.utils import check_not_none

import prediction_market_agent as pma
from prediction_market_agent.agents.all_agents import AgentType, get_agent
Expand All @@ -19,7 +18,8 @@ def main(
Picks one market and answers it, optionally placing a bet.
"""
# Pick a market
market = get_binary_markets(market_type)[0]
cls = check_not_none(MARKET_TYPE_MAP.get(market_type))
market = cls.get_binary_markets(limit=1, sort_by=SortBy.NEWEST)[0]

# Create the agent and run it
agent = get_agent(agent_type)
Expand Down
1,646 changes: 842 additions & 804 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion prediction_market_agent/agents/autogen_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_base_llm_config(self) -> dict[str, t.Any]:
"config_list": [
{
"model": "gpt-4",
"api_key": keys.openai_api_key,
"api_key": keys.openai_api_key.get_secret_value(),
}
],
"temperature": 0,
Expand Down
10 changes: 8 additions & 2 deletions prediction_market_agent/agents/langchain_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
class LangChainAgent(AbstractAgent):
def __init__(self, llm: Optional[BaseLLM] = None) -> None:
keys = utils.APIKeys()
llm = OpenAI(openai_api_key=keys.openai_api_key) if not llm else llm
llm = (
OpenAI(openai_api_key=keys.openai_api_key.get_secret_value())
if not llm
else llm
)
# Can use pre-defined search tool
# TODO: Tavily tool could give better results
# https://docs.tavily.com/docs/tavily-api/langchain
tools = load_tools(
["serpapi", "llm-math"], llm=llm, serpapi_api_key=keys.serp_api_key
["serpapi", "llm-math"],
llm=llm,
serpapi_api_key=keys.serp_api_key.get_secret_value(),
)
self._agent = initialize_agent(
tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
Expand Down
231 changes: 0 additions & 231 deletions prediction_market_agent/tools/betting_strategies.py

This file was deleted.

6 changes: 5 additions & 1 deletion prediction_market_agent/tools/google_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@


def google_search(query: str) -> list[str]:
params = {"q": query, "api_key": utils.APIKeys().serp_api_key, "num": 4}
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
Expand Down
9 changes: 5 additions & 4 deletions prediction_market_agent/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
check_not_none,
should_not_happen,
)
from pydantic import SecretStr


class APIKeys(APIKeysBase):
SERP_API_KEY: t.Optional[str] = None
OPENAI_API_KEY: t.Optional[str] = None
SERP_API_KEY: t.Optional[SecretStr] = None
OPENAI_API_KEY: t.Optional[SecretStr] = None

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

@property
def openai_api_key(self) -> str:
def openai_api_key(self) -> SecretStr:
return check_not_none(
self.OPENAI_API_KEY, "OPENAI_API_KEY missing in the environment."
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 = "0.2.6"
prediction-market-agent-tooling = "^0.5.0"
pydantic-settings = "^2.1.0"
autoflake = "^2.2.1"
isort = "^5.13.2"
Expand Down
Loading

0 comments on commit 5c9fa13

Please sign in to comment.