zhouhui.jiang

update

......@@ -13,7 +13,7 @@ API_CONFIG = {
"headers": {
"accept": "*/*",
"Content-Type": "application/json",
"Authorization": os.getenv("API_AUTHORIZATION", "Bearer 2.a0c407306d3f41c884715004a00288b0"),
"Authorization": os.getenv("API_AUTHORIZATION", "Bearer 2.e0f2823597254ee384b0ee4359c9978d"),
"Ver": os.getenv("API_VER", "033BD94B1168D7E4F0D644C3C95E35BF.D73E33B659AD1D6B7D181D1DF8D05760"),
"Referer": os.getenv("API_REFERER", "http://192.168.1.251/")
}
......
......@@ -100,10 +100,10 @@ agent = create_react_agent(
4. **业务咨询**:解答用户关于出口物流流程、运单状态、操作规范等问题
## 工作原则:
- 上传时文件路径不用确认,路径肯定是完整的,文件肯定是存在的,不用确认文件索引,工具会自动设置索引为0,请直接调用工具接口
- 始终以用户需求为导向,提供准确、及时的服务
- 在调用API前,仔细确认用户提供的参数信息
- 对API返回结果进行清晰、易懂的解释
- 上传时文件路径不用确认,是我们后台处理生成的路径
- 如遇到错误,主动分析原因并提供解决方案
- 保持专业、友好的沟通态度
- 严禁改写工具函数返回的文本格式;对工具输出仅直接转述,不得增删前后缀或改写内容。
......@@ -112,7 +112,7 @@ agent = create_react_agent(
## 可用工具:
- query_waybill_list: 查询运单列表,支持按状态筛选,结果以JSON形式展示
- create_waybill_d: 根据运单号创建D类运单,需要提供运单号参数
- upload_clearance_file: 上传清关PDF文件,需要 code、slip_id、pdf_path,上传时文件路径不用确认,是我们后台处理生成的路径
- upload_clearance_file: 上传清关PDF文件,需要 code、slip_id、pdf_path,上传时文件路径不用确认,路径肯定是完整的,文件肯定是存在的,不用确认文件索引,工具会自动设置索引为0,请直接调用工具接口
- push_waybill_for_ocr: 根据运单ID推送OCR进行识别,需要提供运单ID(waybill_id)参数
## query_waybill_list数据展示说明:
......
......@@ -136,9 +136,19 @@ class MessageProcessor:
# 仅当 HumanMessage 且 content 中包含 file 分片时进行处理;否则保持原样
msg_type = m.get("type") if isinstance(m, dict) else m.__class__.__name__
should_process = (msg_type == "HumanMessage") and isinstance(content, list) and any(isinstance(p, dict) and p.get("type") == "file" for p in content)
is_human = (msg_type == "HumanMessage" or msg_type == "human")
should_process_file = is_human and isinstance(content, list) and any(isinstance(p, dict) and p.get("type") == "file" for p in content)
if should_process:
# 检查是否包含 waybill_id(非文件处理)
should_process_waybill = False
if is_human and isinstance(content, list) and not should_process_file:
# 检查 content 中是否有 waybill_id 参数
for part in content:
if isinstance(part, dict) and "waybill_id" in part:
should_process_waybill = True
break
if should_process_file:
# 提取文本与文件路径
text_parts: list[str] = []
file_paths: list[str] = []
......@@ -201,7 +211,9 @@ class MessageProcessor:
merged_text = f"{merged_text} slip_id:{slip_id_value}"
if file_paths:
merged_text = (merged_text + "\n" + "\n".join(file_paths)).strip()
# 将文件路径拼接为 pdf_path:xxx 的格式,多个文件用逗号分隔
pdf_paths_str = ",".join([f"pdf_path:{path}" for path in file_paths])
merged_text = f"{merged_text},{pdf_paths_str}"
# 将保留的参数添加到content字典中,而不是additional_kwargs
new_content_dict = {"type": "text", "text": merged_text}
......@@ -247,6 +259,60 @@ class MessageProcessor:
print(" -> processed")
if preserved_params:
print(f" -> preserved params: {preserved_params}")
elif should_process_waybill:
# 处理包含 waybill_id 的消息
new_content_list = []
for part in content:
if isinstance(part, dict):
if part.get("type") == "text" and "waybill_id" in part:
# 提取文本和 waybill_id
text = part.get("text", "")
waybill_id = part.get("waybill_id")
# 将 waybill_id 拼接到 text 中
waybill_pattern = r'waybill_id[::]\s*\d+'
if re.search(waybill_pattern, text):
# 如果文本中已有 waybill_id:xxx,则替换
text = re.sub(waybill_pattern, f'waybill_id:{waybill_id}', text)
else:
# 否则追加 waybill_id:xxx
text = f"{text} waybill_id:{waybill_id}"
# 创建新的 content 字典,保留 waybill_id 字段
new_part = {
"type": "text",
"text": text,
"waybill_id": waybill_id
}
new_content_list.append(new_part)
else:
# 其他部分保持不变
new_content_list.append(part)
else:
new_content_list.append(part)
# 更新消息
if isinstance(m, dict):
filtered_msg = {**m, "content": new_content_list}
else:
try:
filtered_msg = m.__class__(
content=new_content_list,
additional_kwargs=getattr(m, "additional_kwargs", {}),
response_metadata=getattr(m, "response_metadata", {}),
id=getattr(m, "id", None),
)
except Exception:
filtered_msg = {
"type": m.__class__.__name__,
"role": (role or "user"),
"id": getattr(m, "id", None),
"additional_kwargs": getattr(m, "additional_kwargs", {}),
"response_metadata": getattr(m, "response_metadata", {}),
"content": new_content_list,
}
filtered_messages.append(filtered_msg)
print(f" -> processed waybill_id message")
else:
# 不处理,其它消息保持不变
filtered_messages.append(m)
......