llm-gemini 0.14__tar.gz → 0.14.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: llm-gemini
3
- Version: 0.14
3
+ Version: 0.14.1
4
4
  Summary: LLM plugin to access Google's Gemini family of models
5
5
  Author: Simon Willison
6
6
  License: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: llm-gemini
3
- Version: 0.14
3
+ Version: 0.14.1
4
4
  Summary: LLM plugin to access Google's Gemini family of models
5
5
  Author: Simon Willison
6
6
  License: Apache-2.0
@@ -88,18 +88,24 @@ def resolve_type(attachment):
88
88
  return mime_type
89
89
 
90
90
 
91
- def cleanup_schema(schema):
91
+ def cleanup_schema(schema, in_properties=False):
92
92
  "Gemini supports only a subset of JSON schema"
93
93
  keys_to_remove = ("$schema", "additionalProperties", "title")
94
- # Recursively remove them
94
+
95
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)
96
+ # Only remove keys if we're not inside a 'properties' block.
97
+ if not in_properties:
98
+ for key in keys_to_remove:
99
+ schema.pop(key, None)
100
+ for key, value in list(schema.items()):
101
+ # If the key is 'properties', set the flag for its value.
102
+ if key == "properties" and isinstance(value, dict):
103
+ cleanup_schema(value, in_properties=True)
104
+ else:
105
+ cleanup_schema(value, in_properties=in_properties)
100
106
  elif isinstance(schema, list):
101
- for value in schema:
102
- cleanup_schema(value)
107
+ for item in schema:
108
+ cleanup_schema(item, in_properties=in_properties)
103
109
  return schema
104
110
 
105
111
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "llm-gemini"
3
- version = "0.14"
3
+ version = "0.14.1"
4
4
  description = "LLM plugin to access Google's Gemini family of models"
5
5
  readme = "README.md"
6
6
  authors = [{name = "Simon Willison"}]
@@ -25,3 +25,7 @@ gemini = "llm_gemini"
25
25
 
26
26
  [project.optional-dependencies]
27
27
  test = ["pytest", "pytest-recording", "pytest-asyncio", "nest-asyncio"]
28
+
29
+ [tool.pytest.ini_options]
30
+ asyncio_mode = "strict"
31
+ asyncio_default_fixture_loop_scope = "function"
@@ -4,6 +4,7 @@ import json
4
4
  import os
5
5
  import pytest
6
6
  import pydantic
7
+ from llm_gemini import cleanup_schema
7
8
 
8
9
  nest_asyncio.apply()
9
10
 
@@ -123,3 +124,89 @@ def test_embedding(model_id, monkeypatch):
123
124
  elif model_id.endswith("-512"):
124
125
  expected_length = 512
125
126
  assert len(response) == expected_length
127
+
128
+
129
+ @pytest.mark.parametrize(
130
+ "schema,expected",
131
+ [
132
+ # Test 1: Top-level keys removal
133
+ (
134
+ {
135
+ "$schema": "http://json-schema.org/draft-07/schema#",
136
+ "title": "Example Schema",
137
+ "additionalProperties": False,
138
+ "type": "object",
139
+ },
140
+ {"type": "object"},
141
+ ),
142
+ # Test 2: Preserve keys within a "properties" block
143
+ (
144
+ {
145
+ "type": "object",
146
+ "properties": {
147
+ "authors": {"type": "string"},
148
+ "title": {"type": "string"},
149
+ "reference": {"type": "string"},
150
+ "year": {"type": "string"},
151
+ },
152
+ "title": "This should be removed from the top-level",
153
+ },
154
+ {
155
+ "type": "object",
156
+ "properties": {
157
+ "authors": {"type": "string"},
158
+ "title": {"type": "string"},
159
+ "reference": {"type": "string"},
160
+ "year": {"type": "string"},
161
+ },
162
+ },
163
+ ),
164
+ # Test 3: Nested keys outside and inside properties block
165
+ (
166
+ {
167
+ "definitions": {
168
+ "info": {
169
+ "title": "Info title", # should be removed because it's not inside a "properties" block
170
+ "description": "A description",
171
+ "properties": {
172
+ "name": {
173
+ "title": "Name Title",
174
+ "type": "string",
175
+ }, # title here should be preserved
176
+ "$schema": {
177
+ "type": "string"
178
+ }, # should be preserved as it's within properties
179
+ },
180
+ }
181
+ },
182
+ "$schema": "http://example.com/schema",
183
+ },
184
+ {
185
+ "definitions": {
186
+ "info": {
187
+ "description": "A description",
188
+ "properties": {
189
+ "name": {"title": "Name Title", "type": "string"},
190
+ "$schema": {"type": "string"},
191
+ },
192
+ }
193
+ }
194
+ },
195
+ ),
196
+ # Test 4: List of schemas
197
+ (
198
+ [
199
+ {
200
+ "$schema": "http://json-schema.org/draft-07/schema#",
201
+ "type": "object",
202
+ },
203
+ {"title": "Should be removed", "type": "array"},
204
+ ],
205
+ [{"type": "object"}, {"type": "array"}],
206
+ ),
207
+ ],
208
+ )
209
+ def test_cleanup_schema(schema, expected):
210
+ # Use a deep copy so the original test data remains unchanged.
211
+ result = cleanup_schema(schema)
212
+ assert result == expected
File without changes
File without changes
File without changes