gomyck-tools 1.3.6__py3-none-any.whl → 1.3.7__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.
- ctools/ai/llm_chat.py +2 -0
- ctools/ai/tools/tool_use_xml_parse.py +14 -7
- ctools/aio_web_server.py +16 -4
- {gomyck_tools-1.3.6.dist-info → gomyck_tools-1.3.7.dist-info}/METADATA +1 -1
- {gomyck_tools-1.3.6.dist-info → gomyck_tools-1.3.7.dist-info}/RECORD +8 -8
- {gomyck_tools-1.3.6.dist-info → gomyck_tools-1.3.7.dist-info}/WHEEL +0 -0
- {gomyck_tools-1.3.6.dist-info → gomyck_tools-1.3.7.dist-info}/licenses/LICENSE +0 -0
- {gomyck_tools-1.3.6.dist-info → gomyck_tools-1.3.7.dist-info}/top_level.txt +0 -0
ctools/ai/llm_chat.py
CHANGED
@@ -44,6 +44,7 @@ class ChatSession:
|
|
44
44
|
|
45
45
|
self.current_message = {}
|
46
46
|
self.full_messages = []
|
47
|
+
self.is_success = True
|
47
48
|
|
48
49
|
async def init_prompts(self, user_system_prompt):
|
49
50
|
if self.mcp_clients:
|
@@ -128,6 +129,7 @@ class ChatSession:
|
|
128
129
|
|
129
130
|
async def process_error_message(self, error_msg, get_call_id, get_event_msg_func, get_full_msg_func):
|
130
131
|
# 最终结果通知前端+实时通知都要有
|
132
|
+
self.is_success = False
|
131
133
|
self.current_message = error_msg
|
132
134
|
if get_event_msg_func: await get_event_msg_func(get_call_id(), ROLE.ASSISTANT, self.current_message)
|
133
135
|
if get_full_msg_func: await get_full_msg_func(get_call_id(), True, self.full_messages)
|
@@ -9,13 +9,20 @@ def parse_tool_use(xml_string):
|
|
9
9
|
root = ET.fromstring(xml_string.strip())
|
10
10
|
if root.tag != "tool_use": raise ValueError("根标签必须是 <tool_use>")
|
11
11
|
tool_name = root.find("name").text.strip()
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
args = root.find("arguments").text
|
13
|
+
if args:
|
14
|
+
arguments_text = args.strip()
|
15
|
+
arguments_text = html.unescape(arguments_text)
|
16
|
+
arguments = json.loads(arguments_text)
|
17
|
+
return {
|
18
|
+
"tool": tool_name,
|
19
|
+
"arguments": arguments
|
20
|
+
}
|
21
|
+
else:
|
22
|
+
return {
|
23
|
+
"tool": tool_name,
|
24
|
+
"arguments": {}
|
25
|
+
}
|
19
26
|
except Exception as e:
|
20
27
|
raise ValueError(f"tool_use_{tool_name} 解析失败: {e}")
|
21
28
|
|
ctools/aio_web_server.py
CHANGED
@@ -5,17 +5,30 @@
|
|
5
5
|
__author__ = 'haoyang'
|
6
6
|
__date__ = '2025/5/30 09:54'
|
7
7
|
|
8
|
-
import asyncio
|
9
8
|
import sys
|
10
9
|
from pathlib import Path
|
11
10
|
from typing import Optional, Dict, Any
|
12
11
|
|
13
12
|
from aiohttp import web
|
14
13
|
|
15
|
-
from ctools import sys_info
|
14
|
+
from ctools import sys_info, cjson
|
15
|
+
from ctools.api_result import R
|
16
16
|
|
17
17
|
DEFAULT_PORT = 8888
|
18
18
|
|
19
|
+
@web.middleware
|
20
|
+
async def response_wrapper_middleware(request, handler):
|
21
|
+
try:
|
22
|
+
result = await handler(request)
|
23
|
+
if isinstance(result, web.Response):
|
24
|
+
return result
|
25
|
+
elif isinstance(result, str):
|
26
|
+
return web.Response(text=result)
|
27
|
+
else:
|
28
|
+
return web.Response(text=cjson.dumps(result))
|
29
|
+
except Exception as e:
|
30
|
+
return web.json_response(text=R.error(str(e)), status=200)
|
31
|
+
|
19
32
|
class AioHttpServer:
|
20
33
|
def __init__(self, port: int = DEFAULT_PORT, app: Optional[web.Application] = None, routes: Optional[web.RouteTableDef] = None, async_func = None):
|
21
34
|
"""
|
@@ -25,7 +38,7 @@ class AioHttpServer:
|
|
25
38
|
port: Port number to listen on
|
26
39
|
app: Optional existing aiohttp Application instance
|
27
40
|
"""
|
28
|
-
self.app = app or web.Application()
|
41
|
+
self.app = app or web.Application(middlewares=[response_wrapper_middleware])
|
29
42
|
self.port = port
|
30
43
|
self.index_root = Path('./')
|
31
44
|
self.index_filename = 'index.html'
|
@@ -58,7 +71,6 @@ class AioHttpServer:
|
|
58
71
|
return web.HTTPNotFound()
|
59
72
|
|
60
73
|
if self.is_tpl:
|
61
|
-
# If using templates, you might want to use a template engine here
|
62
74
|
return web.FileResponse(
|
63
75
|
index_path,
|
64
76
|
headers={'Content-Type': 'text/html'}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
ctools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
ctools/aes_tools.py,sha256=L5Jg4QtVTdIxHe9zEpR8oMQx0IrYK68vjEYb_RmkhPA,699
|
3
|
-
ctools/aio_web_server.py,sha256=
|
3
|
+
ctools/aio_web_server.py,sha256=W4vqHBr4VxaKppRmotyRamOf59f0WU6iYQHGqKFvPJs,4746
|
4
4
|
ctools/api_result.py,sha256=UeQXI_zuZB-uY5qECTpz1fC7EGy82yGQqWMx20tyRTw,1572
|
5
5
|
ctools/application.py,sha256=DcuSt2m8cDuSftx6eKfJ5gA6_F9dDlzkj0K86EG4F7s,15884
|
6
6
|
ctools/b64.py,sha256=_BdhX3p3-MaSSlU2wivN5qPxQfacR3VRBr1WC456tU0,194
|
@@ -60,17 +60,17 @@ ctools/word_fill_entity.py,sha256=eX3G0Gy16hfGpavQSEkCIoKDdTnNgRRJrFvKliETZK8,98
|
|
60
60
|
ctools/work_path.py,sha256=OmfYu-Jjg2huRY6Su8zJ_2EGFFhtBZFbobYTwbjJtG4,1817
|
61
61
|
ctools/ai/__init__.py,sha256=gTYAICILq48icnFbg0HCbsQO8PbU02EDOQ0JeMvfqTY,98
|
62
62
|
ctools/ai/env_config.py,sha256=hOuDVjyK00Ioq1G2z9Plf20TQha0tMV-VHWKAeCv16s,990
|
63
|
-
ctools/ai/llm_chat.py,sha256=
|
63
|
+
ctools/ai/llm_chat.py,sha256=xcjk9ALp9GfTlcHGCMOTYi7MuWoBFB73bmKAL9NedfY,8433
|
64
64
|
ctools/ai/llm_client.py,sha256=Zqizex4Umozqtfh__-wdgNu8p66Bl9iv6cLbNUGyRF8,5098
|
65
65
|
ctools/ai/mcp/__init__.py,sha256=gTYAICILq48icnFbg0HCbsQO8PbU02EDOQ0JeMvfqTY,98
|
66
66
|
ctools/ai/mcp/mcp_client.py,sha256=HLoGN-yCL5vMxwxcZMmXQyWof-nmp1KjrPrXQ46KGQs,11525
|
67
67
|
ctools/ai/tools/__init__.py,sha256=gPc-ViRgtFlfX7JUbk5wQZ3wkJ5Ylh14CIqPwa83VPs,98
|
68
68
|
ctools/ai/tools/json_extract.py,sha256=bgubZ2RwTo_R1X0CzMnvBWu61hglB1l6oO553645RXc,4842
|
69
69
|
ctools/ai/tools/think_process.py,sha256=RGU9j3_O328Byw05ILek-aMfFBczbly2RA-QRouqUjM,257
|
70
|
-
ctools/ai/tools/tool_use_xml_parse.py,sha256=
|
70
|
+
ctools/ai/tools/tool_use_xml_parse.py,sha256=zpHKMhU5LFSpuznU_Z5w_HHp-Bney-Te8DxoU1BNHZ0,1429
|
71
71
|
ctools/ai/tools/xml_extract.py,sha256=KTzsrJZDKmpJ-92yTO6z5nJ9a183ngF6ikTb4oiIjW4,246
|
72
|
-
gomyck_tools-1.3.
|
73
|
-
gomyck_tools-1.3.
|
74
|
-
gomyck_tools-1.3.
|
75
|
-
gomyck_tools-1.3.
|
76
|
-
gomyck_tools-1.3.
|
72
|
+
gomyck_tools-1.3.7.dist-info/licenses/LICENSE,sha256=X25ypfH9E6VTht2hcO8k7LCSdHUcoG_ALQt80jdYZfY,547
|
73
|
+
gomyck_tools-1.3.7.dist-info/METADATA,sha256=VFfjvXYkg1-Pfwksb08fqdFftCuNd4sjJTWwpAVcaOo,1595
|
74
|
+
gomyck_tools-1.3.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
75
|
+
gomyck_tools-1.3.7.dist-info/top_level.txt,sha256=-MiIH9FYRVKp1i5_SVRkaI-71WmF1sZSRrNWFU9ls3s,7
|
76
|
+
gomyck_tools-1.3.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|