model-forge-llm 0.2.0__tar.gz → 0.2.1__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.
- model_forge_llm-0.2.1/PKG-INFO +314 -0
- model_forge_llm-0.2.1/README.md +251 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/pyproject.toml +1 -1
- model_forge_llm-0.2.1/src/model_forge_llm.egg-info/PKG-INFO +314 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/modelforge/__init__.py +1 -1
- model_forge_llm-0.2.0/PKG-INFO +0 -327
- model_forge_llm-0.2.0/README.md +0 -264
- model_forge_llm-0.2.0/src/model_forge_llm.egg-info/PKG-INFO +0 -327
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/CODE_REVIEW_GUIDELINES.md +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/CONTRIBUTING.md +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/LICENSE +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/MANIFEST.in +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/setup.cfg +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/model_forge_llm.egg-info/SOURCES.txt +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/model_forge_llm.egg-info/dependency_links.txt +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/model_forge_llm.egg-info/entry_points.txt +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/model_forge_llm.egg-info/requires.txt +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/model_forge_llm.egg-info/top_level.txt +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/modelforge/auth.py +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/modelforge/cli.py +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/modelforge/config.py +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/modelforge/exceptions.py +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/modelforge/logging_config.py +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/modelforge/modelsdev.py +0 -0
- {model_forge_llm-0.2.0 → model_forge_llm-0.2.1}/src/modelforge/registry.py +0 -0
@@ -0,0 +1,314 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: model-forge-llm
|
3
|
+
Version: 0.2.1
|
4
|
+
Summary: A reusable library for managing LLM providers, authentication, and model selection.
|
5
|
+
Author: ModelForge Contributors
|
6
|
+
License: MIT License
|
7
|
+
|
8
|
+
Copyright (c) 2025 Shuhai Miao
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
12
|
+
in the Software without restriction, including without limitation the rights
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
15
|
+
furnished to do so, subject to the following conditions:
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
18
|
+
copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
26
|
+
SOFTWARE.
|
27
|
+
|
28
|
+
Project-URL: Homepage, https://github.com/your-org/model-forge
|
29
|
+
Project-URL: Repository, https://github.com/your-org/model-forge
|
30
|
+
Project-URL: Issues, https://github.com/your-org/model-forge/issues
|
31
|
+
Project-URL: Documentation, https://model-forge.readthedocs.io
|
32
|
+
Keywords: llm,ai,langchain,openai,ollama,providers,authentication
|
33
|
+
Classifier: Development Status :: 4 - Beta
|
34
|
+
Classifier: Intended Audience :: Developers
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
36
|
+
Classifier: Operating System :: OS Independent
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
40
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
41
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
42
|
+
Requires-Python: <4.0,>=3.11
|
43
|
+
Description-Content-Type: text/markdown
|
44
|
+
License-File: LICENSE
|
45
|
+
Requires-Dist: click>=8.1.7
|
46
|
+
Requires-Dist: requests>=2.32.3
|
47
|
+
Requires-Dist: langchain-core>=0.3.0
|
48
|
+
Requires-Dist: langchain-openai>=0.3.0
|
49
|
+
Requires-Dist: langchain-community>=0.3.0
|
50
|
+
Requires-Dist: langchain-google-genai>=2.1.5
|
51
|
+
Requires-Dist: langchain-github-copilot>=0.4.0
|
52
|
+
Provides-Extra: dev
|
53
|
+
Requires-Dist: pytest>=8.2.2; extra == "dev"
|
54
|
+
Requires-Dist: pytest-mock>=3.14.0; extra == "dev"
|
55
|
+
Requires-Dist: ruff>=0.7.0; extra == "dev"
|
56
|
+
Requires-Dist: mypy>=1.11.0; extra == "dev"
|
57
|
+
Requires-Dist: pre-commit>=3.8.0; extra == "dev"
|
58
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
|
59
|
+
Requires-Dist: types-requests>=2.32.0; extra == "dev"
|
60
|
+
Requires-Dist: twine>=6.1.0; extra == "dev"
|
61
|
+
Requires-Dist: requests-mock>=1.12.1; extra == "dev"
|
62
|
+
Dynamic: license-file
|
63
|
+
|
64
|
+
# ModelForge
|
65
|
+
|
66
|
+
A Python library for managing LLM providers, authentication, and model selection with seamless LangChain integration.
|
67
|
+
|
68
|
+
## Installation
|
69
|
+
|
70
|
+
### Recommended: Virtual Environment
|
71
|
+
```bash
|
72
|
+
# Create and activate virtual environment
|
73
|
+
python -m venv model-forge-env
|
74
|
+
source model-forge-env/bin/activate # On Windows: model-forge-env\Scripts\activate
|
75
|
+
|
76
|
+
# Install package
|
77
|
+
pip install model-forge-llm
|
78
|
+
|
79
|
+
# Verify installation
|
80
|
+
modelforge --help
|
81
|
+
```
|
82
|
+
|
83
|
+
### Quick Install (System-wide)
|
84
|
+
```bash
|
85
|
+
pip install model-forge-llm
|
86
|
+
```
|
87
|
+
|
88
|
+
## Quick Start
|
89
|
+
|
90
|
+
### Option 1: GitHub Copilot via Device Authentication Flow
|
91
|
+
```bash
|
92
|
+
# Discover GitHub Copilot models
|
93
|
+
modelforge models list --provider github_copilot
|
94
|
+
|
95
|
+
# Set up GitHub Copilot with device authentication
|
96
|
+
modelforge auth login --provider github_copilot
|
97
|
+
|
98
|
+
# Select Claude 3.7 Sonnet via GitHub Copilot
|
99
|
+
modelforge config use --provider github_copilot --model claude-3.7-sonnet
|
100
|
+
|
101
|
+
# Test your setup
|
102
|
+
modelforge test --prompt "Write a Python function to reverse a string"
|
103
|
+
```
|
104
|
+
|
105
|
+
### Option 2: OpenAI (API Key Required)
|
106
|
+
```bash
|
107
|
+
# Add OpenAI with your API key
|
108
|
+
modelforge auth login --provider openai --api-key YOUR_API_KEY
|
109
|
+
|
110
|
+
# Select GPT-4o-mini
|
111
|
+
modelforge config use --provider openai --model gpt-4o-mini
|
112
|
+
|
113
|
+
# Test your setup
|
114
|
+
modelforge test --prompt "Hello, world!"
|
115
|
+
```
|
116
|
+
|
117
|
+
### Option 3: Local Ollama (No API Key Needed)
|
118
|
+
```bash
|
119
|
+
# Make sure Ollama is running locally
|
120
|
+
# Then add a local model
|
121
|
+
modelforge config add --provider ollama --model qwen3:1.7b
|
122
|
+
|
123
|
+
# Select the local model
|
124
|
+
modelforge config use --provider ollama --model qwen3:1.7b
|
125
|
+
|
126
|
+
# Test your setup
|
127
|
+
modelforge test --prompt "What is machine learning?"
|
128
|
+
```
|
129
|
+
|
130
|
+
### Common Commands - Complete Lifecycle
|
131
|
+
```bash
|
132
|
+
# Installation & Setup
|
133
|
+
modelforge --help # Verify installation
|
134
|
+
modelforge config show # View current config
|
135
|
+
|
136
|
+
# Model Discovery & Selection
|
137
|
+
modelforge models list # List all available models
|
138
|
+
modelforge models search "claude" # Search models by name
|
139
|
+
modelforge models info --provider openai --model gpt-4o # Get model details
|
140
|
+
|
141
|
+
# Authentication Management
|
142
|
+
modelforge auth login --provider openai --api-key KEY # API key auth
|
143
|
+
modelforge auth login --provider github_copilot # Device flow auth
|
144
|
+
modelforge auth status # Check auth status
|
145
|
+
modelforge auth logout --provider openai # Remove credentials
|
146
|
+
|
147
|
+
# Configuration Management
|
148
|
+
modelforge config add --provider openai --model gpt-4o-mini --api-key KEY
|
149
|
+
modelforge config add --provider ollama --model qwen3:1.7b --local
|
150
|
+
modelforge config use --provider openai --model gpt-4o-mini
|
151
|
+
modelforge config remove --provider openai --model gpt-4o-mini
|
152
|
+
|
153
|
+
# Testing & Usage
|
154
|
+
modelforge test --prompt "Hello, how are you?" # Test current model
|
155
|
+
modelforge test --prompt "Explain quantum computing" --verbose # Debug mode
|
156
|
+
|
157
|
+
# Cache & Maintenance
|
158
|
+
modelforge models list --refresh # Force refresh from models.dev
|
159
|
+
```
|
160
|
+
|
161
|
+
## Python API
|
162
|
+
|
163
|
+
### Basic Usage
|
164
|
+
|
165
|
+
```python
|
166
|
+
from modelforge.registry import ModelForgeRegistry
|
167
|
+
|
168
|
+
# Initialize registry
|
169
|
+
registry = ModelForgeRegistry()
|
170
|
+
|
171
|
+
# Get currently configured model
|
172
|
+
llm = registry.get_llm()
|
173
|
+
|
174
|
+
# Use directly with LangChain
|
175
|
+
from langchain_core.prompts import ChatPromptTemplate
|
176
|
+
|
177
|
+
prompt = ChatPromptTemplate.from_messages([("human", "{input}")])
|
178
|
+
chain = prompt | llm
|
179
|
+
response = chain.invoke({"input": "Tell me a joke"})
|
180
|
+
print(response)
|
181
|
+
```
|
182
|
+
|
183
|
+
### Advanced Usage
|
184
|
+
|
185
|
+
```python
|
186
|
+
from modelforge.registry import ModelForgeRegistry
|
187
|
+
|
188
|
+
# Initialize with debug logging
|
189
|
+
registry = ModelForgeRegistry(verbose=True)
|
190
|
+
|
191
|
+
# Get specific model by provider and name
|
192
|
+
llm = registry.get_llm(provider_name="openai", model_alias="gpt-4o-mini")
|
193
|
+
|
194
|
+
# Use with full LangChain features
|
195
|
+
from langchain_core.prompts import ChatPromptTemplate
|
196
|
+
from langchain_core.output_parsers import StrOutputParser
|
197
|
+
|
198
|
+
# Create complex chains
|
199
|
+
prompt = ChatPromptTemplate.from_template("Explain {topic} in simple terms")
|
200
|
+
chain = prompt | llm | StrOutputParser()
|
201
|
+
|
202
|
+
# Use with streaming
|
203
|
+
for chunk in chain.stream({"topic": "quantum computing"}):
|
204
|
+
print(chunk, end="", flush=True)
|
205
|
+
|
206
|
+
# Batch processing
|
207
|
+
questions = [
|
208
|
+
"What is machine learning?",
|
209
|
+
"Explain neural networks",
|
210
|
+
"How does backpropagation work?"
|
211
|
+
]
|
212
|
+
responses = chain.batch([{"topic": q} for q in questions])
|
213
|
+
```
|
214
|
+
|
215
|
+
### Configuration Management
|
216
|
+
|
217
|
+
```python
|
218
|
+
from modelforge import config
|
219
|
+
|
220
|
+
# Get current model selection
|
221
|
+
current = config.get_current_model()
|
222
|
+
print(f"Current: {current.get('provider')}/{current.get('model')}")
|
223
|
+
|
224
|
+
# Check if models are configured
|
225
|
+
if not current:
|
226
|
+
print("No model selected. Configure with:")
|
227
|
+
print("modelforge config add --provider openai --model gpt-4o-mini")
|
228
|
+
```
|
229
|
+
|
230
|
+
### Error Handling
|
231
|
+
|
232
|
+
```python
|
233
|
+
from modelforge.registry import ModelForgeRegistry
|
234
|
+
from modelforge.exceptions import ConfigurationError, ProviderError
|
235
|
+
|
236
|
+
try:
|
237
|
+
registry = ModelForgeRegistry()
|
238
|
+
llm = registry.get_llm()
|
239
|
+
response = llm.invoke("Hello world")
|
240
|
+
except ConfigurationError as e:
|
241
|
+
print(f"Configuration issue: {e}")
|
242
|
+
print("Run: modelforge config add --provider PROVIDER --model MODEL")
|
243
|
+
except ProviderError as e:
|
244
|
+
print(f"Provider error: {e}")
|
245
|
+
print("Check: modelforge auth status")
|
246
|
+
```
|
247
|
+
|
248
|
+
## Supported Providers
|
249
|
+
|
250
|
+
- **OpenAI**: GPT-4, GPT-4o, GPT-3.5-turbo
|
251
|
+
- **Google**: Gemini Pro, Gemini Flash
|
252
|
+
- **Ollama**: Local models (Llama, Qwen, Mistral)
|
253
|
+
- **GitHub Copilot**: Claude, GPT models via GitHub
|
254
|
+
|
255
|
+
## Authentication
|
256
|
+
|
257
|
+
ModelForge supports multiple authentication methods:
|
258
|
+
|
259
|
+
- **API Keys**: Store securely in configuration
|
260
|
+
- **Device Flow**: Browser-based OAuth for GitHub Copilot
|
261
|
+
- **No Auth**: For local models like Ollama
|
262
|
+
|
263
|
+
```bash
|
264
|
+
# API Key authentication
|
265
|
+
modelforge auth login --provider openai --api-key YOUR_KEY
|
266
|
+
|
267
|
+
# Device flow (GitHub Copilot)
|
268
|
+
modelforge auth login --provider github_copilot
|
269
|
+
|
270
|
+
# Check auth status
|
271
|
+
modelforge auth status
|
272
|
+
```
|
273
|
+
|
274
|
+
## Configuration
|
275
|
+
|
276
|
+
ModelForge uses a two-tier configuration system:
|
277
|
+
|
278
|
+
- **Global**: `~/.config/model-forge/config.json` (user-wide)
|
279
|
+
- **Local**: `./.model-forge/config.json` (project-specific)
|
280
|
+
|
281
|
+
Local config takes precedence over global when both exist.
|
282
|
+
|
283
|
+
## Model Discovery
|
284
|
+
|
285
|
+
```bash
|
286
|
+
# List all available models
|
287
|
+
modelforge models list
|
288
|
+
|
289
|
+
# Search models by name or capability
|
290
|
+
modelforge models search "gpt"
|
291
|
+
|
292
|
+
# Get detailed model info
|
293
|
+
modelforge models info --provider openai --model gpt-4o
|
294
|
+
```
|
295
|
+
|
296
|
+
## Development Setup
|
297
|
+
|
298
|
+
For contributors and developers:
|
299
|
+
|
300
|
+
```bash
|
301
|
+
git clone https://github.com/smiao-icims/model-forge.git
|
302
|
+
cd model-forge
|
303
|
+
poetry install
|
304
|
+
poetry run pytest
|
305
|
+
```
|
306
|
+
|
307
|
+
## Documentation
|
308
|
+
|
309
|
+
- [Models.dev](https://models.dev) - Comprehensive model reference
|
310
|
+
- [GitHub Issues](https://github.com/smiao-icims/model-forge/issues) - Support and bug reports
|
311
|
+
|
312
|
+
## License
|
313
|
+
|
314
|
+
MIT License - see LICENSE file for details.
|
@@ -0,0 +1,251 @@
|
|
1
|
+
# ModelForge
|
2
|
+
|
3
|
+
A Python library for managing LLM providers, authentication, and model selection with seamless LangChain integration.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### Recommended: Virtual Environment
|
8
|
+
```bash
|
9
|
+
# Create and activate virtual environment
|
10
|
+
python -m venv model-forge-env
|
11
|
+
source model-forge-env/bin/activate # On Windows: model-forge-env\Scripts\activate
|
12
|
+
|
13
|
+
# Install package
|
14
|
+
pip install model-forge-llm
|
15
|
+
|
16
|
+
# Verify installation
|
17
|
+
modelforge --help
|
18
|
+
```
|
19
|
+
|
20
|
+
### Quick Install (System-wide)
|
21
|
+
```bash
|
22
|
+
pip install model-forge-llm
|
23
|
+
```
|
24
|
+
|
25
|
+
## Quick Start
|
26
|
+
|
27
|
+
### Option 1: GitHub Copilot via Device Authentication Flow
|
28
|
+
```bash
|
29
|
+
# Discover GitHub Copilot models
|
30
|
+
modelforge models list --provider github_copilot
|
31
|
+
|
32
|
+
# Set up GitHub Copilot with device authentication
|
33
|
+
modelforge auth login --provider github_copilot
|
34
|
+
|
35
|
+
# Select Claude 3.7 Sonnet via GitHub Copilot
|
36
|
+
modelforge config use --provider github_copilot --model claude-3.7-sonnet
|
37
|
+
|
38
|
+
# Test your setup
|
39
|
+
modelforge test --prompt "Write a Python function to reverse a string"
|
40
|
+
```
|
41
|
+
|
42
|
+
### Option 2: OpenAI (API Key Required)
|
43
|
+
```bash
|
44
|
+
# Add OpenAI with your API key
|
45
|
+
modelforge auth login --provider openai --api-key YOUR_API_KEY
|
46
|
+
|
47
|
+
# Select GPT-4o-mini
|
48
|
+
modelforge config use --provider openai --model gpt-4o-mini
|
49
|
+
|
50
|
+
# Test your setup
|
51
|
+
modelforge test --prompt "Hello, world!"
|
52
|
+
```
|
53
|
+
|
54
|
+
### Option 3: Local Ollama (No API Key Needed)
|
55
|
+
```bash
|
56
|
+
# Make sure Ollama is running locally
|
57
|
+
# Then add a local model
|
58
|
+
modelforge config add --provider ollama --model qwen3:1.7b
|
59
|
+
|
60
|
+
# Select the local model
|
61
|
+
modelforge config use --provider ollama --model qwen3:1.7b
|
62
|
+
|
63
|
+
# Test your setup
|
64
|
+
modelforge test --prompt "What is machine learning?"
|
65
|
+
```
|
66
|
+
|
67
|
+
### Common Commands - Complete Lifecycle
|
68
|
+
```bash
|
69
|
+
# Installation & Setup
|
70
|
+
modelforge --help # Verify installation
|
71
|
+
modelforge config show # View current config
|
72
|
+
|
73
|
+
# Model Discovery & Selection
|
74
|
+
modelforge models list # List all available models
|
75
|
+
modelforge models search "claude" # Search models by name
|
76
|
+
modelforge models info --provider openai --model gpt-4o # Get model details
|
77
|
+
|
78
|
+
# Authentication Management
|
79
|
+
modelforge auth login --provider openai --api-key KEY # API key auth
|
80
|
+
modelforge auth login --provider github_copilot # Device flow auth
|
81
|
+
modelforge auth status # Check auth status
|
82
|
+
modelforge auth logout --provider openai # Remove credentials
|
83
|
+
|
84
|
+
# Configuration Management
|
85
|
+
modelforge config add --provider openai --model gpt-4o-mini --api-key KEY
|
86
|
+
modelforge config add --provider ollama --model qwen3:1.7b --local
|
87
|
+
modelforge config use --provider openai --model gpt-4o-mini
|
88
|
+
modelforge config remove --provider openai --model gpt-4o-mini
|
89
|
+
|
90
|
+
# Testing & Usage
|
91
|
+
modelforge test --prompt "Hello, how are you?" # Test current model
|
92
|
+
modelforge test --prompt "Explain quantum computing" --verbose # Debug mode
|
93
|
+
|
94
|
+
# Cache & Maintenance
|
95
|
+
modelforge models list --refresh # Force refresh from models.dev
|
96
|
+
```
|
97
|
+
|
98
|
+
## Python API
|
99
|
+
|
100
|
+
### Basic Usage
|
101
|
+
|
102
|
+
```python
|
103
|
+
from modelforge.registry import ModelForgeRegistry
|
104
|
+
|
105
|
+
# Initialize registry
|
106
|
+
registry = ModelForgeRegistry()
|
107
|
+
|
108
|
+
# Get currently configured model
|
109
|
+
llm = registry.get_llm()
|
110
|
+
|
111
|
+
# Use directly with LangChain
|
112
|
+
from langchain_core.prompts import ChatPromptTemplate
|
113
|
+
|
114
|
+
prompt = ChatPromptTemplate.from_messages([("human", "{input}")])
|
115
|
+
chain = prompt | llm
|
116
|
+
response = chain.invoke({"input": "Tell me a joke"})
|
117
|
+
print(response)
|
118
|
+
```
|
119
|
+
|
120
|
+
### Advanced Usage
|
121
|
+
|
122
|
+
```python
|
123
|
+
from modelforge.registry import ModelForgeRegistry
|
124
|
+
|
125
|
+
# Initialize with debug logging
|
126
|
+
registry = ModelForgeRegistry(verbose=True)
|
127
|
+
|
128
|
+
# Get specific model by provider and name
|
129
|
+
llm = registry.get_llm(provider_name="openai", model_alias="gpt-4o-mini")
|
130
|
+
|
131
|
+
# Use with full LangChain features
|
132
|
+
from langchain_core.prompts import ChatPromptTemplate
|
133
|
+
from langchain_core.output_parsers import StrOutputParser
|
134
|
+
|
135
|
+
# Create complex chains
|
136
|
+
prompt = ChatPromptTemplate.from_template("Explain {topic} in simple terms")
|
137
|
+
chain = prompt | llm | StrOutputParser()
|
138
|
+
|
139
|
+
# Use with streaming
|
140
|
+
for chunk in chain.stream({"topic": "quantum computing"}):
|
141
|
+
print(chunk, end="", flush=True)
|
142
|
+
|
143
|
+
# Batch processing
|
144
|
+
questions = [
|
145
|
+
"What is machine learning?",
|
146
|
+
"Explain neural networks",
|
147
|
+
"How does backpropagation work?"
|
148
|
+
]
|
149
|
+
responses = chain.batch([{"topic": q} for q in questions])
|
150
|
+
```
|
151
|
+
|
152
|
+
### Configuration Management
|
153
|
+
|
154
|
+
```python
|
155
|
+
from modelforge import config
|
156
|
+
|
157
|
+
# Get current model selection
|
158
|
+
current = config.get_current_model()
|
159
|
+
print(f"Current: {current.get('provider')}/{current.get('model')}")
|
160
|
+
|
161
|
+
# Check if models are configured
|
162
|
+
if not current:
|
163
|
+
print("No model selected. Configure with:")
|
164
|
+
print("modelforge config add --provider openai --model gpt-4o-mini")
|
165
|
+
```
|
166
|
+
|
167
|
+
### Error Handling
|
168
|
+
|
169
|
+
```python
|
170
|
+
from modelforge.registry import ModelForgeRegistry
|
171
|
+
from modelforge.exceptions import ConfigurationError, ProviderError
|
172
|
+
|
173
|
+
try:
|
174
|
+
registry = ModelForgeRegistry()
|
175
|
+
llm = registry.get_llm()
|
176
|
+
response = llm.invoke("Hello world")
|
177
|
+
except ConfigurationError as e:
|
178
|
+
print(f"Configuration issue: {e}")
|
179
|
+
print("Run: modelforge config add --provider PROVIDER --model MODEL")
|
180
|
+
except ProviderError as e:
|
181
|
+
print(f"Provider error: {e}")
|
182
|
+
print("Check: modelforge auth status")
|
183
|
+
```
|
184
|
+
|
185
|
+
## Supported Providers
|
186
|
+
|
187
|
+
- **OpenAI**: GPT-4, GPT-4o, GPT-3.5-turbo
|
188
|
+
- **Google**: Gemini Pro, Gemini Flash
|
189
|
+
- **Ollama**: Local models (Llama, Qwen, Mistral)
|
190
|
+
- **GitHub Copilot**: Claude, GPT models via GitHub
|
191
|
+
|
192
|
+
## Authentication
|
193
|
+
|
194
|
+
ModelForge supports multiple authentication methods:
|
195
|
+
|
196
|
+
- **API Keys**: Store securely in configuration
|
197
|
+
- **Device Flow**: Browser-based OAuth for GitHub Copilot
|
198
|
+
- **No Auth**: For local models like Ollama
|
199
|
+
|
200
|
+
```bash
|
201
|
+
# API Key authentication
|
202
|
+
modelforge auth login --provider openai --api-key YOUR_KEY
|
203
|
+
|
204
|
+
# Device flow (GitHub Copilot)
|
205
|
+
modelforge auth login --provider github_copilot
|
206
|
+
|
207
|
+
# Check auth status
|
208
|
+
modelforge auth status
|
209
|
+
```
|
210
|
+
|
211
|
+
## Configuration
|
212
|
+
|
213
|
+
ModelForge uses a two-tier configuration system:
|
214
|
+
|
215
|
+
- **Global**: `~/.config/model-forge/config.json` (user-wide)
|
216
|
+
- **Local**: `./.model-forge/config.json` (project-specific)
|
217
|
+
|
218
|
+
Local config takes precedence over global when both exist.
|
219
|
+
|
220
|
+
## Model Discovery
|
221
|
+
|
222
|
+
```bash
|
223
|
+
# List all available models
|
224
|
+
modelforge models list
|
225
|
+
|
226
|
+
# Search models by name or capability
|
227
|
+
modelforge models search "gpt"
|
228
|
+
|
229
|
+
# Get detailed model info
|
230
|
+
modelforge models info --provider openai --model gpt-4o
|
231
|
+
```
|
232
|
+
|
233
|
+
## Development Setup
|
234
|
+
|
235
|
+
For contributors and developers:
|
236
|
+
|
237
|
+
```bash
|
238
|
+
git clone https://github.com/smiao-icims/model-forge.git
|
239
|
+
cd model-forge
|
240
|
+
poetry install
|
241
|
+
poetry run pytest
|
242
|
+
```
|
243
|
+
|
244
|
+
## Documentation
|
245
|
+
|
246
|
+
- [Models.dev](https://models.dev) - Comprehensive model reference
|
247
|
+
- [GitHub Issues](https://github.com/smiao-icims/model-forge/issues) - Support and bug reports
|
248
|
+
|
249
|
+
## License
|
250
|
+
|
251
|
+
MIT License - see LICENSE file for details.
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "model-forge-llm"
|
7
|
-
version = "0.2.
|
7
|
+
version = "0.2.1"
|
8
8
|
description = "A reusable library for managing LLM providers, authentication, and model selection."
|
9
9
|
readme = "README.md"
|
10
10
|
requires-python = ">=3.11,<4.0"
|