fix: preserve species roles through confirmation
This commit is contained in:
@@ -12,7 +12,13 @@ from gfa_core.mas.stage_catalog import (
|
||||
STAGE_INFO as CATALOG_STAGE_INFO,
|
||||
complete_dependencies as catalog_complete_dependencies,
|
||||
)
|
||||
from gfa_core.mas.utils.intent_parser import is_gwas_fmt_intent, parse_gene_family, resolve_gwas_intent, resolve_population_intent
|
||||
from gfa_core.mas.utils.intent_parser import (
|
||||
is_gwas_fmt_intent,
|
||||
parse_gene_family,
|
||||
parse_gene_family_scope_selection,
|
||||
resolve_gwas_intent,
|
||||
resolve_population_intent,
|
||||
)
|
||||
|
||||
|
||||
class IntentAgentV2(BaseAgent):
|
||||
@@ -696,18 +702,68 @@ class IntentAgentV2(BaseAgent):
|
||||
print(f"[IntentAgentV2] Stages expanded: {original_stages} -> {intent_data['stages']}")
|
||||
|
||||
query_lower = query.lower()
|
||||
species_codes = re.findall(r"(?<![A-Za-z0-9])(?:Ft|At|Os|Sl|Zm|Gm|Br|Vv|Pt|Sb|Lc|Dl|Py|Cp|Lg)(?![A-Za-z0-9])", query, flags=re.IGNORECASE)
|
||||
species_map = {code.lower(): code for code in ["Ft", "At", "Os", "Sl", "Zm", "Gm", "Br", "Vv", "Pt", "Sb", "Lc", "Dl", "Py", "Cp", "Lg"]}
|
||||
target_species = []
|
||||
for item in species_codes:
|
||||
sp = species_map.get(item.lower())
|
||||
if sp and sp not in target_species:
|
||||
target_species.append(sp)
|
||||
selection = parse_gene_family_scope_selection(query)
|
||||
params = intent_data.setdefault("params", {})
|
||||
|
||||
def as_species_list(value: Any) -> List[str]:
|
||||
if isinstance(value, str):
|
||||
values = [item.strip() for item in value.split(",")]
|
||||
elif isinstance(value, (list, tuple, set)):
|
||||
values = [str(item).strip() for item in value]
|
||||
else:
|
||||
values = []
|
||||
return list(dict.fromkeys(item for item in values if item))
|
||||
|
||||
target_species = as_species_list(selection.get("targetSpecies"))
|
||||
reference_species = as_species_list(selection.get("referenceSpecies"))
|
||||
comparative_species = as_species_list(selection.get("comparativeSpecies"))
|
||||
has_query_scope = bool(target_species or reference_species or comparative_species)
|
||||
|
||||
prefix_species = provided_prefix.split(".", 1)[0].strip() if provided_prefix and "." in provided_prefix else ""
|
||||
if not target_species and prefix_species:
|
||||
target_species = [prefix_species]
|
||||
if not target_species:
|
||||
target_species = as_species_list(params.get("targetSpecies") or intent_data.get("target_species"))
|
||||
if not reference_species:
|
||||
reference_species = as_species_list(params.get("referenceSpecies") or intent_data.get("reference_species"))
|
||||
if not comparative_species:
|
||||
comparative_species = as_species_list(params.get("comparativeSpecies") or intent_data.get("comparative_species"))
|
||||
if not target_species and not has_query_scope:
|
||||
llm_species = str(intent_data.get("species") or "").strip()
|
||||
if llm_species and llm_species != "Multi":
|
||||
target_species = [llm_species]
|
||||
|
||||
reference_species = [sp for sp in reference_species if sp not in target_species]
|
||||
comparative_species = [
|
||||
sp for sp in comparative_species
|
||||
if sp not in target_species and sp not in reference_species
|
||||
]
|
||||
scope_mode = (
|
||||
"target_plus_reference_plus_comparative"
|
||||
if reference_species and comparative_species
|
||||
else "target_plus_reference"
|
||||
if reference_species
|
||||
else "target_plus_comparative"
|
||||
if comparative_species
|
||||
else "target_only"
|
||||
)
|
||||
|
||||
intent_data["target_species"] = target_species
|
||||
intent_data["reference_species"] = reference_species
|
||||
intent_data["comparative_species"] = comparative_species
|
||||
intent_data["scopeMode"] = scope_mode
|
||||
params.update({
|
||||
"targetSpecies": target_species,
|
||||
"referenceSpecies": reference_species,
|
||||
"comparativeSpecies": comparative_species,
|
||||
"scopeMode": scope_mode,
|
||||
"target_species": target_species,
|
||||
})
|
||||
explicit_species = bool(target_species)
|
||||
if target_species:
|
||||
intent_data["target_species"] = target_species
|
||||
intent_data.setdefault("params", {})["target_species"] = target_species
|
||||
intent_data["species"] = target_species[0] if len(target_species) == 1 else "Multi"
|
||||
elif has_query_scope:
|
||||
intent_data["species"] = ""
|
||||
generic_identify = (
|
||||
"identify" in intent_data.get("stages", [])
|
||||
and not provided_prefix
|
||||
|
||||
Reference in New Issue
Block a user