-
Notifications
You must be signed in to change notification settings - Fork 48
Rename metadata field to litellm_extra_body and add custom config support #837
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
15a72e6
Fix formatting issues from pre-commit hooks
openhands-agent 52c964f
Remove example file - was for demonstration only
openhands-agent 07e08c5
Fix test mock to use litellm_extra_body instead of metadata
openhands-agent b1d4ebc
Replace trivial tests with meaningful litellm integration test
openhands-agent c265c5f
Merge branch 'main' into rename-metadata-to-litellm-extra-body
li-boxuan 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
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
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
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,87 @@ | ||
| from openhands.sdk.llm import LLM | ||
|
|
||
|
|
||
| def test_llm_litellm_extra_body_default(): | ||
| """Test that litellm_extra_body field defaults to empty dict.""" | ||
| llm = LLM(model="gpt-4o", usage_id="test") | ||
| assert llm.litellm_extra_body == {} | ||
|
|
||
|
|
||
| def test_llm_litellm_extra_body_initialization(): | ||
| """Test litellm_extra_body field initialization with custom values.""" | ||
| custom_extra_body = { | ||
| "trace_version": "1.0.0", | ||
| "tags": ["model:gpt-4", "agent:my-agent"], | ||
| "session_id": "session-123", | ||
| "trace_user_id": "user-456", | ||
| } | ||
| llm = LLM(model="gpt-4o", usage_id="test", litellm_extra_body=custom_extra_body) | ||
| assert llm.litellm_extra_body == custom_extra_body | ||
|
|
||
|
|
||
| def test_llm_litellm_extra_body_modification(): | ||
| """Test that litellm_extra_body field can be modified after initialization.""" | ||
| llm = LLM(model="gpt-4o", usage_id="test") | ||
|
|
||
| # Start with empty litellm_extra_body | ||
| assert llm.litellm_extra_body == {} | ||
|
|
||
| # Add some extra body data | ||
| llm.litellm_extra_body["custom_key"] = "custom_value" | ||
| llm.litellm_extra_body["session_id"] = "session-123" | ||
|
|
||
| assert llm.litellm_extra_body["custom_key"] == "custom_value" | ||
| assert llm.litellm_extra_body["session_id"] == "session-123" | ||
|
||
|
|
||
|
|
||
| def test_llm_litellm_extra_body_complex_structure(): | ||
| """Test litellm_extra_body field with complex nested structure.""" | ||
| complex_extra_body = { | ||
| "trace_version": "2.1.0", | ||
| "tags": ["model:claude-3", "agent:coding-agent", "env:production"], | ||
| "session_info": { | ||
| "id": "session-789", | ||
| "user_id": "user-101", | ||
| "created_at": "2024-01-01T00:00:00Z", | ||
| }, | ||
| "metrics": { | ||
| "tokens_used": 1500, | ||
| "response_time_ms": 250, | ||
| }, | ||
| } | ||
| llm = LLM( | ||
| model="claude-3-5-sonnet", | ||
| usage_id="test", | ||
| litellm_extra_body=complex_extra_body, | ||
| ) | ||
| assert llm.litellm_extra_body == complex_extra_body | ||
|
|
||
| # Test nested access | ||
| assert llm.litellm_extra_body["session_info"]["id"] == "session-789" | ||
| assert llm.litellm_extra_body["metrics"]["tokens_used"] == 1500 | ||
|
|
||
|
|
||
| def test_llm_litellm_extra_body_for_custom_inference(): | ||
| """Test litellm_extra_body field for custom inference cluster use case.""" | ||
| # Example of custom metadata for logging/tracking/routing | ||
| inference_metadata = { | ||
| "cluster_id": "prod-cluster-1", | ||
| "routing_key": "high-priority", | ||
| "user_tier": "premium", | ||
| "request_id": "req-12345", | ||
| "experiment_id": "exp-abc123", | ||
| "custom_headers": { | ||
| "X-Custom-Auth": "bearer-token", | ||
| "X-Request-Source": "openhands-agent", | ||
| }, | ||
| } | ||
| llm = LLM(model="gpt-4o", usage_id="test", litellm_extra_body=inference_metadata) | ||
| assert llm.litellm_extra_body == inference_metadata | ||
|
|
||
| # Verify specific fields that would be useful for custom inference clusters | ||
| assert llm.litellm_extra_body["cluster_id"] == "prod-cluster-1" | ||
| assert llm.litellm_extra_body["routing_key"] == "high-priority" | ||
| assert ( | ||
| llm.litellm_extra_body["custom_headers"]["X-Request-Source"] | ||
| == "openhands-agent" | ||
| ) | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.