Skip to content

Commit c1b277c

Browse files
committed
Fix failing tests.
PiperOrigin-RevId: 829447863
1 parent c4dc642 commit c1b277c

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

genai_processors/content_api.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def from_function_response(
375375
function_response = genai_types.FunctionResponse(
376376
response={response_key: response}, **function_response_args
377377
)
378-
function_response.json()
378+
function_response.model_dump_json()
379379
except ValueError:
380380
# Response is not JSON serializable. Then try to construct content.
381381
response_content = ProcessorContent(response)
@@ -386,8 +386,11 @@ def from_function_response(
386386
)
387387
except ValueError:
388388
parts = [
389-
genai_types.FunctionResponsePart.from_bytes(
390-
data=part.bytes, mime_type=part.mimetype
389+
genai_types.FunctionResponsePart(
390+
inline_data=genai_types.FunctionResponseBlob(
391+
data=part.bytes,
392+
mime_type=part.mimetype,
393+
)
391394
)
392395
for part in response_content
393396
]

genai_processors/tests/content_api_test.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,17 @@ def test_from_function_response_with_mixed_content(self):
132132
genai_types.FunctionResponse(
133133
name='foo',
134134
parts=[
135-
genai_types.FunctionResponsePart.from_bytes(
136-
data=b'Here is a black cat in a black room: ',
137-
mime_type='text/plain',
135+
genai_types.FunctionResponsePart(
136+
inline_data=genai_types.FunctionResponseBlob(
137+
data=b'Here is a black cat in a black room: ',
138+
mime_type='text/plain',
139+
),
138140
),
139-
genai_types.FunctionResponsePart.from_bytes(
140-
data=image_bytes, mime_type='image/png'
141+
genai_types.FunctionResponsePart(
142+
inline_data=genai_types.FunctionResponseBlob(
143+
data=image_bytes,
144+
mime_type='image/png',
145+
),
141146
),
142147
],
143148
),

genai_processors/tests/sql_cache_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def setUp(self):
3030
async def test_cache_put_and_lookup(self):
3131
"""Tests basic put and lookup functionality."""
3232
async with sql_cache.sql_cache(self.db_url) as cache:
33-
await cache.put(TEST_QUERY, TEST_VALUE)
33+
await cache.put(query=TEST_QUERY, value=TEST_VALUE)
3434
result = await cache.lookup(TEST_QUERY)
3535
self.assertEqual(result, TEST_VALUE)
3636

@@ -45,15 +45,15 @@ async def test_cache_ttl(self):
4545
async with sql_cache.sql_cache(
4646
self.db_url, ttl_hours=0.0001 / 60 / 60
4747
) as cache: # Very short TTL
48-
await cache.put(TEST_QUERY, TEST_VALUE)
48+
await cache.put(query=TEST_QUERY, value=TEST_VALUE)
4949
await asyncio.sleep(0.0002) # Wait for TTL to expire
5050
result = await cache.lookup(TEST_QUERY)
5151
self.assertIs(result, cache_base.CacheMiss)
5252

5353
async def test_cache_remove(self):
5454
"""Tests removing an item from the cache."""
5555
async with sql_cache.sql_cache(self.db_url) as cache:
56-
await cache.put(TEST_QUERY, TEST_VALUE)
56+
await cache.put(query=TEST_QUERY, value=TEST_VALUE)
5757
await cache.remove(TEST_QUERY)
5858
result = await cache.lookup(TEST_QUERY)
5959
self.assertIs(result, cache_base.CacheMiss)
@@ -63,8 +63,8 @@ async def test_with_key_prefix(self):
6363
async with sql_cache.sql_cache(self.db_url) as cache1:
6464
cache2 = cache1.with_key_prefix('prefix:')
6565

66-
await cache1.put(TEST_QUERY, TEST_VALUE)
67-
await cache2.put(TEST_QUERY, TEST_VALUE_2)
66+
await cache1.put(query=TEST_QUERY, value=TEST_VALUE)
67+
await cache2.put(query=TEST_QUERY, value=TEST_VALUE_2)
6868

6969
result1 = await cache1.lookup(TEST_QUERY)
7070
result2 = await cache2.lookup(TEST_QUERY)
@@ -84,16 +84,16 @@ async def test_different_content_types(self):
8484

8585
value2 = content_api.ProcessorContent({'a': 1, 'b': True})
8686

87-
await cache.put(query1, value1)
88-
await cache.put(query2, value2)
87+
await cache.put(query=query1, value=value1)
88+
await cache.put(query=query2, value=value2)
8989

9090
self.assertEqual(await cache.lookup(query1), value1)
9191
self.assertEqual(await cache.lookup(query2), value2)
9292

9393
async def test_cleanup_expired(self):
9494
"""Tests that the _cleanup_expired method removes old entries."""
9595
async with sql_cache.sql_cache(self.db_url, ttl_hours=0.0001) as cache:
96-
await cache.put(TEST_QUERY, TEST_VALUE)
96+
await cache.put(query=TEST_QUERY, value=TEST_VALUE)
9797
# Mock datetime to control time
9898
with mock.patch('genai_processors.sql_cache.datetime') as mock_datetime:
9999
mock_datetime.datetime.now.return_value = datetime.datetime.now(

0 commit comments

Comments
 (0)