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 isort and autoflake to CI #29

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/python_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,23 @@ jobs:
- uses: ./.github/actions/python_prepare
- name: Check with black
run: poetry run black --check .

autoflake:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python_prepare
- name: Check with autoflake
run: |
poetry run autoflake --in-place --remove-all-unused-imports --remove-unused-variables --recursive .
git diff --exit-code --quiet || exit 1
Comment on lines +54 to +62
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 15, 2024

Choose a reason for hiding this comment

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

Consider adding a step to install autoflake before running it, unless it's guaranteed to be available in the environment set up by .github/actions/python_prepare. If autoflake is not installed by default, the job will fail due to the missing dependency.

+      - name: Install autoflake
+        run: poetry add --dev autoflake

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
autoflake:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python_prepare
- name: Check with autoflake
run: |
poetry run autoflake --in-place --remove-all-unused-imports --remove-unused-variables --recursive .
git diff --exit-code --quiet || exit 1
autoflake:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python_prepare
- name: Install autoflake
run: poetry add --dev autoflake
- name: Check with autoflake
run: |
poetry run autoflake --in-place --remove-all-unused-imports --remove-unused-variables --recursive .
git diff --exit-code --quiet || exit 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.

autoflake comes pre-installed

Copy link
Contributor

Choose a reason for hiding this comment

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

@evangriffiths: Understood, thank you for clarifying that autoflake comes pre-installed. This ensures the workflow setup is streamlined and efficient. If there's anything else you need, feel free to let me know!


New Learnings Added
User: evangriffiths
PR: gnosis/prediction-market-agent#29
File: .github/workflows/python_ci.yaml:54-62
Timestamp: 2024-02-15T11:28:30.863Z
Learning: `autoflake` comes pre-installed in the environment set up by `.github/actions/python_prepare`.

Note: Learnings are effective only in the context of specific code segments. To apply general coding guidelines, please configure path-based instructions.


isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python_prepare
- name: Check with isort
run: |
poetry run isort --profile black .
git diff --exit-code --quiet || exit 1
Comment on lines +64 to +72
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 15, 2024

Choose a reason for hiding this comment

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

Similar to the autoflake job, ensure isort is installed before attempting to run it. Add a step to install isort if it's not part of the environment prepared by .github/actions/python_prepare.

+      - name: Install isort
+        run: poetry add --dev isort

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
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python_prepare
- name: Check with isort
run: |
poetry run isort --profile black .
git diff --exit-code --quiet || exit 1
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python_prepare
- name: Install isort
run: poetry add --dev isort
- name: Check with isort
run: |
poetry run isort --profile black .
git diff --exit-code --quiet || exit 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.

isort comes pre-installed

Copy link
Contributor

Choose a reason for hiding this comment

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

@evangriffiths: Understood, thank you for clarifying that isort comes pre-installed. It seems no changes are necessary regarding the installation step for isort in the workflow. If there's anything else that needs attention, feel free to let me know.

10 changes: 5 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import typer
import prediction_market_agent as pma
from decimal import Decimal
from prediction_market_agent.agents.all_agents import AgentType, get_agent

import typer
from prediction_market_agent_tooling.markets.markets import (
MarketType,
get_bet_amount,
get_binary_markets,
place_bet,
)

import prediction_market_agent as pma
from prediction_market_agent.agents.all_agents import AgentType, get_agent


def main(
market_type: MarketType = MarketType.MANIFOLD,
Expand All @@ -18,8 +20,6 @@ def main(
"""
Picks one market and answers it, optionally placing a bet.
"""
keys = pma.utils.APIKeys()

# Pick a market
market = get_binary_markets(market_type)[0].to_agent_market()

Expand Down
42 changes: 41 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions prediction_market_agent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
from . import utils
from . import agents
7 changes: 0 additions & 7 deletions prediction_market_agent/agents/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
from . import langchain_agent
from . import autogen_agent
from . import always_yes
from . import llamaindex_agent
from . import metagpt_agent
from . import crewai_agent
from . import custom_agent
11 changes: 6 additions & 5 deletions prediction_market_agent/agents/all_agents.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import typing as t
from enum import Enum

from prediction_market_agent.agents.abstract import AbstractAgent
from prediction_market_agent.agents.langchain_agent import LangChainAgent
from prediction_market_agent.agents.autogen_agent import AutoGenAgent
from prediction_market_agent.agents.always_yes import AlwaysYesAgent
from prediction_market_agent.agents.llamaindex_agent import LlamaIndexAgent
from prediction_market_agent.agents.metagpt_agent import MetaGPTAgent
from prediction_market_agent.agents.autogen_agent import AutoGenAgent
from prediction_market_agent.agents.crewai_agent import CrewAIAgent
from prediction_market_agent.agents.custom_agent import (
CustomAgentOpenAi,
CustomAgentLlama,
CustomAgentOpenAi,
)
from prediction_market_agent.agents.langchain_agent import LangChainAgent
from prediction_market_agent.agents.llamaindex_agent import LlamaIndexAgent
from prediction_market_agent.agents.metagpt_agent import MetaGPTAgent


class AgentType(str, Enum):
Expand Down
3 changes: 2 additions & 1 deletion prediction_market_agent/agents/always_yes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from prediction_market_agent.agents.abstract import AbstractAgent
from prediction_market_agent_tooling.markets.data_models import AgentMarket

from prediction_market_agent.agents.abstract import AbstractAgent


class AlwaysYesAgent(AbstractAgent):
"""
Expand Down
4 changes: 2 additions & 2 deletions prediction_market_agent/agents/autogen_agent.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import autogen
import re
import typing as t

import autogen
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
from prediction_market_agent_tooling.markets.data_models import AgentMarket

from prediction_market_agent import utils
from prediction_market_agent.agents.abstract import AbstractAgent
from prediction_market_agent.tools.google_search import GoogleSearchTool
from prediction_market_agent.tools.web_scrape import WebScrapingTool
from prediction_market_agent_tooling.markets.data_models import AgentMarket


class AutoGenAgent(AbstractAgent):
Expand Down
7 changes: 4 additions & 3 deletions prediction_market_agent/agents/crewai_agent.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
from prediction_market_agent.agents.abstract import AbstractAgent
from prediction_market_agent_tooling.markets.data_models import AgentMarket

from langchain_community.tools import DuckDuckGoSearchRun
from prediction_market_agent_tooling.markets.data_models import AgentMarket

from prediction_market_agent.agents.abstract import AbstractAgent

# TODO can use langchain's @tool decorator on our own tool methods to create a
# tool useable by a crew agent
Expand Down Expand Up @@ -32,7 +33,7 @@ def __init__(self) -> None:
)

def answer_binary_market(self, market: AgentMarket) -> bool:
from crewai import Task, Crew
from crewai import Crew, Task

task1 = Task(
description=(
Expand Down
18 changes: 10 additions & 8 deletions prediction_market_agent/agents/custom_agent.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import json
import requests
from typing import Optional

import requests
from prediction_market_agent_tooling.markets.data_models import AgentMarket
from prediction_market_agent_tooling.tools.utils import (
check_not_none,
should_not_happen,
)

from prediction_market_agent import utils
from prediction_market_agent.agents.abstract import AbstractAgent
from prediction_market_agent.ai_models.abstract_ai_models import (
Message,
AbstractAiChatModel,
Message,
)
from prediction_market_agent.ai_models.llama_ai_models import ChatReplicateLLamaModel
from prediction_market_agent.ai_models.openai_ai_models import ChatOpenAIModel
from prediction_market_agent.tools.google_search import google_search
from prediction_market_agent.tools.tool_exception_handler import tool_exception_handler
from prediction_market_agent.tools.web_scrape_structured import (
web_scrape_structured_and_summarized,
)
from prediction_market_agent.tools.tool_exception_handler import tool_exception_handler
from prediction_market_agent_tooling.tools.utils import (
check_not_none,
should_not_happen,
)
from prediction_market_agent_tooling.markets.data_models import AgentMarket


class CustomAgent(AbstractAgent):
Expand Down
6 changes: 2 additions & 4 deletions prediction_market_agent/agents/langchain_agent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.agents import AgentType
from langchain.agents import AgentType, initialize_agent, load_tools
from langchain_community.llms import OpenAI
from prediction_market_agent_tooling.markets.data_models import AgentMarket

from prediction_market_agent import utils
from prediction_market_agent.agents.abstract import AbstractAgent
from prediction_market_agent_tooling.markets.data_models import AgentMarket


class LangChainAgent(AbstractAgent):
Expand Down
4 changes: 2 additions & 2 deletions prediction_market_agent/agents/llamaindex_agent.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from llama_index.agent import OpenAIAgent
from llama_index.llms import OpenAI
from llama_index.tools import FunctionTool
from prediction_market_agent_tooling.markets.data_models import AgentMarket

from prediction_market_agent import utils
from prediction_market_agent.agents.abstract import AbstractAgent
from prediction_market_agent.tools.google_search import google_search
from prediction_market_agent.tools.web_scrape import web_scrape
from prediction_market_agent import utils
from prediction_market_agent_tooling.markets.data_models import AgentMarket


class LlamaIndexAgent(AbstractAgent):
Expand Down
7 changes: 4 additions & 3 deletions prediction_market_agent/agents/metagpt_agent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import asyncio
import dotenv
import json
import os

from prediction_market_agent.agents.abstract import AbstractAgent
from prediction_market_agent_tooling.tools.utils import check_not_none
import dotenv
from prediction_market_agent_tooling.markets.data_models import AgentMarket
from prediction_market_agent_tooling.tools.utils import check_not_none

from prediction_market_agent.agents.abstract import AbstractAgent


class MetaGPTAgent(AbstractAgent):
Expand Down
1 change: 1 addition & 0 deletions prediction_market_agent/ai_models/abstract_ai_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional

from pydantic import BaseModel


Expand Down
10 changes: 6 additions & 4 deletions prediction_market_agent/ai_models/llama_ai_models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
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,
)
from enum import Enum
from typing import Optional, Literal
from prediction_market_agent_tooling.tools.utils import should_not_happen
import replicate


class LlamaRole(Enum):
Expand Down
12 changes: 7 additions & 5 deletions prediction_market_agent/ai_models/openai_ai_models.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from prediction_market_agent.ai_models.abstract_ai_models import (
AbstractAiChatModel,
Message,
)
from enum import Enum
from typing import Literal, Optional

from openai import OpenAI
from typing import Optional, Literal
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"

Expand Down
24 changes: 10 additions & 14 deletions prediction_market_agent/tools/betting_strategies.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import typing as t
from decimal import Decimal
from functools import reduce
import numpy as np
import typing as t
from web3 import Web3
from prediction_market_agent_tooling.markets.data_models import (
BetAmount,
Currency,
)

import numpy as np
from prediction_market_agent_tooling.gtypes import Probability, wei_type, xDai
from prediction_market_agent_tooling.markets.data_models import BetAmount, Currency
from prediction_market_agent_tooling.markets.markets import MarketType
from prediction_market_agent_tooling.markets.omen import (
omen_calculate_buy_amount,
OmenMarket,
omen_calculate_buy_amount,
)
from prediction_market_agent_tooling.markets.markets import MarketType
from prediction_market_agent_tooling.tools.gnosis_rpc import GNOSIS_RPC_URL
from prediction_market_agent_tooling.tools.utils import check_not_none
from prediction_market_agent_tooling.tools.web3_utils import (
xdai_to_wei,
wei_to_xdai,
ONE_XDAI,
wei_to_xdai,
xdai_to_wei,
)
from prediction_market_agent_tooling.gtypes import Probability, xDai, wei_type
from prediction_market_agent_tooling.tools.utils import check_not_none

from web3 import Web3

OutcomeIndex = t.Literal[0, 1]

Expand Down
3 changes: 1 addition & 2 deletions prediction_market_agent/tools/web_scrape.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import bs4
import requests

from langchain.chains.summarize import load_summarize_chain
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_openai import ChatOpenAI


def _summary(objective: str, content: str) -> str:
Expand Down
1 change: 1 addition & 0 deletions prediction_market_agent/tools/web_scrape_structured.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
from bs4 import BeautifulSoup, Comment, Tag

from prediction_market_agent.tools.web_scrape import _summary


Expand Down
3 changes: 2 additions & 1 deletion prediction_market_agent/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import typing as t

from prediction_market_agent_tooling.config import APIKeys as APIKeysBase
from prediction_market_agent_tooling.tools.utils import (
check_not_none,
should_not_happen,
)
from prediction_market_agent_tooling.config import APIKeys as APIKeysBase


class APIKeys(APIKeysBase):
Expand Down
Loading
Loading