zhouhui.jiang

update

...@@ -13,7 +13,7 @@ API_CONFIG = { ...@@ -13,7 +13,7 @@ API_CONFIG = {
13 "headers": { 13 "headers": {
14 "accept": "*/*", 14 "accept": "*/*",
15 "Content-Type": "application/json", 15 "Content-Type": "application/json",
16 - "Authorization": os.getenv("API_AUTHORIZATION", "Bearer 2.a0c407306d3f41c884715004a00288b0"), 16 + "Authorization": os.getenv("API_AUTHORIZATION", "Bearer 2.e0f2823597254ee384b0ee4359c9978d"),
17 "Ver": os.getenv("API_VER", "033BD94B1168D7E4F0D644C3C95E35BF.D73E33B659AD1D6B7D181D1DF8D05760"), 17 "Ver": os.getenv("API_VER", "033BD94B1168D7E4F0D644C3C95E35BF.D73E33B659AD1D6B7D181D1DF8D05760"),
18 "Referer": os.getenv("API_REFERER", "http://192.168.1.251/") 18 "Referer": os.getenv("API_REFERER", "http://192.168.1.251/")
19 } 19 }
......
...@@ -100,10 +100,10 @@ agent = create_react_agent( ...@@ -100,10 +100,10 @@ agent = create_react_agent(
100 4. **业务咨询**:解答用户关于出口物流流程、运单状态、操作规范等问题 100 4. **业务咨询**:解答用户关于出口物流流程、运单状态、操作规范等问题
101 101
102 ## 工作原则: 102 ## 工作原则:
103 +- 上传时文件路径不用确认,路径肯定是完整的,文件肯定是存在的,不用确认文件索引,工具会自动设置索引为0,请直接调用工具接口
103 - 始终以用户需求为导向,提供准确、及时的服务 104 - 始终以用户需求为导向,提供准确、及时的服务
104 - 在调用API前,仔细确认用户提供的参数信息 105 - 在调用API前,仔细确认用户提供的参数信息
105 - 对API返回结果进行清晰、易懂的解释 106 - 对API返回结果进行清晰、易懂的解释
106 -- 上传时文件路径不用确认,是我们后台处理生成的路径
107 - 如遇到错误,主动分析原因并提供解决方案 107 - 如遇到错误,主动分析原因并提供解决方案
108 - 保持专业、友好的沟通态度 108 - 保持专业、友好的沟通态度
109 - 严禁改写工具函数返回的文本格式;对工具输出仅直接转述,不得增删前后缀或改写内容。 109 - 严禁改写工具函数返回的文本格式;对工具输出仅直接转述,不得增删前后缀或改写内容。
...@@ -112,7 +112,7 @@ agent = create_react_agent( ...@@ -112,7 +112,7 @@ agent = create_react_agent(
112 ## 可用工具: 112 ## 可用工具:
113 - query_waybill_list: 查询运单列表,支持按状态筛选,结果以JSON形式展示 113 - query_waybill_list: 查询运单列表,支持按状态筛选,结果以JSON形式展示
114 - create_waybill_d: 根据运单号创建D类运单,需要提供运单号参数 114 - create_waybill_d: 根据运单号创建D类运单,需要提供运单号参数
115 -- upload_clearance_file: 上传清关PDF文件,需要 code、slip_id、pdf_path,上传时文件路径不用确认,是我们后台处理生成的路径 115 +- upload_clearance_file: 上传清关PDF文件,需要 code、slip_id、pdf_path,上传时文件路径不用确认,路径肯定是完整的,文件肯定是存在的,不用确认文件索引,工具会自动设置索引为0,请直接调用工具接口
116 - push_waybill_for_ocr: 根据运单ID推送OCR进行识别,需要提供运单ID(waybill_id)参数 116 - push_waybill_for_ocr: 根据运单ID推送OCR进行识别,需要提供运单ID(waybill_id)参数
117 117
118 ## query_waybill_list数据展示说明: 118 ## query_waybill_list数据展示说明:
......
...@@ -136,9 +136,19 @@ class MessageProcessor: ...@@ -136,9 +136,19 @@ class MessageProcessor:
136 136
137 # 仅当 HumanMessage 且 content 中包含 file 分片时进行处理;否则保持原样 137 # 仅当 HumanMessage 且 content 中包含 file 分片时进行处理;否则保持原样
138 msg_type = m.get("type") if isinstance(m, dict) else m.__class__.__name__ 138 msg_type = m.get("type") if isinstance(m, dict) else m.__class__.__name__
139 - should_process = (msg_type == "HumanMessage") and isinstance(content, list) and any(isinstance(p, dict) and p.get("type") == "file" for p in content) 139 + is_human = (msg_type == "HumanMessage" or msg_type == "human")
140 + should_process_file = is_human and isinstance(content, list) and any(isinstance(p, dict) and p.get("type") == "file" for p in content)
141 +
142 + # 检查是否包含 waybill_id(非文件处理)
143 + should_process_waybill = False
144 + if is_human and isinstance(content, list) and not should_process_file:
145 + # 检查 content 中是否有 waybill_id 参数
146 + for part in content:
147 + if isinstance(part, dict) and "waybill_id" in part:
148 + should_process_waybill = True
149 + break
140 150
141 - if should_process: 151 + if should_process_file:
142 # 提取文本与文件路径 152 # 提取文本与文件路径
143 text_parts: list[str] = [] 153 text_parts: list[str] = []
144 file_paths: list[str] = [] 154 file_paths: list[str] = []
...@@ -201,7 +211,9 @@ class MessageProcessor: ...@@ -201,7 +211,9 @@ class MessageProcessor:
201 merged_text = f"{merged_text} slip_id:{slip_id_value}" 211 merged_text = f"{merged_text} slip_id:{slip_id_value}"
202 212
203 if file_paths: 213 if file_paths:
204 - merged_text = (merged_text + "\n" + "\n".join(file_paths)).strip() 214 + # 将文件路径拼接为 pdf_path:xxx 的格式,多个文件用逗号分隔
215 + pdf_paths_str = ",".join([f"pdf_path:{path}" for path in file_paths])
216 + merged_text = f"{merged_text},{pdf_paths_str}"
205 217
206 # 将保留的参数添加到content字典中,而不是additional_kwargs 218 # 将保留的参数添加到content字典中,而不是additional_kwargs
207 new_content_dict = {"type": "text", "text": merged_text} 219 new_content_dict = {"type": "text", "text": merged_text}
...@@ -247,6 +259,60 @@ class MessageProcessor: ...@@ -247,6 +259,60 @@ class MessageProcessor:
247 print(" -> processed") 259 print(" -> processed")
248 if preserved_params: 260 if preserved_params:
249 print(f" -> preserved params: {preserved_params}") 261 print(f" -> preserved params: {preserved_params}")
262 + elif should_process_waybill:
263 + # 处理包含 waybill_id 的消息
264 + new_content_list = []
265 + for part in content:
266 + if isinstance(part, dict):
267 + if part.get("type") == "text" and "waybill_id" in part:
268 + # 提取文本和 waybill_id
269 + text = part.get("text", "")
270 + waybill_id = part.get("waybill_id")
271 +
272 + # 将 waybill_id 拼接到 text 中
273 + waybill_pattern = r'waybill_id[::]\s*\d+'
274 + if re.search(waybill_pattern, text):
275 + # 如果文本中已有 waybill_id:xxx,则替换
276 + text = re.sub(waybill_pattern, f'waybill_id:{waybill_id}', text)
277 + else:
278 + # 否则追加 waybill_id:xxx
279 + text = f"{text} waybill_id:{waybill_id}"
280 +
281 + # 创建新的 content 字典,保留 waybill_id 字段
282 + new_part = {
283 + "type": "text",
284 + "text": text,
285 + "waybill_id": waybill_id
286 + }
287 + new_content_list.append(new_part)
288 + else:
289 + # 其他部分保持不变
290 + new_content_list.append(part)
291 + else:
292 + new_content_list.append(part)
293 +
294 + # 更新消息
295 + if isinstance(m, dict):
296 + filtered_msg = {**m, "content": new_content_list}
297 + else:
298 + try:
299 + filtered_msg = m.__class__(
300 + content=new_content_list,
301 + additional_kwargs=getattr(m, "additional_kwargs", {}),
302 + response_metadata=getattr(m, "response_metadata", {}),
303 + id=getattr(m, "id", None),
304 + )
305 + except Exception:
306 + filtered_msg = {
307 + "type": m.__class__.__name__,
308 + "role": (role or "user"),
309 + "id": getattr(m, "id", None),
310 + "additional_kwargs": getattr(m, "additional_kwargs", {}),
311 + "response_metadata": getattr(m, "response_metadata", {}),
312 + "content": new_content_list,
313 + }
314 + filtered_messages.append(filtered_msg)
315 + print(f" -> processed waybill_id message")
250 else: 316 else:
251 # 不处理,其它消息保持不变 317 # 不处理,其它消息保持不变
252 filtered_messages.append(m) 318 filtered_messages.append(m)
......