-
Notifications
You must be signed in to change notification settings - Fork 0
feat: SDK Changes in preparation for release #7
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 10 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
780fa15
align Python with most recent TypeScript changes
a1f9490
Update ldai/client.py
7be4d27
Update ldai/tracker.py
d53c63c
review feedback
24e4680
add testing
5d58b33
README cleanup
de02914
add back missing dataclass
60f7353
fix up types
0055008
fix project url
be7d0fa
Merge branch 'main' into dob/REL-3441/sdkAlignmentChanges
d97db5b
Add LDMessage type
7c02cf0
fixing up types
5cae616
whitespace cleanup
d1257fc
fix tests
742c385
remove eronous print
59928ea
fix: Fixtures are not meant to be called directly,
6d5d8fb
fix: More fixture changes
bf61cc3
fix: change client call
c69a0c8
doc updates
8c60852
clarify docs
9b86f7f
make methods private
e37d4ba
newline EOF
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
".": "1.0.0" | ||
".": "0.1.0" | ||
} |
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,101 @@ | ||
import pytest | ||
from ldclient import LDClient, Context, Config | ||
from ldclient.integrations.test_data import TestData | ||
from ldai.types import AIConfig | ||
from ldai.client import LDAIClient | ||
from ldclient.testing.builders import * | ||
|
||
@pytest.fixture | ||
def td() -> TestData: | ||
td = TestData.data_source() | ||
td.update(td.flag('model-config').variations({ | ||
'model': { 'modelId': 'fakeModel'}, | ||
'prompt': [{'role': 'system', 'content': 'Hello, {{name}}!'}], | ||
'_ldMeta': {'enabled': True, 'versionKey': 'abcd'} | ||
}, "green").variation_for_all(0)) | ||
|
||
td.update(td.flag('multiple-prompt').variations({ | ||
'model': { 'modelId': 'fakeModel'}, | ||
'prompt': [{'role': 'system', 'content': 'Hello, {{name}}!'}, {'role': 'user', 'content': 'The day is, {{day}}!'}], | ||
'_ldMeta': {'enabled': True, 'versionKey': 'abcd'} | ||
}, "green").variation_for_all(0)) | ||
|
||
td.update(td.flag('ctx-interpolation').variations({ | ||
'model': { 'modelId': 'fakeModel'}, | ||
'prompt': [{'role': 'system', 'content': 'Hello, {{ldctx.name}}!'}], | ||
'_ldMeta': {'enabled': True, 'versionKey': 'abcd'} | ||
}).variation_for_all(0)) | ||
|
||
td.update(td.flag('off-config').variations({ | ||
'model': { 'modelId': 'fakeModel'}, | ||
'prompt': [{'role': 'system', 'content': 'Hello, {{name}}!'}], | ||
'_ldMeta': {'enabled': False, 'versionKey': 'abcd'} | ||
}).variation_for_all(0)) | ||
|
||
return td | ||
|
||
@pytest.fixture | ||
def client(td: TestData) -> LDClient: | ||
config = Config('sdk-key', update_processor_class=td, send_events=False) | ||
return LDClient(config=config) | ||
|
||
@pytest.fixture | ||
def ldai_client(client: LDClient) -> LDAIClient: | ||
return LDAIClient(client) | ||
|
||
def test_model_config_interpolation(ldai_client: LDAIClient): | ||
context = Context.create('user-key') | ||
default_value = AIConfig(config={ | ||
'model': { 'modelId': 'fakeModel'}, | ||
'prompt': [{'role': 'system', 'content': 'Hello, {{name}}!'}], | ||
'_ldMeta': {'enabled': True, 'versionKey': 'abcd'} | ||
}, tracker=None, enabled=True) | ||
variables = {'name': 'World'} | ||
|
||
config = ldai_client.model_config('model-config', context, default_value, variables) | ||
|
||
assert config.config['prompt'][0]['content'] == 'Hello, World!' | ||
assert config.enabled is True | ||
assert config.tracker.version_key == 'abcd' | ||
|
||
def test_model_config_no_variables(ldai_client: LDAIClient): | ||
context = Context.create('user-key') | ||
default_value = AIConfig(config={}, tracker=None, enabled=True) | ||
|
||
config = ldai_client.model_config('model-config', context, default_value, {}) | ||
|
||
assert config.config['prompt'][0]['content'] == 'Hello, !' | ||
assert config.enabled is True | ||
assert config.tracker.version_key == 'abcd' | ||
|
||
def test_context_interpolation(ldai_client: LDAIClient): | ||
context = Context.builder('user-key').name("Sandy").build() | ||
default_value = AIConfig(config={}, tracker=None, enabled=True) | ||
variables = {'name': 'World'} | ||
|
||
config = ldai_client.model_config('ctx-interpolation', context, default_value, variables) | ||
|
||
assert config.config['prompt'][0]['content'] == 'Hello, Sandy!' | ||
assert config.enabled is True | ||
assert config.tracker.version_key == 'abcd' | ||
|
||
def test_model_config_disabled(ldai_client: LDAIClient): | ||
context = Context.create('user-key') | ||
default_value = AIConfig(config={}, tracker=None, enabled=True) | ||
|
||
config = ldai_client.model_config('off-config', context, default_value, {}) | ||
|
||
assert config.enabled is False | ||
assert config.tracker.version_key == 'abcd' | ||
|
||
def test_model_config_multiple(ldai_client: LDAIClient): | ||
context = Context.create('user-key') | ||
default_value = AIConfig(config={}, tracker=None, enabled=True) | ||
variables = {'name': 'World', 'day': 'Monday'} | ||
|
||
config = ldai_client.model_config('multiple-prompt', context, default_value, variables) | ||
|
||
assert config.config['prompt'][0]['content'] == 'Hello, World!' | ||
assert config.config['prompt'][1]['content'] == 'The day is, Monday!' | ||
assert config.enabled is True | ||
assert config.tracker.version_key == 'abcd' |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
[tool.poetry] | ||
name = "launchdarkly-server-sdk-ai" | ||
version = "0.0.1" | ||
version = "0.1.0" | ||
description = "LaunchDarkly SDK for AI" | ||
authors = ["LaunchDarkly <[email protected]>"] | ||
license = "Apache-2.0" | ||
readme = "README.md" | ||
homepage = "https://docs.launchdarkly.com/sdk/server-side/python-ai" | ||
homepage = "https://docs.launchdarkly.com/sdk/ai/python" | ||
repository = "https://github.com/launchdarkly/python-server-sdk-ai" | ||
documentation = "https://launchdarkly-python-sdk-ai.readthedocs.io/en/latest/" | ||
classifiers = [ | ||
|
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.