add uv and tests

This commit is contained in:
jaehwang committed 2026-10-02 16:24:33 +09:00
1 parent ef05f13958
commit 762a258f88
6 files changed
+882 -19

No files matched your search

+8 -2
View File
@@ -1,6 +1,7 @@
"""structured output 공용 래퍼.
OpenAI 호환 /chat/completions를 쓰는 프로바이더면 base_url만 바꿔 그대로 쓴다.
출력은 항상 한국어로 받는다.
"""
from typing import TypeVar
@@ -9,6 +10,8 @@ from pydantic import BaseModel
T = TypeVar("T", bound=BaseModel)
KOREAN_OUTPUT_RULE = "모든 출력은 한국어로 쓴다."
class StructuredLLM:
def __init__(self, model: str, api_key: str, base_url: str | None = None):
@@ -23,8 +26,11 @@ class StructuredLLM:
system: str | None = None,
temperature: float = 0.0,
) -> T:
messages = [{"role": "system", "content": system}] if system else []
messages.append({"role": "user", "content": prompt})
system_content = f"{system}\n\n{KOREAN_OUTPUT_RULE}" if system else KOREAN_OUTPUT_RULE
messages = [
{"role": "system", "content": system_content},
{"role": "user", "content": prompt},
]
msg = (await self._client.chat.completions.parse(
model=self.model,