verantyx / axis /axis_core /router.py
kofdai's picture
Upload folder using huggingface_hub
6d07351 verified
# axis_core/router.py
from __future__ import annotations
from dataclasses import dataclass
from enum import Enum
from typing import Dict, Optional
from .util import extract_choice_options, strip_options_from_prompt
class QueryType(str, Enum):
CHOICE = "choice" # 選択問題(複数候補から最適)
DEFINITION = "definition" # 「Xとは」
HOWTO = "howto" # 手順
FORMAL = "formal" # 構成/証明/可逆/∀∃ etc
ADVANCED = "advanced" # 数式/専門長文(理論解説)
GENERAL = "general" # その他
@dataclass
class QueryProfile:
qtype: QueryType
prompt: str
options: Dict[str, str]
raw: str
def detect_query_type(q: str) -> QueryProfile:
raw = (q or "").strip()
options = extract_choice_options(raw)
prompt = strip_options_from_prompt(raw)
# 1) 選択肢が2つ以上 → CHOICE
if len(options) >= 2:
return QueryProfile(QueryType.CHOICE, prompt=prompt, options=options, raw=raw)
# 2) 形式論証トリガ
formal_triggers = ["構成せよ", "論証", "証明", "可逆", "単射", "全射", "同値", "∀", "∃", "必要十分"]
if any(t in raw for t in formal_triggers):
return QueryProfile(QueryType.FORMAL, prompt=prompt, options={}, raw=raw)
# 3) 定義
if raw.endswith("とは") or "とは何" in raw or "定義" in raw:
return QueryProfile(QueryType.DEFINITION, prompt=prompt, options={}, raw=raw)
# 4) howto
howto_triggers = ["やり方", "方法", "手順", "インストール", "設定", "実装", "作り方"]
if any(t in raw for t in howto_triggers):
return QueryProfile(QueryType.HOWTO, prompt=prompt, options={}, raw=raw)
# 5) 高度(数式・専門語の密度でざっくり)
advanced_triggers = ["=", "\\", "Srad", "extremal", "wormhole", "tensor", "complexity", "AdS", "CFT", "island", "Page time"]
if any(t in raw for t in advanced_triggers) or len(raw) > 500:
return QueryProfile(QueryType.ADVANCED, prompt=prompt, options={}, raw=raw)
return QueryProfile(QueryType.GENERAL, prompt=prompt, options={}, raw=raw)