qx-llms 0.1.7__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.
qx_llms-0.1.7/PKG-INFO ADDED
@@ -0,0 +1,242 @@
1
+ Metadata-Version: 2.4
2
+ Name: qx-llms
3
+ Version: 0.1.7
4
+ Summary: A simple LLM client factory utility for use across QX applications
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: Operating System :: OS Independent
7
+ Requires-Python: >=3.12
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: langchain-core==1.2.7
10
+ Requires-Dist: langchain-community==0.4.1
11
+ Requires-Dist: langchain-openai==1.1.7
12
+ Requires-Dist: langchain-anthropic==1.3.1
13
+ Requires-Dist: langchain-google-genai==4.2.0
14
+ Requires-Dist: langchain-deepseek==1.0.1
15
+ Requires-Dist: langchain-ollama==1.0.1
16
+ Requires-Dist: openai-agents
17
+ Requires-Dist: pydantic
18
+ Provides-Extra: test
19
+ Requires-Dist: pytest; extra == "test"
20
+ Requires-Dist: pytest-asyncio; extra == "test"
21
+
22
+ # qx-llms
23
+
24
+ A unified LLM client factory and model registry for use across QX applications. Provides a consistent interface for working with multiple LLM providers through both LangChain and OpenAI Agents SDK.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pip install qx-llms
30
+ ```
31
+
32
+ Or install from source:
33
+
34
+ ```bash
35
+ pip install -e .
36
+ ```
37
+
38
+ ## Features
39
+
40
+ - **Multi-provider support** - OpenAI, Anthropic, Google Gemini, DeepSeek, and more
41
+ - **Two factory interfaces** - LangChain clients and OpenAI Agents SDK models
42
+ - **Model registry** - Centralized model definitions with capabilities and credit costs
43
+ - **Fake models for testing** - Mock implementations that don't make API calls
44
+ - **Graceful fallbacks** - Optional silent failure with dummy models
45
+
46
+ ## Quick Start
47
+
48
+ ### LangChain Factory
49
+
50
+ ```python
51
+ from qx_llms.factories.langchain_client_factory import get_llm_client, get_embeddings_client
52
+
53
+ # Get a chat model
54
+ llm = get_llm_client(model_name="gpt-4o", provider="openai")
55
+ response = llm.invoke("Hello, world!")
56
+
57
+ # Get an embeddings model
58
+ embeddings = get_embeddings_client(model_name="text-embedding-3-small", provider="openai")
59
+ vectors = embeddings.embed_query("Hello, world!")
60
+ ```
61
+
62
+ ### OpenAI Agents Factory
63
+
64
+ ```python
65
+ from qx_llms.factories.openai_client_factory import get_openai_agents_model
66
+
67
+ # Get a model for use with OpenAI Agents SDK
68
+ model = get_openai_agents_model(provider="openai", model_name="gpt-4o")
69
+ ```
70
+
71
+ ### Model Registry
72
+
73
+ ```python
74
+ from qx_llms.model_registry import (
75
+ get_llm_by_name,
76
+ get_llm_options,
77
+ get_llm_credit_mapping,
78
+ get_embedding_by_name,
79
+ get_embedding_options,
80
+ ModelProvider,
81
+ )
82
+
83
+ # Get a specific chat model's details
84
+ model = get_llm_by_name("gpt-4o")
85
+ print(model.name, model.provider, model.credits)
86
+
87
+ # Get all chat models with specific capabilities
88
+ options = get_llm_options(
89
+ providers=[ModelProvider.OPENAI, ModelProvider.ANTHROPIC],
90
+ structured_output=True,
91
+ tool_use=True,
92
+ )
93
+
94
+ # Get credit costs for billing
95
+ credits = get_llm_credit_mapping(credit_multiplier=2)
96
+
97
+ # Get a specific embedding model's details
98
+ embedding = get_embedding_by_name("text-embedding-3-large")
99
+ print(embedding.name, embedding.dimensions, embedding.multimodal)
100
+
101
+ # Get all embedding models with specific capabilities
102
+ embedding_options = get_embedding_options(
103
+ providers=[ModelProvider.OPENAI],
104
+ dimensions=1536,
105
+ )
106
+ ```
107
+
108
+ ## Supported Providers
109
+
110
+ ### LangChain Factory
111
+
112
+ | Provider | Environment Variables | Description |
113
+ |----------|----------------------|-------------|
114
+ | `openai` | `OPENAI_API_KEY` | OpenAI API |
115
+ | `azure_openai` | `AZURE_OPENAI_API_KEY`, `AZURE_OPENAI_ENDPOINT` | Azure OpenAI |
116
+ | `anthropic` | `ANTHROPIC_API_KEY` | Anthropic Claude |
117
+ | `gemini` | `GEMINI_API_KEY` | Google Gemini |
118
+ | `deepseek` | `DEEPSEEK_API_KEY` | DeepSeek |
119
+ | `openai_endpoint` | `OPENAI_ENDPOINT_API_KEY`, `OPENAI_ENDPOINT_BASE_URL` | Custom OpenAI-compatible endpoint |
120
+ | `ollama` | `OLLAMA_BASE_URL` (optional) | Local Ollama |
121
+ | `lmstudio` | `LMSTUDIO_BASE_URL` (optional) | Local LM Studio |
122
+ | `fake` | None | Fake model for testing |
123
+
124
+ ### OpenAI Agents Factory
125
+
126
+ | Provider | Environment Variables | Description |
127
+ |----------|----------------------|-------------|
128
+ | `openai` | `OPENAI_API_KEY` | OpenAI Responses API |
129
+ | `deepseek` | `DEEPSEEK_API_KEY` | DeepSeek |
130
+ | `openrouter` | `OPENROUTER_API_KEY` | OpenRouter |
131
+ | `gemini` | `GEMINI_API_KEY` | Google Gemini |
132
+ | `anthropic` | `ANTHROPIC_API_KEY` | Anthropic |
133
+ | `perplexity` | `PERPLEXITY_API_KEY` | Perplexity |
134
+ | `huggingface` | `HUGGINGFACE_API_KEY` | Hugging Face Inference |
135
+ | `local` | `LOCAL_MODEL_URL` | Local models (Ollama, etc.) |
136
+ | `azure_openai` | `AZURE_OPENAI_API_KEY`, `AZURE_OPENAI_ENDPOINT` | Azure OpenAI |
137
+ | `fake` | None | Fake model for testing |
138
+
139
+ ## Testing with Fake Models
140
+
141
+ Both factories provide fake models that return static responses without making API calls:
142
+
143
+ ```python
144
+ # LangChain fake model
145
+ from qx_llms.factories.langchain_client_factory import get_llm_client
146
+
147
+ fake_llm = get_llm_client(model_name="fake", provider="fake")
148
+
149
+ # OpenAI Agents fake model
150
+ from qx_llms.factories.openai_client_factory import get_openai_agents_model
151
+
152
+ fake_model = get_openai_agents_model(provider="fake")
153
+ response = await fake_model.get_response(...) # Returns "fake response"
154
+ ```
155
+
156
+ ## Model Registry
157
+
158
+ The model registry provides a centralized definition of available models with their capabilities.
159
+
160
+ ### Chat Models
161
+
162
+ ```python
163
+ from qx_llms.model_registry import ChatModel, ModelProvider
164
+
165
+ # Each chat model has these attributes:
166
+ # - name: str - Model identifier (e.g., "gpt-4o")
167
+ # - provider: ModelProvider - Provider enum
168
+ # - structured_output: bool - Supports JSON schema output
169
+ # - tool_use: bool - Supports function calling
170
+ # - vision: bool - Supports image input
171
+ # - accepts_temperature: bool - Supports temperature parameter
172
+ # - credits: int - Base credit cost per request
173
+ ```
174
+
175
+ ### Embedding Models
176
+
177
+ ```python
178
+ from qx_llms.model_registry import EmbeddingModel, ModelProvider
179
+
180
+ # Each embedding model has these attributes:
181
+ # - name: str - Model identifier (e.g., "text-embedding-3-large")
182
+ # - provider: ModelProvider - Provider enum
183
+ # - credits: int - Base credit cost per request
184
+ # - dimensions: int - Output vector size (768, 1536, 3072, etc.)
185
+ # - multimodal: bool - Can embed images (e.g., CLIP, OpenAI multimodal)
186
+ ```
187
+
188
+ ### Filtering Chat Models
189
+
190
+ ```python
191
+ from qx_llms.model_registry import get_llm_options, ModelProvider
192
+
193
+ # Get only models that support structured output and vision
194
+ models = get_llm_options(
195
+ structured_output=True,
196
+ vision=True,
197
+ )
198
+
199
+ # Get models from specific providers
200
+ openai_models = get_llm_options(providers=[ModelProvider.OPENAI])
201
+ ```
202
+
203
+ ### Filtering Embedding Models
204
+
205
+ ```python
206
+ from qx_llms.model_registry import get_embedding_options, ModelProvider
207
+
208
+ # Get only embedding models with specific dimensions
209
+ models = get_embedding_options(dimensions=1536)
210
+
211
+ # Get multimodal embedding models
212
+ multimodal_models = get_embedding_options(multimodal=True)
213
+
214
+ # Get embedding models from specific providers
215
+ openai_embeddings = get_embedding_options(providers=[ModelProvider.OPENAI])
216
+ ```
217
+
218
+ ## Error Handling
219
+
220
+ Both factories support graceful fallbacks:
221
+
222
+ ```python
223
+ # Raises ValueError if provider is invalid or API key is missing
224
+ llm = get_llm_client(model_name="gpt-4o", provider="openai", fail_silently=False)
225
+
226
+ # Returns a dummy model instead of raising
227
+ llm = get_llm_client(model_name="gpt-4o", provider="openai", fail_silently=True)
228
+ ```
229
+
230
+ ## Development
231
+
232
+ ### Running Tests
233
+
234
+ ```bash
235
+ pip install -e ".[test]"
236
+ pytest tests/ -v
237
+ ```
238
+
239
+ ## Requirements
240
+
241
+ - Python >= 3.12
242
+ - See `requirements.txt` for dependencies
@@ -0,0 +1,221 @@
1
+ # qx-llms
2
+
3
+ A unified LLM client factory and model registry for use across QX applications. Provides a consistent interface for working with multiple LLM providers through both LangChain and OpenAI Agents SDK.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install qx-llms
9
+ ```
10
+
11
+ Or install from source:
12
+
13
+ ```bash
14
+ pip install -e .
15
+ ```
16
+
17
+ ## Features
18
+
19
+ - **Multi-provider support** - OpenAI, Anthropic, Google Gemini, DeepSeek, and more
20
+ - **Two factory interfaces** - LangChain clients and OpenAI Agents SDK models
21
+ - **Model registry** - Centralized model definitions with capabilities and credit costs
22
+ - **Fake models for testing** - Mock implementations that don't make API calls
23
+ - **Graceful fallbacks** - Optional silent failure with dummy models
24
+
25
+ ## Quick Start
26
+
27
+ ### LangChain Factory
28
+
29
+ ```python
30
+ from qx_llms.factories.langchain_client_factory import get_llm_client, get_embeddings_client
31
+
32
+ # Get a chat model
33
+ llm = get_llm_client(model_name="gpt-4o", provider="openai")
34
+ response = llm.invoke("Hello, world!")
35
+
36
+ # Get an embeddings model
37
+ embeddings = get_embeddings_client(model_name="text-embedding-3-small", provider="openai")
38
+ vectors = embeddings.embed_query("Hello, world!")
39
+ ```
40
+
41
+ ### OpenAI Agents Factory
42
+
43
+ ```python
44
+ from qx_llms.factories.openai_client_factory import get_openai_agents_model
45
+
46
+ # Get a model for use with OpenAI Agents SDK
47
+ model = get_openai_agents_model(provider="openai", model_name="gpt-4o")
48
+ ```
49
+
50
+ ### Model Registry
51
+
52
+ ```python
53
+ from qx_llms.model_registry import (
54
+ get_llm_by_name,
55
+ get_llm_options,
56
+ get_llm_credit_mapping,
57
+ get_embedding_by_name,
58
+ get_embedding_options,
59
+ ModelProvider,
60
+ )
61
+
62
+ # Get a specific chat model's details
63
+ model = get_llm_by_name("gpt-4o")
64
+ print(model.name, model.provider, model.credits)
65
+
66
+ # Get all chat models with specific capabilities
67
+ options = get_llm_options(
68
+ providers=[ModelProvider.OPENAI, ModelProvider.ANTHROPIC],
69
+ structured_output=True,
70
+ tool_use=True,
71
+ )
72
+
73
+ # Get credit costs for billing
74
+ credits = get_llm_credit_mapping(credit_multiplier=2)
75
+
76
+ # Get a specific embedding model's details
77
+ embedding = get_embedding_by_name("text-embedding-3-large")
78
+ print(embedding.name, embedding.dimensions, embedding.multimodal)
79
+
80
+ # Get all embedding models with specific capabilities
81
+ embedding_options = get_embedding_options(
82
+ providers=[ModelProvider.OPENAI],
83
+ dimensions=1536,
84
+ )
85
+ ```
86
+
87
+ ## Supported Providers
88
+
89
+ ### LangChain Factory
90
+
91
+ | Provider | Environment Variables | Description |
92
+ |----------|----------------------|-------------|
93
+ | `openai` | `OPENAI_API_KEY` | OpenAI API |
94
+ | `azure_openai` | `AZURE_OPENAI_API_KEY`, `AZURE_OPENAI_ENDPOINT` | Azure OpenAI |
95
+ | `anthropic` | `ANTHROPIC_API_KEY` | Anthropic Claude |
96
+ | `gemini` | `GEMINI_API_KEY` | Google Gemini |
97
+ | `deepseek` | `DEEPSEEK_API_KEY` | DeepSeek |
98
+ | `openai_endpoint` | `OPENAI_ENDPOINT_API_KEY`, `OPENAI_ENDPOINT_BASE_URL` | Custom OpenAI-compatible endpoint |
99
+ | `ollama` | `OLLAMA_BASE_URL` (optional) | Local Ollama |
100
+ | `lmstudio` | `LMSTUDIO_BASE_URL` (optional) | Local LM Studio |
101
+ | `fake` | None | Fake model for testing |
102
+
103
+ ### OpenAI Agents Factory
104
+
105
+ | Provider | Environment Variables | Description |
106
+ |----------|----------------------|-------------|
107
+ | `openai` | `OPENAI_API_KEY` | OpenAI Responses API |
108
+ | `deepseek` | `DEEPSEEK_API_KEY` | DeepSeek |
109
+ | `openrouter` | `OPENROUTER_API_KEY` | OpenRouter |
110
+ | `gemini` | `GEMINI_API_KEY` | Google Gemini |
111
+ | `anthropic` | `ANTHROPIC_API_KEY` | Anthropic |
112
+ | `perplexity` | `PERPLEXITY_API_KEY` | Perplexity |
113
+ | `huggingface` | `HUGGINGFACE_API_KEY` | Hugging Face Inference |
114
+ | `local` | `LOCAL_MODEL_URL` | Local models (Ollama, etc.) |
115
+ | `azure_openai` | `AZURE_OPENAI_API_KEY`, `AZURE_OPENAI_ENDPOINT` | Azure OpenAI |
116
+ | `fake` | None | Fake model for testing |
117
+
118
+ ## Testing with Fake Models
119
+
120
+ Both factories provide fake models that return static responses without making API calls:
121
+
122
+ ```python
123
+ # LangChain fake model
124
+ from qx_llms.factories.langchain_client_factory import get_llm_client
125
+
126
+ fake_llm = get_llm_client(model_name="fake", provider="fake")
127
+
128
+ # OpenAI Agents fake model
129
+ from qx_llms.factories.openai_client_factory import get_openai_agents_model
130
+
131
+ fake_model = get_openai_agents_model(provider="fake")
132
+ response = await fake_model.get_response(...) # Returns "fake response"
133
+ ```
134
+
135
+ ## Model Registry
136
+
137
+ The model registry provides a centralized definition of available models with their capabilities.
138
+
139
+ ### Chat Models
140
+
141
+ ```python
142
+ from qx_llms.model_registry import ChatModel, ModelProvider
143
+
144
+ # Each chat model has these attributes:
145
+ # - name: str - Model identifier (e.g., "gpt-4o")
146
+ # - provider: ModelProvider - Provider enum
147
+ # - structured_output: bool - Supports JSON schema output
148
+ # - tool_use: bool - Supports function calling
149
+ # - vision: bool - Supports image input
150
+ # - accepts_temperature: bool - Supports temperature parameter
151
+ # - credits: int - Base credit cost per request
152
+ ```
153
+
154
+ ### Embedding Models
155
+
156
+ ```python
157
+ from qx_llms.model_registry import EmbeddingModel, ModelProvider
158
+
159
+ # Each embedding model has these attributes:
160
+ # - name: str - Model identifier (e.g., "text-embedding-3-large")
161
+ # - provider: ModelProvider - Provider enum
162
+ # - credits: int - Base credit cost per request
163
+ # - dimensions: int - Output vector size (768, 1536, 3072, etc.)
164
+ # - multimodal: bool - Can embed images (e.g., CLIP, OpenAI multimodal)
165
+ ```
166
+
167
+ ### Filtering Chat Models
168
+
169
+ ```python
170
+ from qx_llms.model_registry import get_llm_options, ModelProvider
171
+
172
+ # Get only models that support structured output and vision
173
+ models = get_llm_options(
174
+ structured_output=True,
175
+ vision=True,
176
+ )
177
+
178
+ # Get models from specific providers
179
+ openai_models = get_llm_options(providers=[ModelProvider.OPENAI])
180
+ ```
181
+
182
+ ### Filtering Embedding Models
183
+
184
+ ```python
185
+ from qx_llms.model_registry import get_embedding_options, ModelProvider
186
+
187
+ # Get only embedding models with specific dimensions
188
+ models = get_embedding_options(dimensions=1536)
189
+
190
+ # Get multimodal embedding models
191
+ multimodal_models = get_embedding_options(multimodal=True)
192
+
193
+ # Get embedding models from specific providers
194
+ openai_embeddings = get_embedding_options(providers=[ModelProvider.OPENAI])
195
+ ```
196
+
197
+ ## Error Handling
198
+
199
+ Both factories support graceful fallbacks:
200
+
201
+ ```python
202
+ # Raises ValueError if provider is invalid or API key is missing
203
+ llm = get_llm_client(model_name="gpt-4o", provider="openai", fail_silently=False)
204
+
205
+ # Returns a dummy model instead of raising
206
+ llm = get_llm_client(model_name="gpt-4o", provider="openai", fail_silently=True)
207
+ ```
208
+
209
+ ## Development
210
+
211
+ ### Running Tests
212
+
213
+ ```bash
214
+ pip install -e ".[test]"
215
+ pytest tests/ -v
216
+ ```
217
+
218
+ ## Requirements
219
+
220
+ - Python >= 3.12
221
+ - See `requirements.txt` for dependencies
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "qx-llms"
7
+ version = "0.1.7"
8
+ description = "A simple LLM client factory utility for use across QX applications"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ classifiers = [
12
+ "Programming Language :: Python :: 3",
13
+ "Operating System :: OS Independent",
14
+ ]
15
+ dynamic = ["dependencies"]
16
+
17
+ [project.optional-dependencies]
18
+ test = [
19
+ "pytest",
20
+ "pytest-asyncio",
21
+ ]
22
+
23
+ [tool.setuptools.dynamic]
24
+ dependencies = {file = ["requirements.txt"]}
25
+
26
+ [tool.setuptools.packages.find]
27
+ where = ["."]
28
+ include = ["qx_llms*"]
29
+
30
+ [tool.pytest.ini_options]
31
+ asyncio_mode = "strict"
32
+ asyncio_default_fixture_loop_scope = "function"
File without changes