LLM-Bridge 1.11.2__py3-none-any.whl → 1.11.3b0__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.
@@ -1,4 +1,8 @@
1
1
  from anthropic import BetaMessageStreamEvent, AsyncAnthropic
2
+ from anthropic.types.beta import BetaRawContentBlockDelta, BetaThinkingDelta, BetaTextDelta, BetaInputJSONDelta, \
3
+ BetaBashCodeExecutionToolResultBlock, \
4
+ BetaTextEditorCodeExecutionToolResultBlock
5
+ from anthropic.types.beta.beta_raw_content_block_start_event import ContentBlock
2
6
 
3
7
  from llm_bridge.client.implementations.claude.claude_token_counter import count_claude_output_tokens
4
8
  from llm_bridge.type.chat_response import ChatResponse
@@ -14,16 +18,42 @@ class ClaudeStreamResponseHandler:
14
18
  ) -> ChatResponse:
15
19
  text = ""
16
20
  thought = ""
21
+ code = ""
22
+ code_output = ""
17
23
 
18
24
  if event.type == "content_block_delta":
19
- if event.delta.type == "thinking_delta":
20
- thought += event.delta.thinking
21
- elif event.delta.type == "text_delta":
22
- text += event.delta.text
25
+ event_delta: BetaRawContentBlockDelta = event.delta
26
+
27
+ if event_delta.type == "text_delta":
28
+ text_delta: BetaTextDelta = event_delta
29
+ text += text_delta.text
30
+
31
+ elif event_delta.type == "thinking_delta":
32
+ thinking_delta: BetaThinkingDelta = event_delta
33
+ thought += thinking_delta.thinking
34
+
35
+ elif event_delta.type == "input_json_delta":
36
+ input_json_delta: BetaInputJSONDelta = event_delta
37
+ code += input_json_delta.partial_json
38
+
39
+ if event.type == "content_block_start":
40
+ event_content_block: ContentBlock = event.content_block
41
+
42
+ if event_content_block.type == "bash_code_execution_tool_result":
43
+ bash_code_execution_tool_result_block: BetaBashCodeExecutionToolResultBlock = event_content_block
44
+ if bash_code_execution_tool_result_block.content.type == "bash_code_execution_result":
45
+ code_output += event_content_block.content.stdout
46
+
47
+ elif event_content_block.type == "text_editor_code_execution_tool_result":
48
+ text_editor_code_execution_tool_result: BetaTextEditorCodeExecutionToolResultBlock = event_content_block
49
+ if text_editor_code_execution_tool_result.content.type == "text_editor_code_execution_view_result":
50
+ code_output += event_content_block.content.content
23
51
 
24
52
  chat_response = ChatResponse(
25
53
  text=text,
26
54
  thought=thought,
55
+ code=code,
56
+ code_output=code_output,
27
57
  )
28
58
  output_tokens = await count_claude_output_tokens(
29
59
  client=client,
@@ -33,6 +63,8 @@ class ClaudeStreamResponseHandler:
33
63
  return ChatResponse(
34
64
  text=text,
35
65
  thought=thought,
66
+ code=code,
67
+ code_output=code_output,
36
68
  input_tokens=input_tokens,
37
69
  output_tokens=output_tokens,
38
70
  )
@@ -28,7 +28,11 @@ async def count_claude_output_tokens(
28
28
  model: str,
29
29
  chat_response: ChatResponse,
30
30
  ) -> int:
31
- text = chat_response.text.strip()
31
+ text = ""
32
+ text += chat_response.text.strip()
33
+ text += chat_response.thought.strip()
34
+ text += chat_response.code.strip()
35
+ text += chat_response.code_output.strip()
32
36
  if text == "":
33
37
  return 0
34
38
 
@@ -3,7 +3,8 @@ import re
3
3
 
4
4
  import httpx
5
5
  from anthropic import AsyncAnthropic
6
- from anthropic.types.beta import BetaMessage
6
+ from anthropic.types.beta import BetaMessage, BetaBashCodeExecutionToolResultBlock, BetaTextBlock, BetaThinkingBlock, \
7
+ BetaServerToolUseBlock
7
8
  from fastapi import HTTPException
8
9
 
9
10
  from llm_bridge.client.implementations.claude.claude_token_counter import count_claude_output_tokens
@@ -20,16 +21,37 @@ async def process_claude_non_stream_response(
20
21
  ) -> ChatResponse:
21
22
  text = ""
22
23
  thought = ""
24
+ code = ""
25
+ code_output = ""
23
26
 
24
- for content in message.content:
25
- if content.type == "thinking":
26
- thought += content.thinking
27
- if content.type == "text":
28
- text += content.text
27
+ for content_block in message.content:
28
+ if content_block.type == "text":
29
+ text_block: BetaTextBlock = content_block
30
+ text += text_block.text
31
+
32
+ elif content_block.type == "thinking":
33
+ thinking_block: BetaThinkingBlock = content_block
34
+ thought += thinking_block.thinking
35
+
36
+ elif content_block.type == "server_tool_use":
37
+ server_tool_use_block: BetaServerToolUseBlock = content_block
38
+ code += server_tool_use_block.input
39
+
40
+ elif content_block.type == "bash_code_execution_tool_result":
41
+ bash_code_execution_tool_result_block: BetaBashCodeExecutionToolResultBlock = content_block
42
+ if bash_code_execution_tool_result_block.content.type == "bash_code_execution_result":
43
+ code_output += bash_code_execution_tool_result_block.content.stdout
44
+
45
+ elif content_block.type == "text_editor_code_execution_tool_result":
46
+ text_editor_code_execution_tool_result: BetaBashCodeExecutionToolResultBlock = content_block
47
+ if text_editor_code_execution_tool_result.content.type == "text_editor_code_execution_view_result":
48
+ code_output += content_block.content.content
29
49
 
30
50
  chat_response = ChatResponse(
31
51
  text=text,
32
52
  thought=thought,
53
+ code=code,
54
+ code_output=code_output,
33
55
  )
34
56
  output_tokens = await count_claude_output_tokens(
35
57
  client=client,
@@ -39,6 +61,8 @@ async def process_claude_non_stream_response(
39
61
  return ChatResponse(
40
62
  text=text,
41
63
  thought=thought,
64
+ code=code,
65
+ code_output=code_output,
42
66
  input_tokens=input_tokens,
43
67
  output_tokens=output_tokens,
44
68
  )
@@ -1,6 +1,6 @@
1
1
  import anthropic
2
2
  from anthropic.types import ThinkingConfigEnabledParam, AnthropicBetaParam
3
- from anthropic.types.beta import BetaCodeExecutionTool20250825Param, BetaWebSearchTool20250305Param
3
+ from anthropic.types.beta import BetaWebSearchTool20250305Param, BetaToolUnionParam, BetaCodeExecutionTool20250825Param
4
4
 
5
5
  from llm_bridge.client.implementations.claude.claude_token_counter import count_claude_input_tokens
6
6
  from llm_bridge.client.implementations.claude.non_stream_claude_client import NonStreamClaudeClient
@@ -34,23 +34,29 @@ async def create_claude_client(
34
34
  messages=claude_messages,
35
35
  )
36
36
 
37
- max_tokens = min(32000, 200000 - input_tokens)
37
+ max_tokens = min(
38
+ 32_000, # Max output: Claude 4.5 64K; Claude 4.1 32K
39
+ 200_000 - input_tokens # Context window: Claude Sonnet 4.5 beta: 1M; otherwise 200K
40
+ )
38
41
  thinking = ThinkingConfigEnabledParam(
39
42
  type="enabled",
40
- budget_tokens=16000
43
+ budget_tokens=min(32_000, max_tokens) // 2
41
44
  )
42
45
  temperature = 1
43
- betas: list[AnthropicBetaParam] = ["output-128k-2025-02-19", "code-execution-2025-08-25"]
44
- tools = [
46
+ betas: list[AnthropicBetaParam] = [
47
+ "context-1m-2025-08-07",
48
+ "output-128k-2025-02-19",
49
+ "code-execution-2025-08-25",
50
+ ]
51
+ tools: list[BetaToolUnionParam] = [
45
52
  BetaWebSearchTool20250305Param(
46
53
  type="web_search_20250305",
47
54
  name="web_search",
48
55
  ),
49
- # Code Execution is unavailable in Claude
50
- # BetaCodeExecutionTool20250825Param(
51
- # type="code_execution_20250825",
52
- # name="code_execution",
53
- # )
56
+ BetaCodeExecutionTool20250825Param(
57
+ type="code_execution_20250825",
58
+ name="code_execution",
59
+ )
54
60
  ]
55
61
 
56
62
  if stream:
@@ -79,5 +85,3 @@ async def create_claude_client(
79
85
  input_tokens=input_tokens,
80
86
  tools=tools,
81
87
  )
82
-
83
-
@@ -152,8 +152,8 @@
152
152
  {
153
153
  "apiType": "Claude",
154
154
  "model": "claude-sonnet-4-5",
155
- "input": 3,
156
- "output": 15
155
+ "input": 6,
156
+ "output": 22.5
157
157
  },
158
158
  {
159
159
  "apiType": "Claude",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: LLM-Bridge
3
- Version: 1.11.2
3
+ Version: 1.11.3b0
4
4
  Summary: A Bridge for LLMs
5
5
  Author-email: windsnow1025 <windsnow1025@gmail.com>
6
6
  License-Expression: MIT
@@ -4,9 +4,9 @@ llm_bridge/client/chat_client.py,sha256=XISF2BM-WkZJNbnvcLfMcbSzlrE0XMDulyE_VG9z
4
4
  llm_bridge/client/implementations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  llm_bridge/client/implementations/printing_status.py,sha256=ok3ihBRIEan3qMbc62HeXTThDx1L6Zbs_IT0HPLPspI,102
6
6
  llm_bridge/client/implementations/claude/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- llm_bridge/client/implementations/claude/claude_stream_response_handler.py,sha256=qNy0w3ObKopYp3NBWaz25tGm_bEO9RnEk6qi94W1WIs,1190
8
- llm_bridge/client/implementations/claude/claude_token_counter.py,sha256=g8M7BFY2zM0jrLFyfGPW-4KYetib3x098XKvEdbZh30,1182
9
- llm_bridge/client/implementations/claude/non_stream_claude_client.py,sha256=xnge1J-j_Er4K4L1UxhjuxAs_Pl6vralxTKk9yItwjI,2500
7
+ llm_bridge/client/implementations/claude/claude_stream_response_handler.py,sha256=3fRyaQ_uZiPC-UyNq5OXCH6a_TFlqL3x1um1kd4knwc,2886
8
+ llm_bridge/client/implementations/claude/claude_token_counter.py,sha256=m_aoLJkFPJqSBA3Thzv5vg3GnaucZh41SAgT28sLeBA,1324
9
+ llm_bridge/client/implementations/claude/non_stream_claude_client.py,sha256=OljVF37RaP98WhPnSgLRgqTMPSWJ4dGjeashg3f5dRo,3779
10
10
  llm_bridge/client/implementations/claude/stream_claude_client.py,sha256=q4w1UYc1yZJw5UFOtnxCoeg8MFp5soc1d57YiCTCCGE,2109
11
11
  llm_bridge/client/implementations/gemini/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  llm_bridge/client/implementations/gemini/gemini_response_handler.py,sha256=LADXq5h_bbuCclp4RTf70YtQ0_9JFRRzo7j4V5Ts7y4,4388
@@ -31,7 +31,7 @@ llm_bridge/logic/chat_generate/chat_client_factory.py,sha256=H0rcRHytSfYKz_mwRfJ
31
31
  llm_bridge/logic/chat_generate/chat_message_converter.py,sha256=40VTBOPXg_ocrEZMdt1ObYlm-mhRL35zWzzxv8m2xRc,1538
32
32
  llm_bridge/logic/chat_generate/media_processor.py,sha256=ZR8G24EHwZZr2T9iFDRmScDGyJ_kvThApABzSzK0CL0,702
33
33
  llm_bridge/logic/chat_generate/model_client_factory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
- llm_bridge/logic/chat_generate/model_client_factory/claude_client_factory.py,sha256=j8RwLDul_zdZIIZfzrJji3VmqnYVAV61Xjrbp4NC69k,2603
34
+ llm_bridge/logic/chat_generate/model_client_factory/claude_client_factory.py,sha256=unSrPGhQ4wO4xeMnXOGlCfd6BZE7NNYs6mYVcchXOvc,2800
35
35
  llm_bridge/logic/chat_generate/model_client_factory/gemini_client_factory.py,sha256=ms0v1TnVA_JJFKhOkbF_qHeRJEAZ3SH2QOYUi2w_FBI,3614
36
36
  llm_bridge/logic/chat_generate/model_client_factory/openai_client_factory.py,sha256=uSDkNcUKdyzfJBE_KPq9Uqpt_DpDulluGjUT-iq8li0,4363
37
37
  llm_bridge/logic/chat_generate/model_message_converter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -45,7 +45,7 @@ llm_bridge/logic/message_preprocess/document_processor.py,sha256=IsVqoFgWNa9i8cR
45
45
  llm_bridge/logic/message_preprocess/file_type_checker.py,sha256=nkrVki1a2udCeVqUnfIVi7Wxx8OMKbBuHw3FOlm17uo,1603
46
46
  llm_bridge/logic/message_preprocess/message_preprocessor.py,sha256=ERws57Dsu-f5LpWKqJ_SEP7omNWXeGoJaocX91P6QDQ,1907
47
47
  llm_bridge/resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
- llm_bridge/resources/model_prices.json,sha256=-6KjPzsOtqC6EYL-WFTnszoVzrP5GOFJhPX943BNYZU,3440
48
+ llm_bridge/resources/model_prices.json,sha256=JFCzCLulZ6z9qKKMjMuvZPk_d8Z9rM1GF0szkvfypv0,3442
49
49
  llm_bridge/type/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
50
  llm_bridge/type/chat_response.py,sha256=zEw-my_I0-7msmlTySdBGE2vWUIPILex0UrUPqTJiYY,754
51
51
  llm_bridge/type/message.py,sha256=NyWmSSrciFfvF81aBwAH8qFpo5IpRhh8QXMselbYen8,370
@@ -55,8 +55,8 @@ llm_bridge/type/model_message/claude_message.py,sha256=gYJUTbLUeifQMva3Axarc-VFe
55
55
  llm_bridge/type/model_message/gemini_message.py,sha256=mh8pf929g7_NkBzSOwnLXyrwSzTT4yt2FmyX7NZn0sM,4302
56
56
  llm_bridge/type/model_message/openai_message.py,sha256=xFaLY-cZoSwNd7E9BSWQjBNcRfCVH11X9s2yxXlctR0,453
57
57
  llm_bridge/type/model_message/openai_responses_message.py,sha256=be1q2euA0ybjj4NO6NxOGIRB9eJuXSb4ssUm_bM4Ocs,1529
58
- llm_bridge-1.11.2.dist-info/licenses/LICENSE,sha256=m6uon-6P_CaiqcBfApMfjG9YRtDxcr40Z52JcqUCEAE,1069
59
- llm_bridge-1.11.2.dist-info/METADATA,sha256=GeH0Z_IgD9zRenLpq-p7OFYc5JGazD4Lqr5xvBNz9AM,7849
60
- llm_bridge-1.11.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
61
- llm_bridge-1.11.2.dist-info/top_level.txt,sha256=PtxyrgNX1lSa1Ab_qswg0sekSXejG5zrS6b_v3Po05g,11
62
- llm_bridge-1.11.2.dist-info/RECORD,,
58
+ llm_bridge-1.11.3b0.dist-info/licenses/LICENSE,sha256=m6uon-6P_CaiqcBfApMfjG9YRtDxcr40Z52JcqUCEAE,1069
59
+ llm_bridge-1.11.3b0.dist-info/METADATA,sha256=Skjps0NM7c883d_Mx5PQ0cpbDrEiYLXLu6nbc9qsWdI,7851
60
+ llm_bridge-1.11.3b0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
61
+ llm_bridge-1.11.3b0.dist-info/top_level.txt,sha256=PtxyrgNX1lSa1Ab_qswg0sekSXejG5zrS6b_v3Po05g,11
62
+ llm_bridge-1.11.3b0.dist-info/RECORD,,