diff --git a/poetry.lock b/poetry.lock index 2b1c4aed..156ab007 100644 --- a/poetry.lock +++ b/poetry.lock @@ -6860,13 +6860,13 @@ test = ["coverage", "django", "flake8", "freezegun (==0.3.15)", "mock (>=2.0.0)" [[package]] name = "prediction-market-agent-tooling" -version = "0.56.3" +version = "0.57.0" description = "Tools to benchmark, deploy and monitor prediction market agents." optional = false python-versions = "<3.12,>=3.10" files = [ - {file = "prediction_market_agent_tooling-0.56.3-py3-none-any.whl", hash = "sha256:dd8edc7c12bbc7228a7d4e60599104b1c6a625dbed509eefccf14077b860669c"}, - {file = "prediction_market_agent_tooling-0.56.3.tar.gz", hash = "sha256:ddd119aa72779cf2356ee573c847a0b8b7ed635191e8ae9caad873ea6baef3b5"}, + {file = "prediction_market_agent_tooling-0.57.0-py3-none-any.whl", hash = "sha256:6d9c3129f9e658bc703805c60168efecef8b7b747e928f9e81d87f744f782643"}, + {file = "prediction_market_agent_tooling-0.57.0.tar.gz", hash = "sha256:be9b9cbfbb4c646e60fe1be61ce7a2220d6e50f6e51a3cdde7d53c752615e767"}, ] [package.dependencies] @@ -11106,4 +11106,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "~3.10.0" -content-hash = "4505c4c85ac911308f6e3886e07e224c01ba94ed0bb4beb08d3af34dac06f1e0" +content-hash = "4619718806c0ef63b97367858b245184e85e420f3ab76aa830dcb4fc0ecbf628" diff --git a/prediction_market_agent/agents/social_media_agent/deploy.py b/prediction_market_agent/agents/social_media_agent/deploy.py index 61b86679..d8c6f682 100644 --- a/prediction_market_agent/agents/social_media_agent/deploy.py +++ b/prediction_market_agent/agents/social_media_agent/deploy.py @@ -88,4 +88,4 @@ def post(self, tweet: str | None, reasoning_reply_tweet: str | None) -> None: if __name__ == "__main__": agent = DeployableSocialMediaAgent() - agent.deploy_local(market_type=MarketType.OMEN, sleep_time=540, timeout=180) + agent.deploy_local(market_type=MarketType.OMEN, sleep_time=540, run_time=180) diff --git a/prediction_market_agent/agents/think_thoroughly_agent/deploy.py b/prediction_market_agent/agents/think_thoroughly_agent/deploy.py index b24d4bcc..85fb514c 100644 --- a/prediction_market_agent/agents/think_thoroughly_agent/deploy.py +++ b/prediction_market_agent/agents/think_thoroughly_agent/deploy.py @@ -59,10 +59,10 @@ def get_betting_strategy(self, market: AgentMarket) -> BettingStrategy: if __name__ == "__main__": agent = DeployableThinkThoroughlyAgent( - place_trades=False, store_prediction=False, store_trades=False + place_trades=False, store_predictions=False, store_trades=False ) agent.deploy_local( market_type=MarketType.OMEN, sleep_time=540, - timeout=180, + run_time=180, ) diff --git a/prediction_market_agent/ai_models/abstract_ai_models.py b/prediction_market_agent/ai_models/abstract_ai_models.py deleted file mode 100644 index 82132e54..00000000 --- a/prediction_market_agent/ai_models/abstract_ai_models.py +++ /dev/null @@ -1,16 +0,0 @@ -from typing import Optional - -from pydantic import BaseModel - - -class Message(BaseModel): - role: str - content: str - - -class AbstractAiChatModel: - def complete(self, messages: list[Message]) -> Optional[str]: - """ - Execute the model, and return the completion result as a string. - """ - raise NotImplementedError diff --git a/prediction_market_agent/ai_models/llama_ai_models.py b/prediction_market_agent/ai_models/llama_ai_models.py deleted file mode 100644 index 6f62871e..00000000 --- a/prediction_market_agent/ai_models/llama_ai_models.py +++ /dev/null @@ -1,68 +0,0 @@ -from enum import Enum -from typing import Literal, Optional - -import replicate -from prediction_market_agent_tooling.tools.utils import should_not_happen - -from prediction_market_agent.ai_models.abstract_ai_models import ( - AbstractAiChatModel, - Message, -) - - -class LlamaRole(Enum): - user = "user" - assistant = "assistant" - - -class ChatReplicateLLamaModel(AbstractAiChatModel): - def __init__( - self, - model: Literal["meta/llama-2-70b-chat",] = "meta/llama-2-70b-chat", - system_prompt: Optional[str] = None, - max_tokens: int = 256, - temperature: float = 0.01, - top_p: float = 1.0, - min_new_tokens: int = -1, - ): - self.model = model - self.system_prompt = system_prompt - self.max_tokens = max_tokens - self.temperature = temperature - self.top_p = top_p - self.min_new_tokens = min_new_tokens - - def complete(self, messages: list[Message]) -> Optional[str]: - prompt = construct_llama_prompt(messages) - completion = "".join( - replicate.run( - self.model, - input={ - "prompt": prompt, - "system_prompt": self.system_prompt or "", - "top_p": self.top_p, - "temperature": self.temperature, - "max_new_tokens": self.max_tokens, - "min_new_tokens": self.min_new_tokens, - }, - ) - ) - return completion - - -def construct_llama_prompt(messages: list[Message]) -> str: - """ - Based on https://replicate.com/blog/how-to-prompt-llama. - """ - return "\n".join( - ( - message.content - if message.role == LlamaRole.assistant.value - else ( - f"[INST] {message.content} [/INST]" - if message.role == LlamaRole.user.value - else should_not_happen(f"Invalid role in the message: {message}") - ) - ) - for message in messages - ) diff --git a/prediction_market_agent/ai_models/openai_ai_models.py b/prediction_market_agent/ai_models/openai_ai_models.py deleted file mode 100644 index 5b824185..00000000 --- a/prediction_market_agent/ai_models/openai_ai_models.py +++ /dev/null @@ -1,95 +0,0 @@ -from enum import Enum -from typing import Literal, Optional - -from openai import OpenAI -from openai.types.chat.chat_completion import ChatCompletion -from openai.types.chat.chat_completion_message_param import ( - ChatCompletionMessageParam, - ChatCompletionSystemMessageParam, - ChatCompletionUserMessageParam, -) - -from prediction_market_agent.ai_models.abstract_ai_models import ( - AbstractAiChatModel, - Message, -) - -ROLE_KEY = "role" -CONTENT_KEY = "content" - - -class OpenAiRole(str, Enum): - user = "user" - assistant = "assistant" - system = "system" - - -class ChatOpenAIModel(AbstractAiChatModel): - def __init__( - self, - model: Literal[ - "gpt-4o-2024-08-06", - "gpt-4-1106-preview", - "gpt-4-vision-preview", - "gpt-4", - "gpt-4-0314", - "gpt-4-0613", - "gpt-4-32k", - "gpt-4-32k-0314", - "gpt-4-32k-0613", - "gpt-3.5-turbo", - "gpt-3.5-turbo-16k", - "gpt-3.5-turbo-0301", - "gpt-3.5-turbo-0613", - "gpt-3.5-turbo-1106", - "gpt-3.5-turbo-16k-0613", - ] = "gpt-4o-2024-08-06", - system_prompt: Optional[str] = None, - max_tokens: int = 256, - temperature: float = 0.0, - top_p: float = 1.0, - presence_penalty: float = 0.0, - frequency_penalty: float = 0.0, - api_key: Optional[str] = None, - ): - self.model = model - self.system_prompt = system_prompt - self.max_tokens = max_tokens - self.temperature = temperature - self.top_p = top_p - self.presence_penalty = presence_penalty - self.frequency_penalty = frequency_penalty - self.client = OpenAI(api_key=api_key) - - def complete(self, messages: list[Message]) -> Optional[str]: - messages_formatted: list[ChatCompletionMessageParam] = [] - if self.system_prompt is not None: - messages_formatted.append( - ChatCompletionSystemMessageParam( - role=OpenAiRole.system.value, content=self.system_prompt - ) - ) - for message in messages: - if message.role == OpenAiRole.user.value: - messages_formatted.append( - ChatCompletionUserMessageParam( - role=message.role, content=message.content # type: ignore # This is OK due to the if check. - ) - ) - else: - # TODO: Check `ChatCompletionMessageParam` to support all roles, not just hardcoded system and user. - raise ValueError( - f"Only `user` role is supported at the moment, but got `{message.role}`." - ) - response: ChatCompletion = self.client.chat.completions.create( - model=self.model, - messages=messages_formatted, - n=1, - max_tokens=self.max_tokens, - temperature=self.temperature, - top_p=self.top_p, - presence_penalty=self.presence_penalty, - frequency_penalty=self.frequency_penalty, - ) - completion = response.choices[0].message.content - return completion diff --git a/prediction_market_agent/tools/web_scrape/markdown.py b/prediction_market_agent/tools/web_scrape/markdown.py index e4f5e294..f5ff857e 100644 --- a/prediction_market_agent/tools/web_scrape/markdown.py +++ b/prediction_market_agent/tools/web_scrape/markdown.py @@ -22,7 +22,7 @@ def fetch_html(url: str, timeout: int) -> Response: @observe() -@db_cache(max_age=timedelta(days=1)) +@db_cache(max_age=timedelta(days=1), ignore_args=["timeout"]) def web_scrape(url: str, timeout: int = 10) -> str: """ Taken from agentcoinorg/predictionprophet diff --git a/pyproject.toml b/pyproject.toml index b213fcf9..c96e7d12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,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.56.3", extras = ["langchain", "google"] } +prediction-market-agent-tooling = { version = "^0.57.0", extras = ["langchain", "google"] } pydantic-settings = "^2.1.0" autoflake = "^2.2.1" isort = "^5.13.2" diff --git a/scripts/agent_app.py b/scripts/agent_app.py index 9d609ddf..1a070bd0 100644 --- a/scripts/agent_app.py +++ b/scripts/agent_app.py @@ -79,7 +79,7 @@ def predict( ) -> None: agent = AgentClass( place_trades=False, - store_prediction=False, + store_predictions=False, store_trades=False, enable_langfuse=enable_langfuse, ) diff --git a/tests/ai_models/test_llama_ai_models.py b/tests/ai_models/test_llama_ai_models.py deleted file mode 100644 index 78252279..00000000 --- a/tests/ai_models/test_llama_ai_models.py +++ /dev/null @@ -1,27 +0,0 @@ -from prediction_market_agent.ai_models.llama_ai_models import ( - LlamaRole, - Message, - construct_llama_prompt, -) - - -def test_construct_llama_prompt_0() -> None: - prompt = construct_llama_prompt([]) - assert prompt == "" - - -def test_construct_llama_prompt_1() -> None: - prompt = construct_llama_prompt( - [Message(role=LlamaRole.user.value, content="Hello!")] - ) - assert prompt == "[INST] Hello! [/INST]" - - -def test_construct_llama_prompt_2() -> None: - prompt = construct_llama_prompt( - [ - Message(role=LlamaRole.user.value, content="Hello!"), - Message(role=LlamaRole.assistant.value, content="Bonjour!"), - ] - ) - assert prompt == "[INST] Hello! [/INST]\nBonjour!"