Refactor project structure "api"

This commit is contained in:
2025-10-09 14:25:58 +02:00
parent 517842c834
commit 07b2588656
35 changed files with 48 additions and 47 deletions

View File

@@ -86,7 +86,7 @@ uv pip install -e .
A questo punto si può già modificare il codice e, quando necessario, far partire il progetto tramite il comando: A questo punto si può già modificare il codice e, quando necessario, far partire il progetto tramite il comando:
```sh ```sh
uv run python src/app uv run src/app
``` ```
# **Applicazione** # **Applicazione**
@@ -106,10 +106,11 @@ src
└── app └── app
├── __main__.py ├── __main__.py
├── agents <-- Agenti, modelli, prompts e simili ├── agents <-- Agenti, modelli, prompts e simili
├── base <-- Classi base per le API ├── api <-- Tutte le API esterne
├── markets <-- Market data provider (Es. Binance) │ ├── base <-- Classi base per le API
├── news <-- News data provider (Es. NewsAPI) │ ├── markets <-- Market data provider (Es. Binance)
├── social <-- Social data provider (Es. Reddit) │ ├── news <-- News data provider (Es. NewsAPI)
│ └── social <-- Social data provider (Es. Reddit)
└── utils <-- Codice di utilità generale └── utils <-- Codice di utilità generale
``` ```

View File

@@ -2,7 +2,7 @@ from agno.run.agent import RunOutput
from app.agents.models import AppModels from app.agents.models import AppModels
from app.agents.team import create_team_with from app.agents.team import create_team_with
from app.agents.predictor import PREDICTOR_INSTRUCTIONS, PredictorInput, PredictorOutput, PredictorStyle from app.agents.predictor import PREDICTOR_INSTRUCTIONS, PredictorInput, PredictorOutput, PredictorStyle
from app.base.markets import ProductInfo from app.api.base.markets import ProductInfo
class Pipeline: class Pipeline:

View File

@@ -1,6 +1,6 @@
from enum import Enum from enum import Enum
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from app.base.markets import ProductInfo from app.api.base.markets import ProductInfo
class PredictorStyle(Enum): class PredictorStyle(Enum):

View File

@@ -1,8 +1,8 @@
from agno.team import Team from agno.team import Team
from app.agents import AppModels from app.agents import AppModels
from app.markets import MarketAPIsTool from app.api.markets import MarketAPIsTool
from app.news import NewsAPIsTool from app.api.news import NewsAPIsTool
from app.social import SocialAPIsTool from app.api.social import SocialAPIsTool
def create_team_with(models: AppModels, coordinator: AppModels | None = None) -> Team: def create_team_with(models: AppModels, coordinator: AppModels | None = None) -> Team:

View File

@@ -1,9 +1,9 @@
from agno.tools import Toolkit from agno.tools import Toolkit
from app.base.markets import MarketWrapper, Price, ProductInfo from app.api.base.markets import MarketWrapper, Price, ProductInfo
from app.markets.binance import BinanceWrapper from app.api.markets.binance import BinanceWrapper
from app.markets.coinbase import CoinBaseWrapper from app.api.markets.coinbase import CoinBaseWrapper
from app.markets.cryptocompare import CryptoCompareWrapper from app.api.markets.cryptocompare import CryptoCompareWrapper
from app.markets.yfinance import YFinanceWrapper from app.api.markets.yfinance import YFinanceWrapper
from app.utils import aggregate_history_prices, aggregate_product_info, WrapperHandler from app.utils import aggregate_history_prices, aggregate_product_info, WrapperHandler
__all__ = [ "MarketAPIsTool", "BinanceWrapper", "CoinBaseWrapper", "CryptoCompareWrapper", "YFinanceWrapper", "ProductInfo", "Price" ] __all__ = [ "MarketAPIsTool", "BinanceWrapper", "CoinBaseWrapper", "CryptoCompareWrapper", "YFinanceWrapper", "ProductInfo", "Price" ]

View File

@@ -1,7 +1,7 @@
import os import os
from typing import Any from typing import Any
from binance.client import Client # type: ignore from binance.client import Client # type: ignore
from app.base.markets import ProductInfo, MarketWrapper, Price from app.api.base.markets import ProductInfo, MarketWrapper, Price
def extract_product(currency: str, ticker_data: dict[str, Any]) -> ProductInfo: def extract_product(currency: str, ticker_data: dict[str, Any]) -> ProductInfo:

View File

@@ -3,7 +3,7 @@ from enum import Enum
from datetime import datetime, timedelta from datetime import datetime, timedelta
from coinbase.rest import RESTClient # type: ignore from coinbase.rest import RESTClient # type: ignore
from coinbase.rest.types.product_types import Candle, GetProductResponse, Product # type: ignore from coinbase.rest.types.product_types import Candle, GetProductResponse, Product # type: ignore
from app.base.markets import ProductInfo, MarketWrapper, Price from app.api.base.markets import ProductInfo, MarketWrapper, Price
def extract_product(product_data: GetProductResponse | Product) -> ProductInfo: def extract_product(product_data: GetProductResponse | Product) -> ProductInfo:

View File

@@ -1,7 +1,7 @@
import os import os
from typing import Any from typing import Any
import requests import requests
from app.base.markets import ProductInfo, MarketWrapper, Price from app.api.base.markets import ProductInfo, MarketWrapper, Price
def extract_product(asset_data: dict[str, Any]) -> ProductInfo: def extract_product(asset_data: dict[str, Any]) -> ProductInfo:

View File

@@ -1,6 +1,6 @@
import json import json
from agno.tools.yfinance import YFinanceTools from agno.tools.yfinance import YFinanceTools
from app.base.markets import MarketWrapper, ProductInfo, Price from app.api.base.markets import MarketWrapper, ProductInfo, Price
def extract_product(stock_data: dict[str, str]) -> ProductInfo: def extract_product(stock_data: dict[str, str]) -> ProductInfo:

View File

@@ -1,10 +1,10 @@
from agno.tools import Toolkit from agno.tools import Toolkit
from app.utils import WrapperHandler from app.utils import WrapperHandler
from app.base.news import NewsWrapper, Article from app.api.base.news import NewsWrapper, Article
from app.news.news_api import NewsApiWrapper from app.api.news.news_api import NewsApiWrapper
from app.news.googlenews import GoogleNewsWrapper from app.api.news.googlenews import GoogleNewsWrapper
from app.news.cryptopanic_api import CryptoPanicWrapper from app.api.news.cryptopanic_api import CryptoPanicWrapper
from app.news.duckduckgo import DuckDuckGoWrapper from app.api.news.duckduckgo import DuckDuckGoWrapper
__all__ = ["NewsAPIsTool", "NewsApiWrapper", "GoogleNewsWrapper", "CryptoPanicWrapper", "DuckDuckGoWrapper", "Article"] __all__ = ["NewsAPIsTool", "NewsApiWrapper", "GoogleNewsWrapper", "CryptoPanicWrapper", "DuckDuckGoWrapper", "Article"]

View File

@@ -2,7 +2,7 @@ import os
from typing import Any from typing import Any
import requests import requests
from enum import Enum from enum import Enum
from app.base.news import NewsWrapper, Article from app.api.base.news import NewsWrapper, Article
class CryptoPanicFilter(Enum): class CryptoPanicFilter(Enum):

View File

@@ -1,7 +1,7 @@
import json import json
from typing import Any from typing import Any
from agno.tools.duckduckgo import DuckDuckGoTools from agno.tools.duckduckgo import DuckDuckGoTools
from app.base.news import Article, NewsWrapper from app.api.base.news import Article, NewsWrapper
def extract_article(result: dict[str, Any]) -> Article: def extract_article(result: dict[str, Any]) -> Article:

View File

@@ -1,6 +1,6 @@
from typing import Any from typing import Any
from gnews import GNews # type: ignore from gnews import GNews # type: ignore
from app.base.news import Article, NewsWrapper from app.api.base.news import Article, NewsWrapper
def extract_article(result: dict[str, Any]) -> Article: def extract_article(result: dict[str, Any]) -> Article:

View File

@@ -1,7 +1,7 @@
import os import os
from typing import Any from typing import Any
import newsapi # type: ignore import newsapi # type: ignore
from app.base.news import Article, NewsWrapper from app.api.base.news import Article, NewsWrapper
def extract_article(result: dict[str, Any]) -> Article: def extract_article(result: dict[str, Any]) -> Article:

View File

@@ -1,7 +1,7 @@
from agno.tools import Toolkit from agno.tools import Toolkit
from app.utils import WrapperHandler from app.utils import WrapperHandler
from app.base.social import SocialPost, SocialWrapper from app.api.base.social import SocialPost, SocialWrapper
from app.social.reddit import RedditWrapper from app.api.social.reddit import RedditWrapper
__all__ = ["SocialAPIsTool", "RedditWrapper", "SocialPost"] __all__ = ["SocialAPIsTool", "RedditWrapper", "SocialPost"]

View File

@@ -1,7 +1,7 @@
import os import os
from praw import Reddit # type: ignore from praw import Reddit # type: ignore
from praw.models import Submission # type: ignore from praw.models import Submission # type: ignore
from app.base.social import SocialWrapper, SocialPost, SocialComment from app.api.base.social import SocialWrapper, SocialPost, SocialComment
MAX_COMMENTS = 5 MAX_COMMENTS = 5

View File

@@ -1,5 +1,5 @@
import statistics import statistics
from app.base.markets import ProductInfo, Price from app.api.base.markets import ProductInfo, Price
def aggregate_history_prices(prices: dict[str, list[Price]]) -> list[Price]: def aggregate_history_prices(prices: dict[str, list[Price]]) -> list[Price]:

View File

@@ -1,7 +1,7 @@
import pytest import pytest
from app.agents import AppModels from app.agents import AppModels
from app.agents.predictor import PREDICTOR_INSTRUCTIONS, PredictorInput, PredictorOutput, PredictorStyle from app.agents.predictor import PREDICTOR_INSTRUCTIONS, PredictorInput, PredictorOutput, PredictorStyle
from app.base.markets import ProductInfo from app.api.base.markets import ProductInfo
def unified_checks(model: AppModels, input: PredictorInput) -> None: def unified_checks(model: AppModels, input: PredictorInput) -> None:
llm = model.get_agent(PREDICTOR_INSTRUCTIONS, output_schema=PredictorOutput) # type: ignore[arg-type] llm = model.get_agent(PREDICTOR_INSTRUCTIONS, output_schema=PredictorOutput) # type: ignore[arg-type]

View File

@@ -1,5 +1,5 @@
import pytest import pytest
from app.markets.binance import BinanceWrapper from app.api.markets.binance import BinanceWrapper
@pytest.mark.market @pytest.mark.market
@pytest.mark.api @pytest.mark.api

View File

@@ -1,6 +1,6 @@
import os import os
import pytest import pytest
from app.markets import CoinBaseWrapper from app.api.markets import CoinBaseWrapper
@pytest.mark.market @pytest.mark.market
@pytest.mark.api @pytest.mark.api

View File

@@ -1,6 +1,6 @@
import os import os
import pytest import pytest
from app.markets import CryptoCompareWrapper from app.api.markets import CryptoCompareWrapper
@pytest.mark.market @pytest.mark.market
@pytest.mark.api @pytest.mark.api

View File

@@ -1,6 +1,6 @@
import os import os
import pytest import pytest
from app.news import CryptoPanicWrapper from app.api.news import CryptoPanicWrapper
@pytest.mark.limited @pytest.mark.limited

View File

@@ -1,5 +1,5 @@
import pytest import pytest
from app.news import DuckDuckGoWrapper from app.api.news import DuckDuckGoWrapper
@pytest.mark.news @pytest.mark.news

View File

@@ -1,5 +1,5 @@
import pytest import pytest
from app.news import GoogleNewsWrapper from app.api.news import GoogleNewsWrapper
@pytest.mark.news @pytest.mark.news

View File

@@ -1,6 +1,6 @@
import os import os
import pytest import pytest
from app.news import NewsApiWrapper from app.api.news import NewsApiWrapper
@pytest.mark.news @pytest.mark.news

View File

@@ -1,6 +1,6 @@
import os import os
import pytest import pytest
from app.social.reddit import MAX_COMMENTS, RedditWrapper from app.api.social.reddit import MAX_COMMENTS, RedditWrapper
@pytest.mark.social @pytest.mark.social
@pytest.mark.api @pytest.mark.api

View File

@@ -1,5 +1,5 @@
import pytest import pytest
from app.markets import YFinanceWrapper from app.api.markets import YFinanceWrapper
@pytest.mark.market @pytest.mark.market
@pytest.mark.api @pytest.mark.api

View File

@@ -1,5 +1,5 @@
import pytest import pytest
from app.markets import MarketAPIsTool from app.api.markets import MarketAPIsTool
@pytest.mark.tools @pytest.mark.tools

View File

@@ -1,5 +1,5 @@
import pytest import pytest
from app.news import NewsAPIsTool from app.api.news import NewsAPIsTool
@pytest.mark.tools @pytest.mark.tools

View File

@@ -1,5 +1,5 @@
import pytest import pytest
from app.social import SocialAPIsTool from app.api.social import SocialAPIsTool
@pytest.mark.tools @pytest.mark.tools
@@ -24,7 +24,7 @@ class TestSocialAPIsTool:
result = tool.wrapper_handler.try_call_all(lambda w: w.get_top_crypto_posts(limit=2)) result = tool.wrapper_handler.try_call_all(lambda w: w.get_top_crypto_posts(limit=2))
assert isinstance(result, dict) assert isinstance(result, dict)
assert len(result.keys()) > 0 assert len(result.keys()) > 0
for provider, posts in result.items(): for _provider, posts in result.items():
for post in posts: for post in posts:
assert post.title is not None assert post.title is not None
assert post.time is not None assert post.time is not None

View File

@@ -1,6 +1,6 @@
import pytest import pytest
from datetime import datetime from datetime import datetime
from app.base.markets import ProductInfo, Price from app.api.base.markets import ProductInfo, Price
from app.utils.market_aggregation import aggregate_history_prices, aggregate_product_info from app.utils.market_aggregation import aggregate_history_prices, aggregate_product_info