Skip to content

Commit d53c63c

Browse files
author
Daniel OBrien
committed
review feedback
1 parent 7be4d27 commit d53c63c

File tree

6 files changed

+32
-37
lines changed

6 files changed

+32
-37
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.0.0"
2+
".": "0.1.0"
33
}

CONTRIBUTING.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ LaunchDarkly has published an [SDK contributor's guide](https://docs.launchdarkl
44

55
## Submitting bug reports and feature requests
66

7-
The LaunchDarkly SDK team monitors the [issue tracker](https://github.com/launchdarkly/python-server-sdk-AI/issues) in the SDK repository. Bug reports and feature requests specific to this library should be filed in this issue tracker. The SDK team will respond to all newly filed issues within two business days.
7+
The LaunchDarkly SDK team monitors the [issue tracker](https://github.com/launchdarkly/python-server-sdk-ai/issues) in the SDK repository. Bug reports and feature requests specific to this library should be filed in this issue tracker. The SDK team will respond to all newly filed issues within two business days.
88

99
## Submitting pull requests
1010

@@ -55,8 +55,6 @@ make lint
5555

5656
The library's module structure is as follows:
5757

58-
<!-- TODO: Add structure description -->
59-
6058
### Type hints
6159

6260
Python does not require the use of type hints, but they can be extremely helpful for spotting mistakes and for improving the IDE experience, so we should always use them in the library. Every method in the public API is expected to have type hints for all non-`self` parameters, and for its return value if any.

ldai/client.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,41 @@ class LDAIClient:
1212
def __init__(self, client: LDClient):
1313
self.client = client
1414

15-
def model_config(self, key: str, context: Context, default_value: str, variables: Optional[Dict[str, Any]] = None) -> AIConfig:
16-
"""Get the value of a model configuration asynchronously.
17-
18-
Args:
19-
key: The key of the model configuration.
20-
context: The context to evaluate the model configuration in.
21-
default_value: The default value of the model configuration.
22-
variables: Additional variables for the model configuration.
15+
def model_config(self, key: str, context: Context, default_value: AIConfig, variables: Optional[Dict[str, Any]] = None) -> AIConfig:
16+
"""
17+
Get the value of a model configuration asynchronously.
2318
24-
Returns:
25-
The value of the model configuration.
19+
:param key: The key of the model configuration.
20+
:param context: The context to evaluate the model configuration in.
21+
:param default_value: The default value of the model configuration.
22+
:param variables: Additional variables for the model configuration.
23+
:return: The value of the model configuration.
2624
"""
2725
variation = self.client.variation(key, context, default_value)
2826

29-
all_variables = {'ldctx': context}
27+
all_variables = {}
3028
if variables:
3129
all_variables.update(variables)
30+
all_variables['ldctx'] = context
3231

33-
variation['prompt'] = [
34-
{
35-
**entry,
36-
'content': self.interpolate_template(entry['content'], all_variables)
37-
}
38-
for entry in variation['prompt']
39-
]
32+
if isinstance(variation['prompt'], list) and all(isinstance(entry, dict) for entry in variation['prompt']):
33+
variation['prompt'] = [
34+
{
35+
'role': entry['role'],
36+
'content': self.interpolate_template(entry['content'], all_variables)
37+
}
38+
for entry in variation['prompt']
39+
]
4040

41-
enabled = variation['_ldMeta'].get('enabled')
42-
return AIConfig(config=variation, tracker=LDAIConfigTracker(self.client, variation['_ldMeta']['versionKey'], key, context, bool(enabled)))
41+
enabled = variation.get('_ldMeta',{}).get('enabled', False)
42+
return AIConfig(config=variation, tracker=LDAIConfigTracker(self.client, variation.get('_ldMeta', {}).get('versionKey', ''), key, context, bool(enabled)))
4343

4444
def interpolate_template(self, template: str, variables: Dict[str, Any]) -> str:
45-
"""Interpolate the template with the given variables.
46-
47-
Args:
48-
template: The template string.
49-
variables: The variables to interpolate into the template.
45+
"""
46+
Interpolate the template with the given variables.
5047
51-
Returns:
52-
The interpolated string.
48+
:template: The template string.
49+
:variables: The variables to interpolate into the template.
50+
:return: The interpolated string.
5351
"""
5452
return chevron.render(template, variables)

ldai/tracker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def get_track_data(self):
1919
def track_duration(self, duration: int) -> None:
2020
self.ld_client.track('$ld:ai:duration:total', self.context, self.get_track_data(), duration)
2121

22-
def track_duration_of(self, func, *args, **kwargs):
22+
def track_duration_of(self, func):
2323
start_time = time.time()
24-
result = func(*args, **kwargs)
24+
result = func()
2525
end_time = time.time()
2626
duration = int((end_time - start_time) * 1000) # duration in milliseconds
2727
self.track_duration(duration)
@@ -36,8 +36,8 @@ def track_feedback(self, feedback: Dict[str, FeedbackKind]) -> None:
3636
def track_success(self) -> None:
3737
self.ld_client.track('$ld:ai:generation', self.context, self.get_track_data(), 1)
3838

39-
def track_openai(self, func, *args, **kwargs):
40-
result = self.track_duration_of(func, *args, **kwargs)
39+
def track_openai(self, func):
40+
result = self.track_duration_of(func)
4141
if result.usage:
4242
self.track_tokens(OpenAITokenUsage(result.usage))
4343
return result

ldai/types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class TokenMetrics():
99
output: int # type: ignore
1010

1111
@dataclass
12-
1312
class AIConfigData():
1413
config: dict
1514
prompt: any

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "launchdarkly-server-sdk-ai"
3-
version = "0.0.1"
3+
version = "0.1.0"
44
description = "LaunchDarkly SDK for AI"
55
authors = ["LaunchDarkly <[email protected]>"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)