You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: migrate from Vertex AI models to Google Gemini models (#14)
- Replace VertexAI model classes with GeminiModel for Google AI integration
- Update exception naming: ModelNotDerivedError → ResponseNotDerivedError
- Replace poetry with uv for dependency management
- Update model references throughout codebase and tests
- Refactor language_models module to use google-genai package
- Update documentation to reflect new model structure
- Remove poetry.lock and add uv.lock for new package manager
BREAKING CHANGES:
- Vertex AI models (VertexAIChatModel, VertexAIGenerativeModel, VertexAITextGenerationModel) removed
- Exception class renamed from ModelNotDerivedError to ResponseNotDerivedError
- Package manager changed from poetry to uv
- Google AI models now use GeminiModel instead of Vertex AI classes
Copy file name to clipboardExpand all lines: README.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,14 +3,12 @@
3
3
</p>
4
4
5
5
# Modelsmith
6
-
### Modelsmith is a Python library that allows you to get structured responses in the form of Pydantic models and Python types from Anthropic, Google Vertex AI, and OpenAI models.
6
+
### Modelsmith is a Python library that allows you to get structured responses in the form of Pydantic models and Python types from Anthropic, Google Gemini, and OpenAI models.
7
7
8
8
Currently it allows you to use the following classes of model:
9
-
-__AnthropicModel__ (used with Anthropic's set of models such as `claude-3-haiku`, `claude-3-sonnet`, `claude-3-opus` and `claude-3_5-sonnet`)
10
-
-__OpenAIModel__ (used with OpenAI's set of models such as `gpt-3.5-turbo`, `gpt-4` and `gpt-4o`)
11
-
-__VertexAIChatModel__ (used with Google Vertex AI's chat models such as `chat-bison`)
12
-
-__VertexAITextGenerationModel__ (used with Google Vertex AI's text generation models such as `text-bison`)
13
-
-__VertexAIGenerativeModel__ (used with Google Vertex AI's generative models such as `gemini-pro`)
9
+
-__AnthropicModel__ (used with Anthropic's full set of models)
10
+
-__OpenAIModel__ (used with OpenAI's full set of models)
11
+
-__GeminiModel__ (used with Google's full set of Gemini models)
14
12
15
13
Modelsmith provides a unified interface over all of these. It has been designed to be extensible and can adapt to other models in the future.
Modelsmith does not restrict you to either Pydantic models or Python types. You can combine them in the same response. Below we extract a list of Pydantic model instances.
32
32
33
33
```python
34
-
from modelsmith import Forge, VertexAIGenerativeModel
34
+
from modelsmith import Forge, GeminiModel
35
35
from pydantic import BaseModel, Field
36
36
37
37
@@ -42,7 +42,7 @@ class City(BaseModel):
42
42
43
43
# Pass a list of Pydantic models to the response_model argument.
Using a different model is as simple as passing the desired model class to the Forge. Taking the example above lets use `text-bison` instead of `gemini-pro`.
56
+
Using a different model is as simple as passing the desired model class to the Forge. Taking the example above lets use `gemini-2.5-flash` instead of `gemini-2.5-pro`.
57
57
58
58
```python
59
-
from modelsmith import Forge, VertexAITextGenerationModel# import the correct class
59
+
from modelsmith import Forge, GeminiModel# import the correct class
60
60
from pydantic import BaseModel, Field
61
61
62
62
@@ -65,9 +65,9 @@ class City(BaseModel):
65
65
state: str= Field(description="2-letter abbreviation of the state")
66
66
67
67
68
-
#text-bison instead of gemini-pro
68
+
#gemini-2.5-flash instead of gemini-2.5-pro
69
69
forge = Forge(
70
-
model=VertexAITextGenerationModel("text-bison"),
70
+
model=GeminiModel("gemini-2.5-flash"),
71
71
response_model=list[City],
72
72
)
73
73
@@ -76,7 +76,7 @@ response = forge.generate("I have lived in Irvine, CA and Dallas TX")
If we want to use an Anthropic model the same applies. Simply select the appropriate model class, specify which Anthropic model to use (in this case `claude-3-haiku-20240307`), and pass it to the `Forge` instance.
79
+
If we want to use an Anthropic model the same applies. Simply select the appropriate model class, specify which Anthropic model to use (in this case `claude-sonnet-4-20250514`), and pass it to the `Forge` instance.
80
80
81
81
```python
82
82
from modelsmith import Forge, AnthropicModel # import the correct class
@@ -88,9 +88,9 @@ class City(BaseModel):
88
88
state: str= Field(description="2-letter abbreviation of the state")
89
89
90
90
91
-
# Anthropic's claude-3-haiku-20240307 instead of gemini-pro
91
+
# Anthropic's claude-sonnet-4-20250514 instead of gemini-2.5-flash
92
92
forge = Forge(
93
-
model=AnthropicModel("claude-3-haiku-20240307"),
93
+
model=AnthropicModel("claude-sonnet-4-20250514"),
94
94
response_model=list[City],
95
95
)
96
96
@@ -110,7 +110,7 @@ from modelsmith import Forge, VertexAIGenerativeModel
@@ -234,7 +234,7 @@ Modelsmith looks for JSON output in the LLM response. It uses regular expression
234
234
235
235
## Failing silently
236
236
237
-
Modelsmith will raise a `ModelNotDerivedError` exception if no valid response was obtained. You can change this by passing `False` to the `raise_on_failure` parameter of the `Forge` class.
237
+
Modelsmith will raise a `ResponseNotDerivedError` exception if no valid response was obtained. You can change this by passing `False` to the `raise_on_failure` parameter of the `Forge` class.
238
238
239
239
This will suppress the exception and return `None` instead.
Copy file name to clipboardExpand all lines: docs/installation.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,11 @@ The `AnthropicModel` class takes an optional `api_key` parameter. If not provide
15
15
16
16
## Google Cloud Authentication
17
17
18
-
Authentication to Google Cloud is done via the Application Default Credentials flow. So make sure you have ADC configured. See [Google's documentation](https://cloud.google.com/docs/authentication/provide-credentials-adc) for more details.
18
+
Authentication to Google Cloud is done via either:
19
+
- Application Default Credentials flow. See [Google's documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstart?usertype=adc) for more details.
20
+
- Gemini API Key. See [Google Gemini API docs](https://ai.google.dev/gemini-api/docs/api-key?_gl=1*1ya8hy4*_up*MQ..*_ga*MTA2MDc3MjY2MC4xNzU3NzkwNDQz*_ga_P1DBVKWT6V*czE3NTc3OTgwNTMkbzMkZzAkdDE3NTc3OTgwNTMkajYwJGwwJGgxMDQzMjc4MTU2).
21
+
22
+
The `GeminiModel` allows you to pass the `vertexai`, `api_key`, `project`, and `location` when you initialize the class instance. If you do not pass this in it will be inferred from the environment variables `GOOGLE_GENAI_USE_VERTEXAI`, `GOOGLE_API_KEY`, `GOOGLE_CLOUD_PROJECT`, and `GOOGLE_CLOUD_LOCATION` as per the documentation.
19
23
20
24
## Open AI Authentication
21
25
Authentication to OpenAI is done via the OpenAI flow. See the [OpenAI documentation](https://platform.openai.com/docs/quickstart/step-2-set-up-your-api-key) for more details.
0 commit comments