From bac3f00ae46a7984b0e3b07e142f3c97ab7826e7 Mon Sep 17 00:00:00 2001 From: caoxiaozhu Date: Thu, 14 May 2026 09:32:49 +0000 Subject: [PATCH] =?UTF-8?q?feat(server):=20=E6=96=B0=E5=A2=9E=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=97=B6=E8=81=8A=E5=A4=A9=E6=9C=8D=E5=8A=A1=E5=92=8C?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BB=A3=E7=90=86=E6=9C=8D=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=99=BA=E8=83=BD=E5=AF=B9=E8=AF=9D=E5=92=8C?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=A1=8C=E4=B8=BA=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/app/services/runtime_chat.py | 10 ++-- server/src/app/services/user_agent.py | 70 ++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/server/src/app/services/runtime_chat.py b/server/src/app/services/runtime_chat.py index 0e61b1e..3f6694f 100644 --- a/server/src/app/services/runtime_chat.py +++ b/server/src/app/services/runtime_chat.py @@ -27,7 +27,7 @@ class RuntimeChatService: def complete( self, - messages: list[dict[str, str]], + messages: list[dict[str, Any]], *, slot_priority: tuple[str, ...] = ("main", "backup"), max_tokens: int = 500, @@ -91,7 +91,7 @@ class RuntimeChatService: def _request_chat_completion( self, config: dict[str, str], - messages: list[dict[str, str]], + messages: list[dict[str, Any]], *, max_tokens: int, temperature: float, @@ -136,7 +136,7 @@ class RuntimeChatService: endpoint: str, model: str, api_key: str, - messages: list[dict[str, str]], + messages: list[dict[str, Any]], max_tokens: int, temperature: float, ) -> str: @@ -165,7 +165,7 @@ class RuntimeChatService: endpoint: str, model: str, api_key: str, - messages: list[dict[str, str]], + messages: list[dict[str, Any]], max_tokens: int, temperature: float, ) -> str: @@ -197,7 +197,7 @@ class RuntimeChatService: endpoint: str, model: str, api_key: str, - messages: list[dict[str, str]], + messages: list[dict[str, Any]], max_tokens: int, temperature: float, ) -> str: diff --git a/server/src/app/services/user_agent.py b/server/src/app/services/user_agent.py index 2237532..6970e06 100644 --- a/server/src/app/services/user_agent.py +++ b/server/src/app/services/user_agent.py @@ -2124,6 +2124,61 @@ class UserAgentService: item: dict[str, object], payload: UserAgentRequest, ) -> dict[str, str]: + provided_type = str(item.get("document_type") or "").strip().lower() + expense_type_code = self._collect_entity_values(payload).get("expense_type_code", "") + has_customer = bool(self._collect_entity_values(payload).get("customer")) + if provided_type: + if provided_type in {"flight_itinerary", "train_ticket"}: + return { + "document_type": provided_type, + "expense_type": "travel", + "group_code": "travel", + "scene_label": "差旅票据", + } + if provided_type == "hotel_invoice": + return { + "document_type": provided_type, + "expense_type": "hotel", + "group_code": "travel", + "scene_label": "住宿票据", + } + if provided_type in {"taxi_receipt", "parking_toll_receipt"}: + return { + "document_type": provided_type, + "expense_type": "transport", + "group_code": "travel", + "scene_label": "交通票据", + } + if provided_type == "meal_receipt": + group_code = "entertainment" if expense_type_code == "entertainment" or has_customer else "meal" + return { + "document_type": provided_type, + "expense_type": group_code, + "group_code": group_code, + "scene_label": "餐饮票据", + } + if provided_type == "office_invoice": + return { + "document_type": provided_type, + "expense_type": "office", + "group_code": "office", + "scene_label": "办公用品票据", + } + if provided_type == "meeting_invoice": + return { + "document_type": provided_type, + "expense_type": "meeting", + "group_code": "meeting", + "scene_label": "会务票据", + } + if provided_type == "training_invoice": + return { + "document_type": provided_type, + "expense_type": "training", + "group_code": "training", + "scene_label": "培训票据", + } + text = " ".join( [ str(item.get("filename") or ""), @@ -2132,8 +2187,6 @@ class UserAgentService: ] ).lower() compact = text.replace(" ", "") - expense_type_code = self._collect_entity_values(payload).get("expense_type_code", "") - has_customer = bool(self._collect_entity_values(payload).get("customer")) if any(keyword in compact for keyword in ("机票", "航班", "火车", "高铁", "行程单")): return { @@ -2187,6 +2240,19 @@ class UserAgentService: return "other" def _extract_document_fields(self, item: dict[str, object]) -> dict[str, str]: + raw_fields = item.get("document_fields") + if isinstance(raw_fields, list): + normalized_fields: dict[str, str] = {} + for field in raw_fields: + if not isinstance(field, dict): + continue + label = str(field.get("label") or "").strip() + value = str(field.get("value") or "").strip() + if label and value: + normalized_fields[label] = value + if normalized_fields: + return normalized_fields + text = " ".join([str(item.get("summary") or ""), str(item.get("text") or "")]).strip() fields: dict[str, str] = {} amount_match = AMOUNT_TEXT_PATTERN.search(text)