From 9513ab09326e08e7846571c675b699f60decc32c Mon Sep 17 00:00:00 2001 From: Berack96 Date: Mon, 20 Oct 2025 10:16:23 +0200 Subject: [PATCH] QueryOutputs per riflettere il campo is_crypto; aggiunto test per la verifica delle query crypto --- src/app/agents/core.py | 2 +- src/app/agents/pipeline.py | 2 +- src/app/agents/prompts/query_check.txt | 1 + tests/agents/test_query_check.py | 48 ++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/agents/test_query_check.py diff --git a/src/app/agents/core.py b/src/app/agents/core.py index b3df55e..3086f81 100644 --- a/src/app/agents/core.py +++ b/src/app/agents/core.py @@ -9,7 +9,7 @@ class QueryInputs(BaseModel): class QueryOutputs(BaseModel): response: str - is_ok: bool + is_crypto: bool diff --git a/src/app/agents/pipeline.py b/src/app/agents/pipeline.py index eb4abab..f73b211 100644 --- a/src/app/agents/pipeline.py +++ b/src/app/agents/pipeline.py @@ -108,7 +108,7 @@ class Pipeline: # Step 2: Crea gli steps def condition_query_ok(step_input: StepInput) -> StepOutput: val = step_input.previous_step_content - return StepOutput(stop=not val.is_ok) if isinstance(val, QueryOutputs) else StepOutput(stop=True) + return StepOutput(stop=not val.is_crypto) if isinstance(val, QueryOutputs) else StepOutput(stop=True) query_check = Step(name=PipelineEvent.QUERY_CHECK, agent=q_check_agent) info_recovery = Step(name=PipelineEvent.INFO_RECOVERY, team=team) diff --git a/src/app/agents/prompts/query_check.txt b/src/app/agents/prompts/query_check.txt index 7767eae..903cb54 100644 --- a/src/app/agents/prompts/query_check.txt +++ b/src/app/agents/prompts/query_check.txt @@ -3,6 +3,7 @@ GOAL: check if the query is crypto-related 1) Determine the language of the query: - This will help you understand better the intention of the user - Focus on the query of the user + - DO NOT answer the query 2) Determine if the query is crypto or investment-related: - Crypto-related if it mentions cryptocurrencies, tokens, NFTs, blockchain, exchanges, wallets, DeFi, oracles, smart contracts, on-chain, off-chain, staking, yield, liquidity, tokenomics, coins, ticker symbols, etc. diff --git a/tests/agents/test_query_check.py b/tests/agents/test_query_check.py new file mode 100644 index 0000000..132c9be --- /dev/null +++ b/tests/agents/test_query_check.py @@ -0,0 +1,48 @@ +import pytest +from app.agents.core import QueryOutputs +from app.agents.prompts import QUERY_CHECK_INSTRUCTIONS +from app.configs import AppConfig + + +class TestQueryCheckAgent: + @pytest.fixture(autouse=True) + def setup(self): + self.configs = AppConfig.load() + self.model = self.configs.get_model_by_name("qwen3:1.7b") + self.agent = self.model.get_agent(QUERY_CHECK_INSTRUCTIONS, output_schema=QueryOutputs) + + def test_query_not_ok(self): + response = self.agent.run("Is the sky blue?") #type: ignore + assert response is not None + assert response.content is not None + content = response.content + assert isinstance(content, QueryOutputs) + assert content.is_crypto == False + + def test_query_not_ok2(self): + response = self.agent.run("What is the capital of France?") #type: ignore + assert response is not None + assert response.content is not None + content = response.content + assert isinstance(content, QueryOutputs) + assert content.is_crypto == False + + def test_query_ok(self): + response = self.agent.run("Bitcoin") #type: ignore + assert response is not None + assert response.content is not None + content = response.content + assert isinstance(content, QueryOutputs) + assert content.is_crypto == True + + def test_query_ok2(self): + response = self.agent.run("Ha senso investire in Etherium?") #type: ignore + assert response is not None + assert response.content is not None + content = response.content + assert isinstance(content, QueryOutputs) + assert content.is_crypto == True + + + +