generated from kgod/ai-review-template
feat: add resume agent MVP
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import importlib.util
|
||||
import json
|
||||
import sys
|
||||
from dataclasses import replace
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
BACKEND_ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(BACKEND_ROOT))
|
||||
|
||||
from app.llm_services import LLMServiceError, build_services # noqa: E402
|
||||
from app.settings import load_settings # noqa: E402
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Call the configured OpenAI-compatible gateway once."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--text",
|
||||
default="我从2022年3月至今在星河科技有限公司担任产品经理。",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
settings = load_settings()
|
||||
if not settings.openai_api_key:
|
||||
print("OPENAI_API_KEY is empty; configure backend/.env first.", file=sys.stderr)
|
||||
return 2
|
||||
if importlib.util.find_spec("openai") is None:
|
||||
print("OpenAI SDK is not installed; run pip install -r requirements.txt.", file=sys.stderr)
|
||||
return 3
|
||||
|
||||
live_settings = replace(
|
||||
settings,
|
||||
llm_provider="openai",
|
||||
fallback_to_rules=False,
|
||||
)
|
||||
extractor, _rewriter = build_services(live_settings)
|
||||
try:
|
||||
patch = extractor.extract_anchor(
|
||||
args.text,
|
||||
"work_experience",
|
||||
["company", "position", "start_date", "end_date_or_present"],
|
||||
)
|
||||
except LLMServiceError as exc:
|
||||
print(f"Gateway smoke test failed safely: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"ok": True,
|
||||
"base_url": live_settings.openai_base_url,
|
||||
"model": live_settings.openai_model,
|
||||
"structured_output_mode": live_settings.structured_output_mode,
|
||||
"extracted": patch,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
indent=2,
|
||||
)
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user