isa-model 0.3.2__py3-none-any.whl → 0.3.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- isa_model/inference/services/llm/llm_adapter.py +60 -3
- {isa_model-0.3.2.dist-info → isa_model-0.3.4.dist-info}/METADATA +1 -1
- {isa_model-0.3.2.dist-info → isa_model-0.3.4.dist-info}/RECORD +5 -5
- {isa_model-0.3.2.dist-info → isa_model-0.3.4.dist-info}/WHEEL +0 -0
- {isa_model-0.3.2.dist-info → isa_model-0.3.4.dist-info}/top_level.txt +0 -0
@@ -89,6 +89,33 @@ class LangChainMessageAdapter:
|
|
89
89
|
msg_dict["role"] = "user"
|
90
90
|
elif msg.type == "ai":
|
91
91
|
msg_dict["role"] = "assistant"
|
92
|
+
# Handle tool calls if present in LangChain AI messages
|
93
|
+
if hasattr(msg, 'tool_calls') and msg.tool_calls:
|
94
|
+
tool_calls = []
|
95
|
+
for tc in msg.tool_calls:
|
96
|
+
if isinstance(tc, dict):
|
97
|
+
# LangChain format: {"name": "func", "args": {...}, "id": "..."}
|
98
|
+
tool_call = {
|
99
|
+
"id": tc.get("id", f"call_{len(tool_calls)}"),
|
100
|
+
"type": "function",
|
101
|
+
"function": {
|
102
|
+
"name": tc.get("name", "unknown"),
|
103
|
+
"arguments": json.dumps(tc.get("args", {}))
|
104
|
+
}
|
105
|
+
}
|
106
|
+
else:
|
107
|
+
# Handle other tool call formats
|
108
|
+
tool_call = {
|
109
|
+
"id": getattr(tc, 'id', f"call_{len(tool_calls)}"),
|
110
|
+
"type": "function",
|
111
|
+
"function": {
|
112
|
+
"name": getattr(tc, 'name', 'unknown'),
|
113
|
+
"arguments": json.dumps(getattr(tc, 'args', {}))
|
114
|
+
}
|
115
|
+
}
|
116
|
+
tool_calls.append(tool_call)
|
117
|
+
|
118
|
+
msg_dict["tool_calls"] = tool_calls # type: ignore
|
92
119
|
elif msg.type == "tool":
|
93
120
|
msg_dict["role"] = "tool"
|
94
121
|
if hasattr(msg, 'tool_call_id'):
|
@@ -218,6 +245,35 @@ class LangChainToolAdapter:
|
|
218
245
|
return f"Error executing LangChain tool {tool.name}: {str(e)}"
|
219
246
|
|
220
247
|
|
248
|
+
# ============= OpenAI 格式工具适配器 =============
|
249
|
+
|
250
|
+
class DictToolAdapter:
|
251
|
+
"""OpenAI 格式工具字典适配器"""
|
252
|
+
|
253
|
+
def __init__(self):
|
254
|
+
self.adapter_name = "dict_tool"
|
255
|
+
self.priority = 9 # Higher priority than Python functions
|
256
|
+
|
257
|
+
def can_handle(self, tool: Any) -> bool:
|
258
|
+
"""检查是否是 OpenAI 格式的工具字典"""
|
259
|
+
return (isinstance(tool, dict) and
|
260
|
+
tool.get("type") == "function" and
|
261
|
+
"function" in tool and
|
262
|
+
isinstance(tool["function"], dict) and
|
263
|
+
"name" in tool["function"])
|
264
|
+
|
265
|
+
def to_openai_schema(self, tool: Any) -> Dict[str, Any]:
|
266
|
+
"""工具已经是 OpenAI 格式,直接返回"""
|
267
|
+
return tool
|
268
|
+
|
269
|
+
async def execute_tool(self, tool: Any, arguments: Dict[str, Any]) -> Any:
|
270
|
+
"""执行 OpenAI 格式工具(通常需要外部执行器)"""
|
271
|
+
# 对于 OpenAI 格式的工具字典,我们无法直接执行
|
272
|
+
# 这种情况下返回一个指示,让调用方处理
|
273
|
+
tool_name = tool["function"]["name"]
|
274
|
+
return f"Error: Cannot execute dict tool {tool_name} directly. Requires external executor."
|
275
|
+
|
276
|
+
|
221
277
|
# ============= Python 函数适配器 =============
|
222
278
|
|
223
279
|
class PythonFunctionAdapter:
|
@@ -364,10 +420,11 @@ class AdapterManager:
|
|
364
420
|
StandardMessageAdapter() # 回退适配器
|
365
421
|
]
|
366
422
|
|
367
|
-
#
|
423
|
+
# 工具适配器(按优先级排序)
|
368
424
|
self.tool_adapters = [
|
369
|
-
|
370
|
-
|
425
|
+
DictToolAdapter(), # 最高优先级 - OpenAI格式工具
|
426
|
+
LangChainToolAdapter(), # 中等优先级 - LangChain工具
|
427
|
+
PythonFunctionAdapter() # 最低优先级 - Python函数
|
371
428
|
]
|
372
429
|
|
373
430
|
def register_custom_adapter(self, adapter, adapter_type: str):
|
@@ -43,7 +43,7 @@ isa_model/inference/services/embedding/ollama_embed_service.py,sha256=s6LPSh-D06
|
|
43
43
|
isa_model/inference/services/embedding/openai_embed_service.py,sha256=cjAzmYXlY0XLgwemdlhhUVlDecgzFy2xn3DSycoYvdo,8474
|
44
44
|
isa_model/inference/services/llm/__init__.py,sha256=C6t9w33j3Ap4oGcJal9-htifKe0rxwws_kC3F-_B_Ps,341
|
45
45
|
isa_model/inference/services/llm/base_llm_service.py,sha256=SXxFhH2z1UYqt2ihiuursrKEjiiiC3vWCvRQVETsdVc,5238
|
46
|
-
isa_model/inference/services/llm/llm_adapter.py,sha256=
|
46
|
+
isa_model/inference/services/llm/llm_adapter.py,sha256=cxvvBpyhyrDxe9xIuEIjAwElAFkEZmGOWtM_wlyidcg,20159
|
47
47
|
isa_model/inference/services/llm/ollama_llm_service.py,sha256=c5xAdbbicskbxhivIQUse-QiUbCElR_Bo88wIA3dZUI,10194
|
48
48
|
isa_model/inference/services/llm/openai_llm_service.py,sha256=e5GmO4YpVUBImQvQTZ26UwiAmHkU1RPl_vIa1dNe_NM,8148
|
49
49
|
isa_model/inference/services/llm/triton_llm_service.py,sha256=ZFo7JoZ799Nvyi8Cz1jfWOa6TUn0hDRJtBrotadMAd4,17673
|
@@ -85,7 +85,7 @@ isa_model/training/core/config.py,sha256=oqgKpBvtzrN6jwLIQYQ2707lH6nmjrktRiSxp9i
|
|
85
85
|
isa_model/training/core/dataset.py,sha256=XCFsnf0NUMU1dJpdvo_CAMyvXB-9_RCUEiy8TU50e20,7802
|
86
86
|
isa_model/training/core/trainer.py,sha256=h5TjqjdFr0Fsv5y4-0siy1KmOlqLfliVaUXybvuoeXU,26932
|
87
87
|
isa_model/training/core/utils.py,sha256=Nik0M2ssfNbWqP6fKO0Kfyhzr_H6Q19ioxB-qCYbn5E,8387
|
88
|
-
isa_model-0.3.
|
89
|
-
isa_model-0.3.
|
90
|
-
isa_model-0.3.
|
91
|
-
isa_model-0.3.
|
88
|
+
isa_model-0.3.4.dist-info/METADATA,sha256=CDkFSLl4Z0B44AmxdCZBdwP-fNiik5kPu1Vks0iP3bU,12226
|
89
|
+
isa_model-0.3.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
90
|
+
isa_model-0.3.4.dist-info/top_level.txt,sha256=eHSy_Xb3kNkh2kK11mi1mZh0Wz91AQ5b8k2KFYO-rE8,10
|
91
|
+
isa_model-0.3.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|