vv-llm 0.3.73__tar.gz

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.
Files changed (45) hide show
  1. vv_llm-0.3.73/LICENSE +21 -0
  2. vv_llm-0.3.73/PKG-INFO +174 -0
  3. vv_llm-0.3.73/README.md +145 -0
  4. vv_llm-0.3.73/pyproject.toml +118 -0
  5. vv_llm-0.3.73/src/vv_llm/__init__.py +1 -0
  6. vv_llm-0.3.73/src/vv_llm/chat_clients/__init__.py +657 -0
  7. vv_llm-0.3.73/src/vv_llm/chat_clients/anthropic_client.py +1004 -0
  8. vv_llm-0.3.73/src/vv_llm/chat_clients/baichuan_client.py +15 -0
  9. vv_llm-0.3.73/src/vv_llm/chat_clients/base_client.py +885 -0
  10. vv_llm-0.3.73/src/vv_llm/chat_clients/deepseek_client.py +15 -0
  11. vv_llm-0.3.73/src/vv_llm/chat_clients/ernie_client.py +15 -0
  12. vv_llm-0.3.73/src/vv_llm/chat_clients/gemini_client.py +13 -0
  13. vv_llm-0.3.73/src/vv_llm/chat_clients/groq_client.py +15 -0
  14. vv_llm-0.3.73/src/vv_llm/chat_clients/local_client.py +14 -0
  15. vv_llm-0.3.73/src/vv_llm/chat_clients/message_normalizer.py +133 -0
  16. vv_llm-0.3.73/src/vv_llm/chat_clients/minimax_client.py +13 -0
  17. vv_llm-0.3.73/src/vv_llm/chat_clients/mistral_client.py +15 -0
  18. vv_llm-0.3.73/src/vv_llm/chat_clients/moonshot_client.py +15 -0
  19. vv_llm-0.3.73/src/vv_llm/chat_clients/openai_client.py +15 -0
  20. vv_llm-0.3.73/src/vv_llm/chat_clients/openai_compatible_client.py +1482 -0
  21. vv_llm-0.3.73/src/vv_llm/chat_clients/py.typed +0 -0
  22. vv_llm-0.3.73/src/vv_llm/chat_clients/qwen_client.py +15 -0
  23. vv_llm-0.3.73/src/vv_llm/chat_clients/stepfun_client.py +15 -0
  24. vv_llm-0.3.73/src/vv_llm/chat_clients/stream_event_adapter.py +315 -0
  25. vv_llm-0.3.73/src/vv_llm/chat_clients/tool_call_parser.py +65 -0
  26. vv_llm-0.3.73/src/vv_llm/chat_clients/utils.py +998 -0
  27. vv_llm-0.3.73/src/vv_llm/chat_clients/xai_client.py +15 -0
  28. vv_llm-0.3.73/src/vv_llm/chat_clients/yi_client.py +15 -0
  29. vv_llm-0.3.73/src/vv_llm/chat_clients/zhipuai_client.py +15 -0
  30. vv_llm-0.3.73/src/vv_llm/py.typed +0 -0
  31. vv_llm-0.3.73/src/vv_llm/server/token_server.py +79 -0
  32. vv_llm-0.3.73/src/vv_llm/settings/__init__.py +268 -0
  33. vv_llm-0.3.73/src/vv_llm/settings/py.typed +0 -0
  34. vv_llm-0.3.73/src/vv_llm/types/__init__.py +156 -0
  35. vv_llm-0.3.73/src/vv_llm/types/defaults.py +1630 -0
  36. vv_llm-0.3.73/src/vv_llm/types/enums.py +95 -0
  37. vv_llm-0.3.73/src/vv_llm/types/exception.py +5 -0
  38. vv_llm-0.3.73/src/vv_llm/types/llm_parameters.py +259 -0
  39. vv_llm-0.3.73/src/vv_llm/types/py.typed +0 -0
  40. vv_llm-0.3.73/src/vv_llm/types/settings.py +155 -0
  41. vv_llm-0.3.73/src/vv_llm/utilities/chunking.py +231 -0
  42. vv_llm-0.3.73/src/vv_llm/utilities/gcp_token.py +356 -0
  43. vv_llm-0.3.73/src/vv_llm/utilities/media_processing.py +214 -0
  44. vv_llm-0.3.73/src/vv_llm/utilities/rate_limiter.py +328 -0
  45. vv_llm-0.3.73/src/vv_llm/utilities/retry.py +66 -0
vv_llm-0.3.73/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Anderson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
vv_llm-0.3.73/PKG-INFO ADDED
@@ -0,0 +1,174 @@
1
+ Metadata-Version: 2.1
2
+ Name: vv-llm
3
+ Version: 0.3.73
4
+ Summary: Universal LLM interfaces for multi-provider chat and utilities
5
+ Author-Email: Anderson <andersonby@163.com>
6
+ License: MIT
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: openai>=1.99.3
9
+ Requires-Dist: tiktoken>=0.7.0
10
+ Requires-Dist: httpx>=0.27.0
11
+ Requires-Dist: anthropic>=0.47.1
12
+ Requires-Dist: pydantic>=2.8.2
13
+ Requires-Dist: Pillow>=10.4.0
14
+ Requires-Dist: deepseek-tokenizer>=0.1.0
15
+ Requires-Dist: qwen-tokenizer>=0.2.0
16
+ Provides-Extra: bedrock
17
+ Requires-Dist: boto3>=1.28.57; extra == "bedrock"
18
+ Requires-Dist: botocore>=1.31.57; extra == "bedrock"
19
+ Provides-Extra: diskcache
20
+ Requires-Dist: diskcache; extra == "diskcache"
21
+ Provides-Extra: redis
22
+ Requires-Dist: redis; extra == "redis"
23
+ Provides-Extra: server
24
+ Requires-Dist: fastapi; extra == "server"
25
+ Requires-Dist: uvicorn; extra == "server"
26
+ Provides-Extra: vertex
27
+ Requires-Dist: google-auth>=2.35.0; extra == "vertex"
28
+ Description-Content-Type: text/markdown
29
+
30
+ # vv-llm
31
+
32
+ Universal LLM interface layer for Python. One API, 16 backends, sync & async.
33
+
34
+ ```
35
+ pip install vv-llm
36
+ ```
37
+
38
+ ## Supported Backends
39
+
40
+ OpenAI | Anthropic | DeepSeek | Gemini | Qwen | Groq | Mistral | Moonshot | MiniMax | Yi | ZhiPuAI | Baichuan | StepFun | xAI | Ernie | Local
41
+
42
+ Also supports Azure OpenAI, Vertex AI, and AWS Bedrock deployments.
43
+
44
+ ## Quick Start
45
+
46
+ ### Configure
47
+
48
+ ```python
49
+ from vv_llm.settings import settings
50
+
51
+ settings.load({
52
+ "VERSION": "2",
53
+ "endpoints": [
54
+ {
55
+ "id": "openai-default",
56
+ "api_base": "https://api.openai.com/v1",
57
+ "api_key": "sk-...",
58
+ }
59
+ ],
60
+ "backends": {
61
+ "openai": {
62
+ "models": {
63
+ "gpt-4o": {
64
+ "id": "gpt-4o",
65
+ "endpoints": ["openai-default"],
66
+ }
67
+ }
68
+ }
69
+ }
70
+ })
71
+ ```
72
+
73
+ ### Sync
74
+
75
+ ```python
76
+ from vv_llm.chat_clients import create_chat_client, BackendType
77
+
78
+ client = create_chat_client(BackendType.OpenAI, model="gpt-4o")
79
+ resp = client.create_completion([
80
+ {"role": "user", "content": "Explain RAG in one sentence"}
81
+ ])
82
+ print(resp.content)
83
+ ```
84
+
85
+ ### Streaming
86
+
87
+ ```python
88
+ for chunk in client.create_stream([
89
+ {"role": "user", "content": "Write a haiku"}
90
+ ]):
91
+ if chunk.content:
92
+ print(chunk.content, end="")
93
+ ```
94
+
95
+ ### Async
96
+
97
+ ```python
98
+ import asyncio
99
+ from vv_llm.chat_clients import create_async_chat_client, BackendType
100
+
101
+ async def main():
102
+ client = create_async_chat_client(BackendType.OpenAI, model="gpt-4o")
103
+ resp = await client.create_completion([
104
+ {"role": "user", "content": "hello"}
105
+ ])
106
+ print(resp.content)
107
+
108
+ asyncio.run(main())
109
+ ```
110
+
111
+ ## Features
112
+
113
+ - **Unified interface** — same `create_completion` / `create_stream` API across all providers
114
+ - **Type-safe factory** — `create_chat_client(BackendType.X)` returns the correct client type
115
+ - **Multi-endpoint** — configure multiple endpoints per backend with random selection and failover
116
+ - **Tool calling** — normalized tool/function calling across providers
117
+ - **Multimodal** — text + image inputs where supported
118
+ - **Thinking/reasoning** — access chain-of-thought from Claude, DeepSeek Reasoner, etc.
119
+ - **Token counting** — per-model tokenizers (tiktoken, deepseek-tokenizer, qwen-tokenizer)
120
+ - **Rate limiting** — RPM/TPM controls with memory, Redis, or DiskCache backends
121
+ - **Context length control** — automatic message truncation to fit model limits
122
+ - **Prompt caching** — Anthropic prompt caching support
123
+ - **Retry with backoff** — configurable retry logic for transient failures
124
+
125
+ ## Utilities
126
+
127
+ ```python
128
+ from vv_llm.chat_clients import format_messages, get_token_counts, get_message_token_counts
129
+ ```
130
+
131
+ | Function | Description |
132
+ |---|---|
133
+ | `format_messages` | Normalize multimodal/tool messages across formats |
134
+ | `get_token_counts` | Count tokens for a text string |
135
+ | `get_message_token_counts` | Count tokens for a message list |
136
+
137
+ ## Optional Dependencies
138
+
139
+ ```bash
140
+ pip install 'vv-llm[redis]' # Redis rate limiting
141
+ pip install 'vv-llm[diskcache]' # DiskCache rate limiting
142
+ pip install 'vv-llm[server]' # FastAPI token server
143
+ pip install 'vv-llm[vertex]' # Google Vertex AI
144
+ pip install 'vv-llm[bedrock]' # AWS Bedrock
145
+ ```
146
+
147
+ ## Project Structure
148
+
149
+ ```
150
+ src/vv_llm/
151
+ chat_clients/ # Per-backend clients + factory
152
+ settings/ # Configuration management
153
+ types/ # Type definitions & enums
154
+ utilities/ # Rate limiting, retry, media processing, token counting
155
+ server/ # Optional token counting server
156
+
157
+ tests/unit/ # Unit tests
158
+ tests/live/ # Live integration tests (requires real API keys)
159
+ ```
160
+
161
+ ## Development
162
+
163
+ ```bash
164
+ pdm install -d # Install dev dependencies
165
+ pdm run lint # Ruff linter
166
+ pdm run format-check # Ruff format check
167
+ pdm run type-check # Ty type checker
168
+ pdm run test # Unit tests
169
+ pdm run test-live # Live tests (needs real endpoints)
170
+ ```
171
+
172
+ ## License
173
+
174
+ MIT
@@ -0,0 +1,145 @@
1
+ # vv-llm
2
+
3
+ Universal LLM interface layer for Python. One API, 16 backends, sync & async.
4
+
5
+ ```
6
+ pip install vv-llm
7
+ ```
8
+
9
+ ## Supported Backends
10
+
11
+ OpenAI | Anthropic | DeepSeek | Gemini | Qwen | Groq | Mistral | Moonshot | MiniMax | Yi | ZhiPuAI | Baichuan | StepFun | xAI | Ernie | Local
12
+
13
+ Also supports Azure OpenAI, Vertex AI, and AWS Bedrock deployments.
14
+
15
+ ## Quick Start
16
+
17
+ ### Configure
18
+
19
+ ```python
20
+ from vv_llm.settings import settings
21
+
22
+ settings.load({
23
+ "VERSION": "2",
24
+ "endpoints": [
25
+ {
26
+ "id": "openai-default",
27
+ "api_base": "https://api.openai.com/v1",
28
+ "api_key": "sk-...",
29
+ }
30
+ ],
31
+ "backends": {
32
+ "openai": {
33
+ "models": {
34
+ "gpt-4o": {
35
+ "id": "gpt-4o",
36
+ "endpoints": ["openai-default"],
37
+ }
38
+ }
39
+ }
40
+ }
41
+ })
42
+ ```
43
+
44
+ ### Sync
45
+
46
+ ```python
47
+ from vv_llm.chat_clients import create_chat_client, BackendType
48
+
49
+ client = create_chat_client(BackendType.OpenAI, model="gpt-4o")
50
+ resp = client.create_completion([
51
+ {"role": "user", "content": "Explain RAG in one sentence"}
52
+ ])
53
+ print(resp.content)
54
+ ```
55
+
56
+ ### Streaming
57
+
58
+ ```python
59
+ for chunk in client.create_stream([
60
+ {"role": "user", "content": "Write a haiku"}
61
+ ]):
62
+ if chunk.content:
63
+ print(chunk.content, end="")
64
+ ```
65
+
66
+ ### Async
67
+
68
+ ```python
69
+ import asyncio
70
+ from vv_llm.chat_clients import create_async_chat_client, BackendType
71
+
72
+ async def main():
73
+ client = create_async_chat_client(BackendType.OpenAI, model="gpt-4o")
74
+ resp = await client.create_completion([
75
+ {"role": "user", "content": "hello"}
76
+ ])
77
+ print(resp.content)
78
+
79
+ asyncio.run(main())
80
+ ```
81
+
82
+ ## Features
83
+
84
+ - **Unified interface** — same `create_completion` / `create_stream` API across all providers
85
+ - **Type-safe factory** — `create_chat_client(BackendType.X)` returns the correct client type
86
+ - **Multi-endpoint** — configure multiple endpoints per backend with random selection and failover
87
+ - **Tool calling** — normalized tool/function calling across providers
88
+ - **Multimodal** — text + image inputs where supported
89
+ - **Thinking/reasoning** — access chain-of-thought from Claude, DeepSeek Reasoner, etc.
90
+ - **Token counting** — per-model tokenizers (tiktoken, deepseek-tokenizer, qwen-tokenizer)
91
+ - **Rate limiting** — RPM/TPM controls with memory, Redis, or DiskCache backends
92
+ - **Context length control** — automatic message truncation to fit model limits
93
+ - **Prompt caching** — Anthropic prompt caching support
94
+ - **Retry with backoff** — configurable retry logic for transient failures
95
+
96
+ ## Utilities
97
+
98
+ ```python
99
+ from vv_llm.chat_clients import format_messages, get_token_counts, get_message_token_counts
100
+ ```
101
+
102
+ | Function | Description |
103
+ |---|---|
104
+ | `format_messages` | Normalize multimodal/tool messages across formats |
105
+ | `get_token_counts` | Count tokens for a text string |
106
+ | `get_message_token_counts` | Count tokens for a message list |
107
+
108
+ ## Optional Dependencies
109
+
110
+ ```bash
111
+ pip install 'vv-llm[redis]' # Redis rate limiting
112
+ pip install 'vv-llm[diskcache]' # DiskCache rate limiting
113
+ pip install 'vv-llm[server]' # FastAPI token server
114
+ pip install 'vv-llm[vertex]' # Google Vertex AI
115
+ pip install 'vv-llm[bedrock]' # AWS Bedrock
116
+ ```
117
+
118
+ ## Project Structure
119
+
120
+ ```
121
+ src/vv_llm/
122
+ chat_clients/ # Per-backend clients + factory
123
+ settings/ # Configuration management
124
+ types/ # Type definitions & enums
125
+ utilities/ # Rate limiting, retry, media processing, token counting
126
+ server/ # Optional token counting server
127
+
128
+ tests/unit/ # Unit tests
129
+ tests/live/ # Live integration tests (requires real API keys)
130
+ ```
131
+
132
+ ## Development
133
+
134
+ ```bash
135
+ pdm install -d # Install dev dependencies
136
+ pdm run lint # Ruff linter
137
+ pdm run format-check # Ruff format check
138
+ pdm run type-check # Ty type checker
139
+ pdm run test # Unit tests
140
+ pdm run test-live # Live tests (needs real endpoints)
141
+ ```
142
+
143
+ ## License
144
+
145
+ MIT
@@ -0,0 +1,118 @@
1
+ [project]
2
+ authors = [
3
+ { name = "Anderson", email = "andersonby@163.com" },
4
+ ]
5
+ dependencies = [
6
+ "openai>=1.99.3",
7
+ "tiktoken>=0.7.0",
8
+ "httpx>=0.27.0",
9
+ "anthropic>=0.47.1",
10
+ "pydantic>=2.8.2",
11
+ "Pillow>=10.4.0",
12
+ "deepseek-tokenizer>=0.1.0",
13
+ "qwen-tokenizer>=0.2.0",
14
+ ]
15
+ description = "Universal LLM interfaces for multi-provider chat and utilities"
16
+ name = "vv-llm"
17
+ readme = "README.md"
18
+ requires-python = ">=3.10"
19
+ version = "0.3.73"
20
+
21
+ [project.license]
22
+ text = "MIT"
23
+
24
+ [project.optional-dependencies]
25
+ bedrock = [
26
+ "boto3 >= 1.28.57",
27
+ "botocore >= 1.31.57",
28
+ ]
29
+ diskcache = [
30
+ "diskcache",
31
+ ]
32
+ redis = [
33
+ "redis",
34
+ ]
35
+ server = [
36
+ "fastapi",
37
+ "uvicorn",
38
+ ]
39
+ vertex = [
40
+ "google-auth>=2.35.0",
41
+ ]
42
+
43
+ [build-system]
44
+ build-backend = "pdm.backend"
45
+ requires = [
46
+ "pdm-backend",
47
+ ]
48
+
49
+ [tool.pdm]
50
+ distribution = true
51
+
52
+ [tool.pdm.build]
53
+ excludes = [
54
+ "tests",
55
+ ]
56
+
57
+ [tool.pdm.scripts]
58
+ format = "ruff format src/"
59
+ format-check = "ruff format --check src/"
60
+ lint = "ruff check src/"
61
+ type-check = "ty check src/ --output-format concise --exit-zero"
62
+
63
+ [tool.pdm.scripts.check-all]
64
+ composite = [
65
+ "lint",
66
+ "format-check",
67
+ "type-check",
68
+ ]
69
+
70
+ [tool.pdm.scripts.test]
71
+ cmd = "pytest tests/unit"
72
+ env_file = ".env"
73
+
74
+ [tool.pdm.scripts.test-live]
75
+ cmd = "python tests/live/run_live_tests.py"
76
+
77
+ [tool.pdm.scripts.test-live.env]
78
+ VV_LLM_RUN_LIVE_TESTS = "1"
79
+
80
+ [tool.ruff]
81
+ line-length = 180
82
+ target-version = "py310"
83
+
84
+ [tool.ruff.lint]
85
+ select = [
86
+ "E",
87
+ "W",
88
+ "F",
89
+ "I",
90
+ "B",
91
+ "C4",
92
+ "UP",
93
+ ]
94
+ ignore = [
95
+ "E501",
96
+ "I001",
97
+ ]
98
+
99
+ [tool.ruff.format]
100
+ indent-style = "space"
101
+ line-ending = "auto"
102
+ quote-style = "double"
103
+
104
+ [tool.pytest.ini_options]
105
+ pythonpath = [
106
+ "tests",
107
+ ]
108
+ testpaths = [
109
+ "tests/unit",
110
+ ]
111
+
112
+ [dependency-groups]
113
+ dev = [
114
+ "types-redis>=4.6.0.20241004",
115
+ "pytest>=8.3.4",
116
+ "ruff>=0.8.0",
117
+ "ty>=0.0.1a24",
118
+ ]
@@ -0,0 +1 @@
1
+