gomyck-tools 1.3.9__py3-none-any.whl → 1.4.1__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/env_config.py CHANGED
@@ -5,7 +5,7 @@ __date__ = '2025/5/16 16:42'
5
5
 
6
6
  import json
7
7
  import os
8
- from typing import Any
8
+ from typing import Any, Optional
9
9
 
10
10
  from dotenv.main import DotEnv
11
11
 
@@ -17,12 +17,23 @@ class Configuration:
17
17
  """Initialize configuration with environment variables."""
18
18
  if not os.path.exists(dotenv_path): raise FileNotFoundError(f"Could not find .env file at {dotenv_path}")
19
19
  self.env = DotEnv(dotenv_path=dotenv_path)
20
+ for key, value in self.env.dict().items():
21
+ if value: os.environ[key] = value
20
22
 
21
- def get_env(self, key: str) -> str:
23
+ def get_env(self, key: str, default: Optional[Any] = None) -> Any:
22
24
  value = self.env.get(key)
23
- if value and value.lower() == "true": return True
24
- if value and value.lower() == "false": return False
25
- return value if value else os.getenv(key)
25
+ if value:
26
+ val = value.strip().lower()
27
+ if val == "true": return True
28
+ if val == "false": return False
29
+ return value
30
+ value = os.getenv(key)
31
+ if value:
32
+ val = value.strip().lower()
33
+ if val == "true": return True
34
+ if val == "false": return False
35
+ return value
36
+ return default
26
37
 
27
38
  def get_llm_api_key(self) -> str:
28
39
  api_key = self.get_env("LLM_API_KEY")
ctools/ai/llm_client.py CHANGED
@@ -3,7 +3,7 @@ import os
3
3
 
4
4
  import httpx
5
5
 
6
- from ctools import sys_log, cjson
6
+ from ctools import sys_log, cjson, call
7
7
  from ctools.ai.llm_exception import LLMException
8
8
 
9
9
  logging.getLogger("httpcore").setLevel(logging.WARNING)
@@ -20,11 +20,17 @@ def process_SSE(line):
20
20
  return "[DONE]"
21
21
  return data
22
22
 
23
- shared_client = httpx.AsyncClient(
24
- base_url=os.getenv("LLM_BASE_URL", "https://api.siliconflow.cn/v1/"),
25
- timeout=httpx.Timeout(connect=10.0, read=60.0, write=10.0, pool=5.0),
26
- limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
27
- )
23
+ shared_client = None
24
+
25
+ @call.once
26
+ def init_shared_client():
27
+ global shared_client
28
+ shared_client = httpx.AsyncClient(
29
+ base_url=os.getenv("LLM_BASE_URL", "https://api.siliconflow.cn/v1/"),
30
+ timeout=httpx.Timeout(connect=10.0, read=60.0, write=10.0, pool=5.0),
31
+ limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
32
+ )
33
+ return shared_client
28
34
 
29
35
  class LLMClient:
30
36
  """Manages communication with the LLM provider."""
@@ -51,6 +57,7 @@ class LLMClient:
51
57
  self.top_p = top_p
52
58
  self.top_k = top_k
53
59
  self.frequency_penalty = frequency_penalty
60
+ init_shared_client()
54
61
 
55
62
  async def model_completion(self, messages: list[dict[str, str]]):
56
63
  self.no_think_compatible(messages)
@@ -292,6 +292,7 @@ def is_image_content(content: dict) -> bool:
292
292
  @asynccontextmanager
293
293
  async def init_mcp_clients(mcp_server_config: dict[str, Any]) -> list[MCPClient]:
294
294
  mcp_clients = []
295
+ if not mcp_server_config["mcpServers"]: yield mcp_clients
295
296
  for name, sc in mcp_server_config["mcpServers"].items():
296
297
  try:
297
298
  mc = MCPClient(name, sc)
@@ -5,6 +5,7 @@ __date__ = '2025/6/9 09:49'
5
5
 
6
6
  import asyncio
7
7
  import json
8
+ import os
8
9
  import sys
9
10
  import uuid
10
11
 
@@ -38,10 +39,10 @@ def build_call_back(debug=False):
38
39
  call_id = uuid.uuid4()
39
40
  queue = asyncio.Queue()
40
41
  async def on_msg(cid, role, msg):
41
- if debug: print(msg, file=sys.__stdout__, end='')
42
+ if debug: print(msg, file=sys.__stdout__, end='', flush=True)
42
43
  await queue.put({"id": cid, "role": role, "msg": msg})
43
44
  async def on_final(cid, is_final, msg):
44
- if debug: print(cid, is_final, msg, file=sys.__stdout__)
45
+ if debug: print(cid, is_final, msg, file=sys.__stdout__, flush=True)
45
46
  if is_final:
46
47
  await queue.put("[DONE]")
47
48
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gomyck-tools
3
- Version: 1.3.9
3
+ Version: 1.4.1
4
4
  Summary: A tools collection for python development by hao474798383
5
5
  Author-email: gomyck <hao474798383@163.com>
6
6
  License-Expression: Apache-2.0
@@ -14,15 +14,15 @@ ctools/similar.py,sha256=7mBbp7JrGGyAgA_hDmCvGJ6hGE1Lh43ocyqPkLGclyc,695
14
14
  ctools/sys_info.py,sha256=T5pcRblNHEmXEvPk2PPvQga7Hh5aDnNN72pt4U176SE,4270
15
15
  ctools/sys_log.py,sha256=T-tgOcrFggSJ2I6pLHhKpj4fvVFk_vbZBOrInKC6y3Q,2789
16
16
  ctools/ai/__init__.py,sha256=gTYAICILq48icnFbg0HCbsQO8PbU02EDOQ0JeMvfqTY,98
17
- ctools/ai/env_config.py,sha256=CQtvQz1f3lvVuDTcnvDDZitnUeUdM3Ta8fXMn-x5Etg,1100
17
+ ctools/ai/env_config.py,sha256=pZ8dG-4-CeMjBdgFHvljY2xMfyBE_0bM961UjIzm6xs,1400
18
18
  ctools/ai/llm_chat.py,sha256=dAFar0A5h3ws_kjx9MlWZAawLPYHIwvfdyO_umJgkpU,8655
19
- ctools/ai/llm_client.py,sha256=iI8kUPn8z0pgTq8mTwnIJm9bOREmSZU5btePinmgGpg,5515
19
+ ctools/ai/llm_client.py,sha256=nQKjQj8WzDqCnMsYag3Td5hYTXep2PthRm6KS7Qyc8U,5661
20
20
  ctools/ai/llm_exception.py,sha256=wsCVl0m53Mk7Xfug1obocAthlX0oEo4dytg1eOhWHPg,389
21
21
  ctools/ai/mcp/__init__.py,sha256=gTYAICILq48icnFbg0HCbsQO8PbU02EDOQ0JeMvfqTY,98
22
- ctools/ai/mcp/mcp_client.py,sha256=eDxiG6ZHa4HX-Sz63ObmxyXIq2WZwUxQt8fSw9COfGc,11589
22
+ ctools/ai/mcp/mcp_client.py,sha256=9T22s8BmerT7FrmRJr2VRhvNaV17Xz-C8jGNp08PYu0,11649
23
23
  ctools/ai/tools/__init__.py,sha256=gPc-ViRgtFlfX7JUbk5wQZ3wkJ5Ylh14CIqPwa83VPs,98
24
24
  ctools/ai/tools/json_extract.py,sha256=bgubZ2RwTo_R1X0CzMnvBWu61hglB1l6oO553645RXc,4842
25
- ctools/ai/tools/quick_tools.py,sha256=_bJNH4miLltoFjolvJKnOzrArF0hRrXrkBO4elV-Mug,2335
25
+ ctools/ai/tools/quick_tools.py,sha256=WeUFDLLHrP6PCs1pM3G_hRS2YSTp5XjCrJ077u06jeo,2369
26
26
  ctools/ai/tools/think_process.py,sha256=RGU9j3_O328Byw05ILek-aMfFBczbly2RA-QRouqUjM,257
27
27
  ctools/ai/tools/tool_use_xml_parse.py,sha256=zpHKMhU5LFSpuznU_Z5w_HHp-Bney-Te8DxoU1BNHZ0,1429
28
28
  ctools/ai/tools/xml_extract.py,sha256=lpUTERzUQhbiWanc5_ukBP0wPIVg0F9va39S36yyI-4,231
@@ -75,8 +75,8 @@ ctools/web/ctoken.py,sha256=CdHm6-ykBLh7Lv8ZRMunSW40qMTkRH0ITeMLuG9z1ts,883
75
75
  ctools/web/download_util.py,sha256=EVN3fxwbUE5Q8nurAya5IYialIKBMoFtSOy0uPKyV-E,1951
76
76
  ctools/web/params_util.py,sha256=2vAuwn8OPydv_7BPKypqk4zuerPZqOGcf95wV19H1Ks,824
77
77
  ctools/web/upload_util.py,sha256=xH4Z-sz-s7EVDEz2gKXoP9OZTLc-er5yvsiLqhSDFm8,1076
78
- gomyck_tools-1.3.9.dist-info/licenses/LICENSE,sha256=X25ypfH9E6VTht2hcO8k7LCSdHUcoG_ALQt80jdYZfY,547
79
- gomyck_tools-1.3.9.dist-info/METADATA,sha256=Z8IRmbiJXNtXNq1ezTsNFHTeLCI1he23ONzg4KOjwY4,1595
80
- gomyck_tools-1.3.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
81
- gomyck_tools-1.3.9.dist-info/top_level.txt,sha256=-MiIH9FYRVKp1i5_SVRkaI-71WmF1sZSRrNWFU9ls3s,7
82
- gomyck_tools-1.3.9.dist-info/RECORD,,
78
+ gomyck_tools-1.4.1.dist-info/licenses/LICENSE,sha256=X25ypfH9E6VTht2hcO8k7LCSdHUcoG_ALQt80jdYZfY,547
79
+ gomyck_tools-1.4.1.dist-info/METADATA,sha256=CDdnfnwdeNZsLWRZqCrx7cneqAbQgwXraoYDbI4ahg0,1595
80
+ gomyck_tools-1.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
81
+ gomyck_tools-1.4.1.dist-info/top_level.txt,sha256=-MiIH9FYRVKp1i5_SVRkaI-71WmF1sZSRrNWFU9ls3s,7
82
+ gomyck_tools-1.4.1.dist-info/RECORD,,