"text-purple-600">import openai
"text-purple-600">from typing "text-purple-600">import List, Dict, Optional
"text-purple-600">from customs_rag "text-purple-600">import CustomsKnowledgeBase
"text-purple-600">class HSClassifierAgent:
"text-purple-600">def __init__("text-orange-600">self, region: str = "CN"):
"""
初始化海关归类Agent
:param region: 归类区域 (CN/US/EU)
"""
"text-orange-600">self.region = region
"text-orange-600">self.kb = CustomsKnowledgeBase(region)
"text-orange-600">self.model = "gpt-4-turbo"
"text-purple-600">async "text-purple-600">def "text-purple-600">classify_product("text-orange-600">self, product_info: Dict) -> Dict:
"""
根据产品信息进行HS归类
"""
# 1. 理解产品信息
product_desc = "text-orange-600">self._format_product_desc(product_info)
# 2. 检索海关判例和归类规则
rag_context = "text-purple-600">await "text-orange-600">self.kb.search(product_desc)
# 3. 生成归类建议
prompt = "text-orange-600">self._build_prompt(product_desc, rag_context)
response = "text-purple-600">await "text-orange-600">self._call_llm(prompt)
"text-purple-600">return "text-orange-600">self._parse_response(response)
"text-purple-600">def _build_prompt("text-orange-600">self, product_desc: str, context: List[str]) -> str:
"text-purple-600">return f"""
作为海关归类专家,请基于以下信息对产品进行{"text-orange-600">self.region}海关归类:
[产品信息]
{product_desc}
[参考判例与规则]
{context}
请提供:
1. 推荐的HS编码(6位或8位)
2. 归类依据(GRI规则引用)
3. 潜在风险提示
"""