Fixed Docker

- Update Dockerfile, docker-compose
- fixed app instructions not working
- fixed json ouput sanification
- added tests for predictor
This commit is contained in:
2025-09-26 12:45:05 +02:00
parent d8ed299724
commit 3e746cdd45
9 changed files with 170 additions and 88 deletions

View File

@@ -0,0 +1,43 @@
import json
import pytest
from app.agents import predictor
from app.models import Models
def unified_checks(model: Models, input):
llm = model.get_agent(predictor.instructions())
result = llm.run(input)
print(result.content)
potential_json = Models.extract_json_str_from_response(result.content)
content = json.loads(potential_json) # Verifica che l'output sia un JSON valido
assert content['strategia'] is not None
assert isinstance(content['portafoglio'], list)
assert abs(sum(item['percentuale'] for item in content['portafoglio']) - 100) < 0.01 # La somma deve essere esattamente 100
class TestPredictor:
@pytest.fixture(scope="class")
def inputs(self):
data = []
for symbol, price in [("BTC", 60000.00), ("ETH", 3500.00), ("SOL", 150.00)]:
product_info = predictor.ProductInfo()
product_info.symbol = symbol
product_info.price = price
data.append(product_info)
return predictor.prepare_inputs(
data=data,
style=predictor.PredictorStyle.AGGRESSIVE,
sentiment="positivo"
)
def test_gemini_model_output(self, inputs):
unified_checks(Models.GEMINI, inputs)
@pytest.mark.slow
def test_ollama_gpt_oss_model_output(self, inputs):
unified_checks(Models.OLLAMA_GPT, inputs)
def test_ollama_qwen_model_output(self, inputs):
unified_checks(Models.OLLAMA_QWEN, inputs)

View File

@@ -30,6 +30,15 @@ def pytest_configure(config):
config.addinivalue_line(
"markers", "cryptocompare: marks tests that require CryptoCompare credentials"
)
config.addinivalue_line(
"markers", "gemini: marks tests that use Gemini model"
)
config.addinivalue_line(
"markers", "ollama_gpt: marks tests that use Ollama GPT model"
)
config.addinivalue_line(
"markers", "ollama_qwen: marks tests that use Ollama Qwen model"
)
def pytest_collection_modifyitems(config, items):
@@ -42,3 +51,10 @@ def pytest_collection_modifyitems(config, items):
# Aggiungi marker 'slow' ai test che potrebbero essere lenti
if "overview" in item.name.lower() or "analysis" in item.name.lower():
item.add_marker(pytest.mark.slow)
if "gemini" in item.name.lower():
item.add_marker(pytest.mark.gemini)
if "ollama_gpt" in item.name.lower():
item.add_marker(pytest.mark.ollama_gpt)
if "ollama_qwen" in item.name.lower():
item.add_marker(pytest.mark.ollama_qwen)