Download core/llm_quant.py from Corin1998/Score: direct link, hf CLI and curl.
- Browser
- Download file 1.76 kB
-
https://huggingface.co/spaces/Corin1998/Score/resolve/main/core/llm_quant.py
- Command line
-
hf download hf://spaces/Corin1998/Score/core/llm_quant.py
-
curl -L -o llm_quant.py https://huggingface.co/spaces/Corin1998/Score/resolve/main/core/llm_quant.py
1.76 kB
| # core/llm_quant.py | |
| from __future__ import annotations | |
| from typing import Dict, Any, Optional | |
| import json | |
| from .openai_client import get_client, TEXT_MODEL | |
| _SYSTEM = """あなたは中立な金融アナリストです。与えられたテキストから | |
| (1) 業界/市場のCAGR(%)、(2) 市場規模(円換算が望ましいが不明ならnull)、 | |
| (3) 主力商品/サービス数、(4) そのうち成長中の数 | |
| を抽出してください。数値は半角。根拠が複数ある場合は最も信頼できる1つを採用し、出所の短い引用も返してください。 | |
| 必ず次のJSONだけを返すこと。""" | |
| _SCHEMA = """ | |
| { | |
| "market": {"cagr_pct": null, "size_jpy": null, "evidence": []}, | |
| "products": {"count": null, "growing_count": null, "notes": null} | |
| } | |
| """ | |
| def extract_market_product_signals(text: str, company_hint: str="") -> Dict[str, Any]: | |
| if not text or len(text.strip()) == 0: | |
| return {"market":{"cagr_pct":None,"size_jpy":None,"evidence":[]}, | |
| "products":{"count":None,"growing_count":None,"notes":None}} | |
| client = get_client() | |
| prompt = f"""{_SCHEMA} | |
| 【会社名の参考】{company_hint or '(記載なし)'} | |
| 【解析対象テキスト(抜粋可)】 | |
| {text[:16000]}""" | |
| resp = client.chat.completions.create( | |
| model=TEXT_MODEL, | |
| messages=[ | |
| {"role":"system","content":_SYSTEM}, | |
| {"role":"user","content":prompt}, | |
| ], | |
| response_format={"type":"json_object"}, | |
| temperature=0.1, | |
| ) | |
| try: | |
| return json.loads(resp.choices[0].message.content) | |
| except Exception: | |
| return {"market":{"cagr_pct":None,"size_jpy":None,"evidence":[]}, | |
| "products":{"count":None,"growing_count":None,"notes":None}} | |