-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add root-level tools map with customParameters to AI Config types #141
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 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6661d5f
feat: add root-level tools map with customParameters to AI Config types
jsonbailey 36c6af7
fix: add AITool to __all__ in __init__.py
jsonbailey 3080987
refactor: rename AITool to LDTool for cross-SDK naming consistency
jsonbailey 4ba1e93
fix: simplify _parse_tools guard and warn on malformed tool entries
jsonbailey 5a9fd22
refactor: use early continue in _parse_tools loop
jsonbailey ccc744e
fix: sort LDTool import alphabetically to satisfy isort
jsonbailey 19a2b2c
fix: remove incorrect default.tools fallback from _parse_tools call s…
jsonbailey 7c522ae
feat: add description field to LDTool
jsonbailey 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| import pytest | ||
| from ldclient import Config, Context, LDClient | ||
| from ldclient.integrations.test_data import TestData | ||
|
|
||
| from ldai import LDTool, LDAIClient | ||
| from ldai.models import AIAgentConfigDefault, AICompletionConfigDefault | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def td() -> TestData: | ||
| td = TestData.data_source() | ||
| td.update( | ||
| td.flag('completion-with-tools') | ||
| .variations( | ||
| { | ||
| 'model': {'name': 'gpt-5', 'parameters': {'temperature': 0.7}}, | ||
| 'messages': [{'role': 'user', 'content': 'Hello'}], | ||
| 'tools': { | ||
| 'web-search-tool': { | ||
| 'name': 'web-search-tool', | ||
| 'type': 'function', | ||
| 'parameters': {'type': 'object', 'properties': {}, 'required': []}, | ||
| 'customParameters': {'some-custom-parameter': 'some-custom-value'}, | ||
| } | ||
| }, | ||
| '_ldMeta': {'enabled': True, 'variationKey': 'v1', 'version': 1}, | ||
| }, | ||
| ) | ||
| .variation_for_all(0) | ||
| ) | ||
|
|
||
| td.update( | ||
| td.flag('completion-no-tools') | ||
| .variations( | ||
| { | ||
| 'model': {'name': 'gpt-5'}, | ||
| 'messages': [{'role': 'user', 'content': 'Hello'}], | ||
| '_ldMeta': {'enabled': True, 'variationKey': 'v1', 'version': 1}, | ||
| }, | ||
| ) | ||
| .variation_for_all(0) | ||
| ) | ||
|
|
||
| td.update( | ||
| td.flag('agent-with-tools') | ||
| .variations( | ||
| { | ||
| 'model': {'name': 'gpt-5'}, | ||
| 'instructions': 'You are a helpful agent.', | ||
| 'tools': { | ||
| 'search-tool': { | ||
| 'name': 'search-tool', | ||
| 'type': 'function', | ||
| 'customParameters': {'maxResults': 10}, | ||
| } | ||
| }, | ||
| '_ldMeta': {'enabled': True, 'variationKey': 'v1', 'version': 1, 'mode': 'agent'}, | ||
| }, | ||
| ) | ||
| .variation_for_all(0) | ||
| ) | ||
|
|
||
| return td | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def client(td) -> LDAIClient: | ||
| config = Config('fake-sdk-key', update_processor_class=td, send_events=False) | ||
| ld_client = LDClient(config=config) | ||
| return LDAIClient(ld_client) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def context() -> Context: | ||
| return Context.builder('test-user').name('Test User').build() | ||
|
|
||
|
|
||
| def test_completion_config_includes_tools_from_variation(client, context): | ||
| result = client.completion_config('completion-with-tools', context, AICompletionConfigDefault()) | ||
|
|
||
| assert result.tools is not None | ||
| assert 'web-search-tool' in result.tools | ||
| tool = result.tools['web-search-tool'] | ||
| assert tool.name == 'web-search-tool' | ||
| assert tool.type == 'function' | ||
| assert tool.custom_parameters == {'some-custom-parameter': 'some-custom-value'} | ||
|
|
||
|
|
||
| def test_completion_config_tools_none_when_not_in_variation(client, context): | ||
| result = client.completion_config('completion-no-tools', context, AICompletionConfigDefault()) | ||
|
|
||
| assert result.tools is None | ||
|
|
||
|
|
||
| def test_completion_config_falls_back_to_default_tools(client, context): | ||
| default_tool = LDTool(name='default-tool', type='function', custom_parameters={'priority': 'high'}) | ||
| default = AICompletionConfigDefault(tools={'default-tool': default_tool}) | ||
|
|
||
| result = client.completion_config('completion-no-tools', context, default) | ||
|
|
||
| assert result.tools is not None | ||
| assert 'default-tool' in result.tools | ||
| assert result.tools['default-tool'].custom_parameters == {'priority': 'high'} | ||
|
|
||
|
|
||
| def test_agent_config_includes_tools_from_variation(client, context): | ||
| result = client.agent_config('agent-with-tools', context, AIAgentConfigDefault()) | ||
|
|
||
| assert result.tools is not None | ||
| assert 'search-tool' in result.tools | ||
| tool = result.tools['search-tool'] | ||
| assert tool.name == 'search-tool' | ||
| assert tool.custom_parameters == {'maxResults': 10} | ||
|
|
||
|
|
||
| def test_aitool_to_dict_serializes_custom_parameters_as_camel_case(): | ||
| tool = LDTool( | ||
| name='my-tool', | ||
| type='function', | ||
| parameters={'type': 'object'}, | ||
| custom_parameters={'someKey': 'someValue'}, | ||
| ) | ||
| d = tool.to_dict() | ||
|
|
||
| assert d['name'] == 'my-tool' | ||
| assert d['type'] == 'function' | ||
| assert d['parameters'] == {'type': 'object'} | ||
| assert 'customParameters' in d | ||
| assert d['customParameters'] == {'someKey': 'someValue'} | ||
| assert 'custom_parameters' not in d | ||
|
|
||
|
|
||
| def test_aitool_to_dict_omits_none_fields(): | ||
| tool = LDTool(name='bare-tool') | ||
| d = tool.to_dict() | ||
|
|
||
| assert d == {'name': 'bare-tool'} |
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.