fix: return ToolResponse in qingjian tools for AgentScope compatibility
Some checks failed
Pre-commit / run (ubuntu-latest) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_en (ubuntu-latest, 3.10) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_zh (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.12) (push) Has been cancelled
Some checks failed
Pre-commit / run (ubuntu-latest) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_en (ubuntu-latest, 3.10) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_zh (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.12) (push) Has been cancelled
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from agentscope.tool import ToolResponse
|
||||||
|
|
||||||
from .rules import (
|
from .rules import (
|
||||||
detect_intent,
|
detect_intent,
|
||||||
detect_order_status,
|
detect_order_status,
|
||||||
@@ -12,41 +17,55 @@ from .rules import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def tool_detect_intent(msg: str) -> str:
|
def _tool_ok(value: Any) -> ToolResponse:
|
||||||
|
"""Wrap python values into AgentScope ToolResponse."""
|
||||||
|
try:
|
||||||
|
text = json.dumps(value, ensure_ascii=False)
|
||||||
|
except Exception:
|
||||||
|
text = str(value)
|
||||||
|
return ToolResponse(
|
||||||
|
content=[{"type": "text", "text": text}],
|
||||||
|
metadata={"value": value},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def tool_detect_intent(msg: str) -> ToolResponse:
|
||||||
"""识别客户当前意图: image/pricing/greeting/external_contact/finish_or_quote_trigger/nonsense/unknown。"""
|
"""识别客户当前意图: image/pricing/greeting/external_contact/finish_or_quote_trigger/nonsense/unknown。"""
|
||||||
return detect_intent(msg or "")
|
return _tool_ok(detect_intent(msg or ""))
|
||||||
|
|
||||||
|
|
||||||
def tool_extract_image_urls(msg: str) -> list[str]:
|
def tool_extract_image_urls(msg: str) -> ToolResponse:
|
||||||
"""提取消息中的图片 URL 列表。"""
|
"""提取消息中的图片 URL 列表。"""
|
||||||
return extract_image_urls(msg or "")
|
return _tool_ok(extract_image_urls(msg or ""))
|
||||||
|
|
||||||
|
|
||||||
def tool_detect_order_status(goods_order: str) -> str:
|
def tool_detect_order_status(goods_order: str) -> ToolResponse:
|
||||||
"""识别订单状态: paid/pending_payment/refund/unknown。"""
|
"""识别订单状态: paid/pending_payment/refund/unknown。"""
|
||||||
return detect_order_status(goods_order or "")
|
return _tool_ok(detect_order_status(goods_order or ""))
|
||||||
|
|
||||||
|
|
||||||
def tool_extract_size_pairs(msg: str) -> list[tuple[float, float]]:
|
def tool_extract_size_pairs(msg: str) -> ToolResponse:
|
||||||
"""提取尺寸对,单位米。返回 [(w, h), ...]。"""
|
"""提取尺寸对,单位米。返回 [(w, h), ...]。"""
|
||||||
return extract_size_pairs_m(msg or "")
|
return _tool_ok(extract_size_pairs_m(msg or ""))
|
||||||
|
|
||||||
|
|
||||||
def tool_detect_risk(msg: str, goods_name: str = "") -> dict:
|
def tool_detect_risk(msg: str, goods_name: str = "") -> ToolResponse:
|
||||||
"""检测风险:地图政治、黄暴。"""
|
"""检测风险:地图政治、黄暴。"""
|
||||||
text = msg or ""
|
text = msg or ""
|
||||||
gname = goods_name or ""
|
gname = goods_name or ""
|
||||||
return {
|
return _tool_ok(
|
||||||
"map_or_political": has_map_or_political_risk(text, gname),
|
{
|
||||||
"porn": has_porn_risk(text),
|
"map_or_political": has_map_or_political_risk(text, gname),
|
||||||
}
|
"porn": has_porn_risk(text),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def tool_detect_external_contact(msg: str) -> bool:
|
def tool_detect_external_contact(msg: str) -> ToolResponse:
|
||||||
"""检测是否索要外部联系方式(微信/QQ/手机号等)。"""
|
"""检测是否索要外部联系方式(微信/QQ/手机号等)。"""
|
||||||
return requests_external_contact(msg or "")
|
return _tool_ok(requests_external_contact(msg or ""))
|
||||||
|
|
||||||
|
|
||||||
def tool_is_meaningless_short(msg: str) -> bool:
|
def tool_is_meaningless_short(msg: str) -> ToolResponse:
|
||||||
"""检测是否无意义短句(嗯/哦/ok等)。"""
|
"""检测是否无意义短句(嗯/哦/ok等)。"""
|
||||||
return is_meaningless_short(msg or "")
|
return _tool_ok(is_meaningless_short(msg or ""))
|
||||||
|
|||||||
Reference in New Issue
Block a user