Skip to content
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

fix: Update how prompt is handled #12

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ldai/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from dataclasses import asdict, dataclass
import json
from typing import Any, Dict, List, Literal, Optional

import chevron
Expand All @@ -13,6 +14,8 @@ class LDMessage:
role: Literal['system', 'user', 'assistant']
content: str

def to_json(self):
return json.dumps(asdict(self))

@dataclass
class AIConfigData:
Expand Down Expand Up @@ -59,7 +62,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(
Expand All @@ -71,7 +74,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', ''),
Expand Down
Loading