-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: when converting the llm_request to JSON, skip non-serializable data #879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stephensmithnewfront
wants to merge
6
commits into
google:main
Choose a base branch
from
stephensmithnewfront:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+66
−1
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b781880
Telemetry unit test for non-serializable data.
stephensmithnewfront 179da9d
When converting the llm_request to JSON, skip non-serializable data.
stephensmithnewfront caf533b
Merge branch 'main' into main
stephensmithnewfront e821ae9
Merge branch 'main' into main
stephensmithnewfront 5dc68f4
Update _create_invocation_context() return type to InvocationContext.
stephensmithnewfront 23a33f7
Oops, remove unnecessary import.
stephensmithnewfront File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from typing import Any | ||
from typing import Optional | ||
|
||
from google.adk.sessions import InMemorySessionService | ||
from google.adk.agents.invocation_context import InvocationContext | ||
from google.adk.agents.readonly_context import ReadonlyContext | ||
from google.adk.agents.llm_agent import LlmAgent | ||
from google.adk.models.llm_request import LlmRequest | ||
from google.adk.models.llm_response import LlmResponse | ||
from google.adk.telemetry import trace_call_llm | ||
from google.genai import types | ||
import pytest | ||
|
||
|
||
async def _create_invocation_context( | ||
agent: LlmAgent, state: Optional[dict[str, Any]] = None | ||
) -> InvocationContext: | ||
session_service = InMemorySessionService() | ||
session = await session_service.create_session( | ||
app_name='test_app', user_id='test_user', state=state | ||
) | ||
invocation_context = InvocationContext( | ||
invocation_id='test_id', | ||
agent=agent, | ||
session=session, | ||
session_service=session_service, | ||
) | ||
return invocation_context | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_trace_call_llm_function_response_includes_part_from_bytes(): | ||
agent = LlmAgent(name='test_agent') | ||
invocation_context = await _create_invocation_context(agent) | ||
llm_request = LlmRequest( | ||
contents=[ | ||
types.Content( | ||
role="user", | ||
parts=[ | ||
types.Part.from_function_response( | ||
name="test_function_1", | ||
response={ | ||
"result": b"test_data", | ||
}, | ||
), | ||
], | ||
), | ||
types.Content( | ||
role="user", | ||
parts=[ | ||
types.Part.from_function_response( | ||
name="test_function_2", | ||
response={ | ||
"result": types.Part.from_bytes(data=b"test_data", mime_type="application/octet-stream"), | ||
}, | ||
), | ||
], | ||
), | ||
], | ||
config=types.GenerateContentConfig(system_instruction=""), | ||
) | ||
llm_response = LlmResponse(turn_complete=True) | ||
trace_call_llm(invocation_context, 'test_event_id', llm_request, llm_response) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: import not needed anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, good catch; fixed