添加ai业务
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""招聘公告信息提取:调用 CONTENT_EXTRACT 模型,输出结构化字典。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from langchain_core.messages import HumanMessage, SystemMessage
|
||||
|
||||
from app.ai.extract.prompt import EXTRACT_SYSTEM_PROMPT
|
||||
from app.ai.model_config import SpiderModel
|
||||
from app.core.logger import log
|
||||
from app.tool.json_helper import parse_llm_json
|
||||
|
||||
|
||||
def extract_announcement(content: str) -> dict | None:
|
||||
"""从公告全文中提取结构化信息。
|
||||
|
||||
Args:
|
||||
content: 公告全文(正文 + 图片 OCR 文字 + 二维码内容拼接)。
|
||||
|
||||
Returns:
|
||||
提取出的字段字典;内容为空、模型调用失败或结果不是字典时返回 None。
|
||||
"""
|
||||
if not content or not content.strip():
|
||||
return None
|
||||
|
||||
messages = [
|
||||
SystemMessage(content=EXTRACT_SYSTEM_PROMPT),
|
||||
HumanMessage(content=content),
|
||||
]
|
||||
|
||||
try:
|
||||
response = SpiderModel.CONTENT_EXTRACT.invoke(messages)
|
||||
except Exception as exc:
|
||||
log.error(f"公告信息提取失败: {exc}")
|
||||
return None
|
||||
|
||||
result = parse_llm_json(str(response.content))
|
||||
if not isinstance(result, dict):
|
||||
log.warning(f"公告信息提取结果不是 JSON 对象: {type(result).__name__}")
|
||||
return None
|
||||
|
||||
log.info(f"公告信息提取完成(字段 {len(result)} 个): {result.get('title')}")
|
||||
return result
|
||||
Reference in New Issue
Block a user