flexllm 0.3.3__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.
- flexllm/__init__.py +224 -0
- flexllm/__main__.py +1096 -0
- flexllm/async_api/__init__.py +9 -0
- flexllm/async_api/concurrent_call.py +100 -0
- flexllm/async_api/concurrent_executor.py +1036 -0
- flexllm/async_api/core.py +373 -0
- flexllm/async_api/interface.py +12 -0
- flexllm/async_api/progress.py +277 -0
- flexllm/base_client.py +988 -0
- flexllm/batch_tools/__init__.py +16 -0
- flexllm/batch_tools/folder_processor.py +317 -0
- flexllm/batch_tools/table_processor.py +363 -0
- flexllm/cache/__init__.py +10 -0
- flexllm/cache/response_cache.py +293 -0
- flexllm/chain_of_thought_client.py +1120 -0
- flexllm/claudeclient.py +402 -0
- flexllm/client_pool.py +698 -0
- flexllm/geminiclient.py +563 -0
- flexllm/llm_client.py +523 -0
- flexllm/llm_parser.py +60 -0
- flexllm/mllm_client.py +559 -0
- flexllm/msg_processors/__init__.py +174 -0
- flexllm/msg_processors/image_processor.py +729 -0
- flexllm/msg_processors/image_processor_helper.py +485 -0
- flexllm/msg_processors/messages_processor.py +341 -0
- flexllm/msg_processors/unified_processor.py +1404 -0
- flexllm/openaiclient.py +256 -0
- flexllm/pricing/__init__.py +104 -0
- flexllm/pricing/data.json +1201 -0
- flexllm/pricing/updater.py +223 -0
- flexllm/provider_router.py +213 -0
- flexllm/token_counter.py +270 -0
- flexllm/utils/__init__.py +1 -0
- flexllm/utils/core.py +41 -0
- flexllm-0.3.3.dist-info/METADATA +573 -0
- flexllm-0.3.3.dist-info/RECORD +39 -0
- flexllm-0.3.3.dist-info/WHEEL +4 -0
- flexllm-0.3.3.dist-info/entry_points.txt +3 -0
- flexllm-0.3.3.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# maque.mllm.processors - 统一的高性能图像处理和消息预处理模块
|
|
2
|
+
|
|
3
|
+
# 核心图像处理功能
|
|
4
|
+
from .image_processor import (
|
|
5
|
+
ImageCacheConfig,
|
|
6
|
+
encode_image_to_base64,
|
|
7
|
+
encode_to_base64,
|
|
8
|
+
get_pil_image,
|
|
9
|
+
get_pil_image_sync,
|
|
10
|
+
decode_base64_to_pil,
|
|
11
|
+
decode_base64_to_file,
|
|
12
|
+
decode_base64_to_bytes,
|
|
13
|
+
encode_base64_from_local_path,
|
|
14
|
+
encode_base64_from_pil,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
# 基础消息处理功能
|
|
18
|
+
from .messages_processor import (
|
|
19
|
+
process_content_recursive,
|
|
20
|
+
messages_preprocess,
|
|
21
|
+
batch_messages_preprocess,
|
|
22
|
+
batch_process_messages, # 别名
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# 统一高性能处理器(推荐用于生产环境)
|
|
26
|
+
from .unified_processor import (
|
|
27
|
+
UnifiedProcessorConfig,
|
|
28
|
+
UnifiedImageProcessor,
|
|
29
|
+
UnifiedMemoryCache,
|
|
30
|
+
batch_process_messages as unified_batch_process_messages,
|
|
31
|
+
unified_encode_image_to_base64,
|
|
32
|
+
get_global_unified_processor,
|
|
33
|
+
cleanup_global_unified_processor,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# 便捷的类接口
|
|
37
|
+
from .image_processor_helper import ImageProcessor
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
# 图像缓存配置
|
|
41
|
+
"ImageCacheConfig",
|
|
42
|
+
# 核心图像处理
|
|
43
|
+
"encode_image_to_base64",
|
|
44
|
+
"encode_to_base64",
|
|
45
|
+
"get_pil_image",
|
|
46
|
+
"get_pil_image_sync",
|
|
47
|
+
"decode_base64_to_pil",
|
|
48
|
+
"decode_base64_to_file",
|
|
49
|
+
"decode_base64_to_bytes",
|
|
50
|
+
"encode_base64_from_local_path",
|
|
51
|
+
"encode_base64_from_pil",
|
|
52
|
+
# 基础消息处理
|
|
53
|
+
"process_content_recursive",
|
|
54
|
+
"messages_preprocess",
|
|
55
|
+
"batch_messages_preprocess",
|
|
56
|
+
"batch_process_messages",
|
|
57
|
+
# 统一高性能处理器(推荐)
|
|
58
|
+
"UnifiedProcessorConfig",
|
|
59
|
+
"UnifiedImageProcessor",
|
|
60
|
+
"UnifiedMemoryCache",
|
|
61
|
+
"unified_batch_process_messages",
|
|
62
|
+
"unified_encode_image_to_base64",
|
|
63
|
+
"get_global_unified_processor",
|
|
64
|
+
"cleanup_global_unified_processor",
|
|
65
|
+
# 便捷类接口
|
|
66
|
+
"ImageProcessor",
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
# 版本和性能信息
|
|
70
|
+
__version__ = "3.0.0" # 架构精简后的新版本
|
|
71
|
+
__description__ = "统一高性能图像处理和消息预处理模块 - 精简架构,专注于统一处理器"
|
|
72
|
+
|
|
73
|
+
# 性能建议
|
|
74
|
+
PERFORMANCE_RECOMMENDATIONS = {
|
|
75
|
+
"unified_high_performance": {
|
|
76
|
+
"function": "unified_batch_process_messages",
|
|
77
|
+
"single_image_function": "unified_encode_image_to_base64",
|
|
78
|
+
"config": "UnifiedProcessorConfig.high_performance()",
|
|
79
|
+
"recommended_settings": {
|
|
80
|
+
"max_concurrent": 20,
|
|
81
|
+
"max_workers": 16,
|
|
82
|
+
"memory_cache_size_mb": 1000,
|
|
83
|
+
},
|
|
84
|
+
"speedup": "50-200x",
|
|
85
|
+
"description": "🚀 最高性能选择,统一处理本地文件和URL,支持自适应配置",
|
|
86
|
+
},
|
|
87
|
+
"unified_auto_detect": {
|
|
88
|
+
"function": "unified_batch_process_messages",
|
|
89
|
+
"single_image_function": "unified_encode_image_to_base64",
|
|
90
|
+
"config": "UnifiedProcessorConfig.auto_detect()",
|
|
91
|
+
"recommended_settings": "自动检测系统资源并调整",
|
|
92
|
+
"speedup": "根据系统自动优化",
|
|
93
|
+
"description": "🤖 智能配置选择,根据CPU和内存自动调整参数",
|
|
94
|
+
},
|
|
95
|
+
"unified_memory_optimized": {
|
|
96
|
+
"function": "unified_batch_process_messages",
|
|
97
|
+
"single_image_function": "unified_encode_image_to_base64",
|
|
98
|
+
"config": "UnifiedProcessorConfig.memory_optimized()",
|
|
99
|
+
"recommended_settings": {
|
|
100
|
+
"max_concurrent": 6,
|
|
101
|
+
"max_workers": 4,
|
|
102
|
+
"memory_cache_size_mb": 200,
|
|
103
|
+
},
|
|
104
|
+
"speedup": "20-60x",
|
|
105
|
+
"description": "💾 内存优化选择,适合资源受限环境",
|
|
106
|
+
},
|
|
107
|
+
"single_processing": {
|
|
108
|
+
"function": "messages_preprocess",
|
|
109
|
+
"description": "⚡ 推荐用于单个消息列表处理,简单快速",
|
|
110
|
+
},
|
|
111
|
+
"image_only": {
|
|
112
|
+
"function": "encode_image_to_base64",
|
|
113
|
+
"description": "🖼️ 仅处理单张图像时使用",
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def get_performance_recommendation(use_case: str = "unified_auto_detect") -> dict:
|
|
119
|
+
"""获取性能建议
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
use_case: 使用场景,可选:
|
|
123
|
+
- 'unified_auto_detect': 自适应配置(推荐)
|
|
124
|
+
- 'unified_high_performance': 最高性能配置
|
|
125
|
+
- 'unified_memory_optimized': 内存优化配置
|
|
126
|
+
- 'single_processing': 单个消息处理
|
|
127
|
+
- 'image_only': 单张图像处理
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
性能建议字典
|
|
131
|
+
"""
|
|
132
|
+
return PERFORMANCE_RECOMMENDATIONS.get(
|
|
133
|
+
use_case, PERFORMANCE_RECOMMENDATIONS["unified_auto_detect"]
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def print_performance_guide():
|
|
138
|
+
"""打印性能使用指南"""
|
|
139
|
+
print("🚀 Sparrow VLLM Client 统一处理器使用指南")
|
|
140
|
+
print("=" * 60)
|
|
141
|
+
print()
|
|
142
|
+
|
|
143
|
+
for use_case, config in PERFORMANCE_RECOMMENDATIONS.items():
|
|
144
|
+
print(f"📊 {use_case.replace('_', ' ').title()}:")
|
|
145
|
+
print(f" {config['description']}")
|
|
146
|
+
print(f" 函数: {config['function']}")
|
|
147
|
+
if "speedup" in config:
|
|
148
|
+
print(f" 性能提升: {config['speedup']}")
|
|
149
|
+
if "config" in config:
|
|
150
|
+
print(f" 配置: {config['config']}")
|
|
151
|
+
print()
|
|
152
|
+
|
|
153
|
+
print("💡 推荐: 优先使用 unified_auto_detect 获得最佳性能!")
|
|
154
|
+
print()
|
|
155
|
+
print("📝 批量消息处理示例:")
|
|
156
|
+
print("```python")
|
|
157
|
+
print(
|
|
158
|
+
"from flexllm.msg_processors import unified_batch_process_messages, UnifiedProcessorConfig"
|
|
159
|
+
)
|
|
160
|
+
print("")
|
|
161
|
+
print("# 自适应配置(推荐)")
|
|
162
|
+
print("config = UnifiedProcessorConfig.auto_detect()")
|
|
163
|
+
print("processed = await unified_batch_process_messages(")
|
|
164
|
+
print(" messages_list,")
|
|
165
|
+
print(" processor_config=config,")
|
|
166
|
+
print(" show_progress=True")
|
|
167
|
+
print(")")
|
|
168
|
+
print("```")
|
|
169
|
+
print()
|
|
170
|
+
print("🎯 精简架构特性:")
|
|
171
|
+
print(" ✅ 统一处理本地文件和URL")
|
|
172
|
+
print(" ✅ 自适应系统资源配置")
|
|
173
|
+
print(" ✅ 智能缓存系统")
|
|
174
|
+
print(" ✅ 性能监控统计")
|