From 0f2a335f2a8d01116d1162fdab67a01f335f2fce Mon Sep 17 00:00:00 2001 From: Daniel OBrien Date: Fri, 8 Nov 2024 14:18:58 -0500 Subject: [PATCH 1/3] change return data --- ldai/client.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ldai/client.py b/ldai/client.py index 0312096..5d48cb2 100644 --- a/ldai/client.py +++ b/ldai/client.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass +from dataclasses import asdict, dataclass from typing import Any, Dict, List, Literal, Optional import chevron @@ -13,6 +13,8 @@ class LDMessage: role: Literal['system', 'user', 'assistant'] content: str + def to_dict(self): + return asdict(self) @dataclass class AIConfigData: @@ -59,7 +61,7 @@ def model_config( if isinstance(variation['prompt'], list) and all( isinstance(entry, dict) for entry in variation['prompt'] ): - variation['prompt'] = [ + prompt = [ LDMessage( role=entry['role'], content=self.__interpolate_template( @@ -71,7 +73,7 @@ def model_config( enabled = variation.get('_ldMeta', {}).get('enabled', False) return AIConfig( - config=AIConfigData(model=variation['model'], prompt=variation['prompt']), + config=AIConfigData(model=variation['model'], prompt=prompt), tracker=LDAIConfigTracker( self.client, variation.get('_ldMeta', {}).get('versionKey', ''), From 683bf8933e8e3602d4d18b26a38109ec54d6a79d Mon Sep 17 00:00:00 2001 From: Daniel OBrien Date: Fri, 8 Nov 2024 15:05:21 -0500 Subject: [PATCH 2/3] change to_json --- ldai/client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ldai/client.py b/ldai/client.py index 5d48cb2..615edb6 100644 --- a/ldai/client.py +++ b/ldai/client.py @@ -1,4 +1,5 @@ from dataclasses import asdict, dataclass +import json from typing import Any, Dict, List, Literal, Optional import chevron @@ -13,8 +14,8 @@ class LDMessage: role: Literal['system', 'user', 'assistant'] content: str - def to_dict(self): - return asdict(self) + def to_json(self): + return json.dumps(asdict(self)) @dataclass class AIConfigData: From ffc2b3114faebd6344cca18f4d990eff6e43fb32 Mon Sep 17 00:00:00 2001 From: Daniel OBrien Date: Fri, 8 Nov 2024 16:42:09 -0500 Subject: [PATCH 3/3] fix sort order, limit python version --- ldai/client.py | 7 +++---- pyproject.toml | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ldai/client.py b/ldai/client.py index 615edb6..90218e2 100644 --- a/ldai/client.py +++ b/ldai/client.py @@ -1,21 +1,20 @@ -from dataclasses import asdict, dataclass -import json +from dataclasses import dataclass from typing import Any, Dict, List, Literal, Optional import chevron +from dataclasses_json import dataclass_json from ldclient import Context from ldclient.client import LDClient from ldai.tracker import LDAIConfigTracker +@dataclass_json @dataclass class LDMessage: role: Literal['system', 'user', 'assistant'] content: str - def to_json(self): - return json.dumps(asdict(self)) @dataclass class AIConfigData: diff --git a/pyproject.toml b/pyproject.toml index c03027d..0b86b18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,11 +27,12 @@ exclude = [ ] [tool.poetry.dependencies] -python = ">=3.8" +python = ">=3.8,<4" launchdarkly-server-sdk = ">=9.4.0" chevron = "=0.14.0" pycodestyle = "^2.12.1" isort = "^5.13.2" +dataclasses-json = "^0.6.7" [tool.poetry.group.dev.dependencies]