Spaces:
Sleeping
Sleeping
deploy: v35 document-level chunking (DP split + parallel chunks), progress view, Supabase logbook
8debb9c verified | """v35 νμ΄νλΌμΈ(v34 + λ¬Έμ λ¨μ chunk)μ ν μ€νΈ 1건μ μ€ννλ νλ‘κ·Έλλ§€ν± λ¬λ. | |
| κ΅μ΄ λ‘μ§μ μ¬κ΅¬ννμ§ μκ³ solar-eval μμ§μ κ·Έλλ‘ import νλ€ β λ°λͺ¨κ° | |
| 보μ¬μ£Όλ λμμ΄ νκ° run κ³Ό λ°μ΄νΈ λ¨μλ‘ κ°μμΌ νκΈ° λλ¬Έμ΄λ€ (μ¬λ³Έ λ‘μ§μ | |
| λ°λμ κ°λΌμ§λ€). λ‘컬μμλ uv μν¬μ€νμ΄μ€μ solar_eval μ, HF Space μμλ | |
| `build_space.py` κ° λ²€λλ§ν μ¬λ³Έμ μ΄λ€ (sys.path μ μ€ν¬λ¦½νΈ μμ΄ λ¨Όμ λΌ | |
| Space μμλ λ²€λ μ¬λ³Έμ΄ μ΄κΈ΄λ€). | |
| config μμ°(νμ΄νλΌμΈ yamlΒ·ν둬ννΈΒ·μΉν μ¬μ Β·νμ΄νΈλ¦¬μ€νΈ)μ | |
| 1. `./assets/` β HF Space λ μ΄μμ (build_space.py κ° μ‘°λ¦½) | |
| 2. `../03-evaluation/` β λ ν¬ λ μ΄μμ (λ‘컬 κ°λ°) | |
| μμλ‘ μ°Ύλλ€. | |
| """ | |
| from __future__ import annotations | |
| import asyncio | |
| import time | |
| from collections.abc import Callable | |
| from pathlib import Path | |
| from typing import Any | |
| import yaml | |
| PIPELINE_NAME = ( | |
| "pipeline_dev_v35" # = v34 + document_chunking (extends). λ yaml μ΄ λͺ¨λ μμ΄μΌ νλ€ | |
| ) | |
| PROMPT_NAME = "prompt_dev_260825_combo" | |
| DEFAULT_MODEL = "solar-pro4" | |
| # μμ§μ StepCallback κ³Ό κ°μ λͺ¨μ: (event, index, total, step_name, doc_chunk) | |
| StepCallback = Callable[[str, int, int, str, tuple[int, int] | None], None] | |
| def find_config_dir() -> Path: | |
| here = Path(__file__).resolve().parent | |
| for cand in (here / "assets", here.parent / "03-evaluation"): | |
| if (cand / "pipelines" / f"{PIPELINE_NAME}.yaml").is_file(): | |
| return cand | |
| raise FileNotFoundError( | |
| f"config μμ°μ μ°Ύμ μ μμ΅λλ€ β {here}/assets λλ ../03-evaluation μ " | |
| f"pipelines/{PIPELINE_NAME}.yaml μ΄ μμ΄μΌ ν©λλ€ (build_space.py μ°Έμ‘°)." | |
| ) | |
| def build_pipeline() -> Any: | |
| """v35 νμ΄νλΌμΈ μΈμ€ν΄μ€λ₯Ό λ§λ λ€. μ±μμ 1ν λ§λ€μ΄ μ¬μ¬μ©νλ€.""" | |
| import solar_eval.pipelines.steps # noqa: F401 β STEP_REGISTRY λ±λ‘ | |
| from solar_eval.core.dataset_loader import DatasetLoader | |
| from solar_eval.core.pipeline_compose import compose_pipeline | |
| from solar_eval.models.prompt_version import load_step_prompts | |
| from solar_eval.pipelines.registry import create_pipeline | |
| config_dir = find_config_dir() | |
| pipelines_dir = config_dir / "pipelines" | |
| def load_base(name: str) -> dict[str, Any]: | |
| return yaml.safe_load((pipelines_dir / f"{name}.yaml").read_text()) | |
| raw = load_base(PIPELINE_NAME) | |
| composed = compose_pipeline(raw, load_base=load_base) | |
| prompts = load_step_prompts(config_dir / "prompts" / PROMPT_NAME) | |
| return create_pipeline( | |
| "multi_step", | |
| input_fields=["original"], | |
| pipeline_config=composed, | |
| prompts=prompts, | |
| dataset_loader=DatasetLoader(), | |
| config_dir=config_dir, | |
| ) | |
| def step_names(pipeline: Any) -> list[str]: | |
| """UI κ° μ§ν νμλ₯Ό 미리 그릴 μ μκ² μ€ν μ΄λ¦μ μμλλ‘.""" | |
| return [step.name for step in pipeline.steps] | |
| async def _run_async( | |
| pipeline: Any, text: str, model: str, on_step: StepCallback | None | |
| ) -> dict[str, Any]: | |
| from solar_eval.models.sample import EvalSample | |
| from solar_eval.providers.upstage import UpstageProvider | |
| sample = EvalSample(input={"original": text}) | |
| start = time.monotonic() | |
| # νκ° run κ³Ό κ°μ 쑰건: temp 0.0, reasoning off (SP4 κ΅μ²΄μ μ μ½) | |
| result = await pipeline.run( | |
| sample, | |
| prompts="", | |
| provider=UpstageProvider(), | |
| model=model, | |
| temperature=0.0, | |
| max_tokens=8000, | |
| reasoning_effort=None, | |
| on_step=on_step, | |
| ) | |
| elapsed = time.monotonic() - start | |
| return { | |
| "output": result.output, | |
| "step_outputs": result.artifacts.get("step_outputs", {}), | |
| "usage": result.artifacts.get("usage", {}), | |
| "elapsed_s": elapsed, | |
| "pipeline_key": PIPELINE_NAME, | |
| "prompt_key": PROMPT_NAME, | |
| "model": model, | |
| } | |
| def run_proofread( | |
| pipeline: Any, | |
| text: str, | |
| model: str = DEFAULT_MODEL, | |
| on_step: StepCallback | None = None, | |
| ) -> dict[str, Any]: | |
| """ν μ€νΈ 1건 κ΅μ΄. {output, step_outputs, usage, elapsed_s, pipeline_key, prompt_key, model}. | |
| `on_step` μ μ€ν μμ/μ’ λ£μ LLM μ€ν μ bulk μ§νλ§λ€ λΆλ¦°λ€ β UI μ§ν νμμ©. | |
| """ | |
| return asyncio.run(_run_async(pipeline, text, model, on_step)) | |