llm-gemini 0.12__tar.gz → 0.13__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: llm-gemini
3
- Version: 0.12
3
+ Version: 0.13
4
4
  Summary: LLM plugin to access Google's Gemini family of models
5
5
  Author: Simon Willison
6
6
  License: Apache-2.0
@@ -11,7 +11,7 @@ Project-URL: CI, https://github.com/simonw/llm-gemini/actions
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: llm>=0.22
14
+ Requires-Dist: llm>=0.23
15
15
  Requires-Dist: httpx
16
16
  Requires-Dist: ijson
17
17
  Provides-Extra: test
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: llm-gemini
3
- Version: 0.12
3
+ Version: 0.13
4
4
  Summary: LLM plugin to access Google's Gemini family of models
5
5
  Author: Simon Willison
6
6
  License: Apache-2.0
@@ -11,7 +11,7 @@ Project-URL: CI, https://github.com/simonw/llm-gemini/actions
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: llm>=0.22
14
+ Requires-Dist: llm>=0.23
15
15
  Requires-Dist: httpx
16
16
  Requires-Dist: ijson
17
17
  Provides-Extra: test
@@ -1,4 +1,4 @@
1
- llm>=0.22
1
+ llm>=0.23
2
2
  httpx
3
3
  ijson
4
4
 
@@ -1,3 +1,4 @@
1
+ import copy
1
2
  import httpx
2
3
  import ijson
3
4
  import llm
@@ -64,8 +65,16 @@ def register_models(register):
64
65
  ]:
65
66
  can_google_search = model_id in GOOGLE_SEARCH_MODELS
66
67
  register(
67
- GeminiPro(model_id, can_google_search=can_google_search),
68
- AsyncGeminiPro(model_id, can_google_search=can_google_search),
68
+ GeminiPro(
69
+ model_id,
70
+ can_google_search=can_google_search,
71
+ can_schema="flash-thinking" not in model_id,
72
+ ),
73
+ AsyncGeminiPro(
74
+ model_id,
75
+ can_google_search=can_google_search,
76
+ can_schema="flash-thinking" not in model_id,
77
+ ),
69
78
  )
70
79
 
71
80
 
@@ -79,10 +88,26 @@ def resolve_type(attachment):
79
88
  return mime_type
80
89
 
81
90
 
91
+ def cleanup_schema(schema):
92
+ "Gemini supports only a subset of JSON schema"
93
+ keys_to_remove = ("$schema", "additionalProperties")
94
+ # Recursively remove them
95
+ if isinstance(schema, dict):
96
+ for key in keys_to_remove:
97
+ schema.pop(key, None)
98
+ for value in schema.values():
99
+ cleanup_schema(value)
100
+ elif isinstance(schema, list):
101
+ for value in schema:
102
+ cleanup_schema(value)
103
+ return schema
104
+
105
+
82
106
  class _SharedGemini:
83
107
  needs_key = "gemini"
84
108
  key_env_var = "LLM_GEMINI_KEY"
85
109
  can_stream = True
110
+ supports_schema = True
86
111
 
87
112
  attachment_types = (
88
113
  # Text
@@ -169,9 +194,10 @@ class _SharedGemini:
169
194
  default=None,
170
195
  )
171
196
 
172
- def __init__(self, model_id, can_google_search=False):
197
+ def __init__(self, model_id, can_google_search=False, can_schema=False):
173
198
  self.model_id = model_id
174
199
  self.can_google_search = can_google_search
200
+ self.supports_schema = can_schema
175
201
  if can_google_search:
176
202
  self.Options = self.OptionsWithGoogleSearch
177
203
 
@@ -226,6 +252,12 @@ class _SharedGemini:
226
252
  if prompt.system:
227
253
  body["systemInstruction"] = {"parts": [{"text": prompt.system}]}
228
254
 
255
+ if prompt.schema:
256
+ body["generationConfig"] = {
257
+ "response_mime_type": "application/json",
258
+ "response_schema": cleanup_schema(copy.deepcopy(prompt.schema)),
259
+ }
260
+
229
261
  config_map = {
230
262
  "temperature": "temperature",
231
263
  "max_output_tokens": "maxOutputTokens",
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "llm-gemini"
3
- version = "0.12"
3
+ version = "0.13"
4
4
  description = "LLM plugin to access Google's Gemini family of models"
5
5
  readme = "README.md"
6
6
  authors = [{name = "Simon Willison"}]
@@ -9,7 +9,7 @@ classifiers = [
9
9
  "License :: OSI Approved :: Apache Software License"
10
10
  ]
11
11
  dependencies = [
12
- "llm>=0.22",
12
+ "llm>=0.23",
13
13
  "httpx",
14
14
  "ijson"
15
15
  ]
File without changes
File without changes
File without changes