llm-gemini 0.12__py3-none-any.whl → 0.13a0__py3-none-any.whl

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.13a0
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.23a0
15
15
  Requires-Dist: httpx
16
16
  Requires-Dist: ijson
17
17
  Provides-Extra: test
@@ -0,0 +1,7 @@
1
+ llm_gemini.py,sha256=M4_OIzaF3ytfrCdQ_md9sS6ViDN38JlP9aaykY5Ct0E,13634
2
+ llm_gemini-0.13a0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
3
+ llm_gemini-0.13a0.dist-info/METADATA,sha256=_SbfjPGKz4M4Wfvd6p8zyx37qOF99R-aTBxGQ0lnGHY,7018
4
+ llm_gemini-0.13a0.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
5
+ llm_gemini-0.13a0.dist-info/entry_points.txt,sha256=n544bpgUPIBc5l_cnwsTxPc3gMGJHPtAyqBNp-CkMWk,26
6
+ llm_gemini-0.13a0.dist-info/top_level.txt,sha256=WUQmG6_2QKbT_8W4HH93qyKl_0SUteL4Ra6_PhyNGKU,11
7
+ llm_gemini-0.13a0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.1)
2
+ Generator: setuptools (75.8.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
llm_gemini.py CHANGED
@@ -1,3 +1,4 @@
1
+ import copy
1
2
  import httpx
2
3
  import ijson
3
4
  import llm
@@ -79,10 +80,26 @@ def resolve_type(attachment):
79
80
  return mime_type
80
81
 
81
82
 
83
+ def cleanup_schema(schema):
84
+ "Gemini supports only a subset of JSON schema"
85
+ keys_to_remove = ("$schema", "additionalProperties")
86
+ # Recursively remove them
87
+ if isinstance(schema, dict):
88
+ for key in keys_to_remove:
89
+ schema.pop(key, None)
90
+ for value in schema.values():
91
+ cleanup_schema(value)
92
+ elif isinstance(schema, list):
93
+ for value in schema:
94
+ cleanup_schema(value)
95
+ return schema
96
+
97
+
82
98
  class _SharedGemini:
83
99
  needs_key = "gemini"
84
100
  key_env_var = "LLM_GEMINI_KEY"
85
101
  can_stream = True
102
+ supports_schema = True
86
103
 
87
104
  attachment_types = (
88
105
  # Text
@@ -226,6 +243,12 @@ class _SharedGemini:
226
243
  if prompt.system:
227
244
  body["systemInstruction"] = {"parts": [{"text": prompt.system}]}
228
245
 
246
+ if prompt.schema:
247
+ body["generationConfig"] = {
248
+ "response_mime_type": "application/json",
249
+ "response_schema": cleanup_schema(copy.deepcopy(prompt.schema)),
250
+ }
251
+
229
252
  config_map = {
230
253
  "temperature": "temperature",
231
254
  "max_output_tokens": "maxOutputTokens",
@@ -1,7 +0,0 @@
1
- llm_gemini.py,sha256=er-6W-CJEOZdC0O6iBYkWsAstlYhtYASkQUXfqhE7Wk,12916
2
- llm_gemini-0.12.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
3
- llm_gemini-0.12.dist-info/METADATA,sha256=CKh9OfBqO_Ep7NU2eyGMnkDyuqwnOaBA-geYJpCugac,7014
4
- llm_gemini-0.12.dist-info/WHEEL,sha256=nn6H5-ilmfVryoAQl3ZQ2l8SH5imPWFpm1A5FgEuFV4,91
5
- llm_gemini-0.12.dist-info/entry_points.txt,sha256=n544bpgUPIBc5l_cnwsTxPc3gMGJHPtAyqBNp-CkMWk,26
6
- llm_gemini-0.12.dist-info/top_level.txt,sha256=WUQmG6_2QKbT_8W4HH93qyKl_0SUteL4Ra6_PhyNGKU,11
7
- llm_gemini-0.12.dist-info/RECORD,,