| |
| 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" |
| HOWTO = "howto" |
| FORMAL = "formal" |
| 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) |
|
|
| |
| if len(options) >= 2: |
| return QueryProfile(QueryType.CHOICE, prompt=prompt, options=options, raw=raw) |
|
|
| |
| formal_triggers = ["構成せよ", "論証", "証明", "可逆", "単射", "全射", "同値", "∀", "∃", "必要十分"] |
| if any(t in raw for t in formal_triggers): |
| return QueryProfile(QueryType.FORMAL, prompt=prompt, options={}, raw=raw) |
|
|
| |
| if raw.endswith("とは") or "とは何" in raw or "定義" in raw: |
| return QueryProfile(QueryType.DEFINITION, prompt=prompt, options={}, raw=raw) |
|
|
| |
| howto_triggers = ["やり方", "方法", "手順", "インストール", "設定", "実装", "作り方"] |
| if any(t in raw for t in howto_triggers): |
| return QueryProfile(QueryType.HOWTO, prompt=prompt, options={}, raw=raw) |
|
|
| |
| 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) |