-
Notifications
You must be signed in to change notification settings - Fork 0
Updates to Python tracking #3
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
Changes from all commits
f52bf8f
dc073a4
6c0742d
fe50860
bff84ef
1b5e2a5
f68fa4d
6b4f3fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,85 @@ | ||
from enum import Enum | ||
from typing import TypedDict | ||
from typing import Callable | ||
from dataclasses import dataclass | ||
|
||
@dataclass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't typically see both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keelerm84 this is a lack of knowledge on my part. I switched them over to dataclasses in the following commit. |
||
class TokenMetrics(): | ||
total: int | ||
input: int | ||
output: int # type: ignore | ||
|
||
@dataclass | ||
|
||
class AIConfigData(): | ||
config: dict | ||
prompt: any | ||
_ldMeta: dict | ||
|
||
class AITracker(): | ||
track_duration: Callable[..., None] | ||
track_tokens: Callable[..., None] | ||
track_error: Callable[..., None] | ||
track_generation: Callable[..., None] | ||
track_feedback: Callable[..., None] | ||
|
||
class AIConfig(): | ||
def __init__(self, config: AIConfigData, tracker: AITracker): | ||
self.config = config | ||
self.tracker = tracker | ||
|
||
class FeedbackKind(Enum): | ||
Positive = "positive" | ||
Negative = "negative" | ||
|
||
class TokenUsage(TypedDict): | ||
total_tokens: int | ||
prompt_tokens: int | ||
completion_tokens: int | ||
@dataclass | ||
|
||
class UnderscoreTokenUsage(TypedDict): | ||
class TokenUsage(): | ||
total_tokens: int | ||
prompt_tokens: int | ||
completion_tokens: int | ||
|
||
class BedrockTokenUsage(TypedDict): | ||
totalTokens: int | ||
inputTokens: int | ||
outputTokens: int | ||
def to_metrics(self): | ||
return { | ||
'total': self['total_tokens'], | ||
'input': self['prompt_tokens'], | ||
'output': self['completion_tokens'], | ||
} | ||
|
||
class TokenMetrics(TypedDict): | ||
total: int | ||
input: int | ||
output: int # type: ignore | ||
class OpenAITokenUsage: | ||
def __init__(self, data: any): | ||
self.total_tokens = data.total_tokens | ||
self.prompt_tokens = data.prompt_tokens | ||
self.completion_tokens = data.completion_tokens | ||
|
||
def to_metrics(self) -> TokenMetrics: | ||
return { | ||
'total': self.total_tokens, | ||
'input': self.prompt_tokens, | ||
'output': self.completion_tokens, | ||
} | ||
|
||
class UnderscoreTokenUsage: | ||
def __init__(self, data: dict): | ||
self.total_tokens = data.get('total_tokens', 0) | ||
self.prompt_tokens = data.get('prompt_tokens', 0) | ||
self.completion_tokens = data.get('completion_tokens', 0) | ||
|
||
def to_metrics(self) -> TokenMetrics: | ||
return { | ||
'total': self.total_tokens, | ||
'input': self.prompt_tokens, | ||
'output': self.completion_tokens, | ||
} | ||
|
||
class BedrockTokenUsage: | ||
def __init__(self, data: dict): | ||
self.totalTokens = data.get('totalTokens', 0) | ||
self.inputTokens = data.get('inputTokens', 0) | ||
self.outputTokens = data.get('outputTokens', 0) | ||
|
||
def to_metrics(self) -> TokenMetrics: | ||
return { | ||
'total': self.totalTokens, | ||
'input': self.inputTokens, | ||
'output': self.outputTokens, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "launchdarkly-server-sdk-ai" | ||
version = "0.0.14" | ||
version = "0.0.1" | ||
description = "LaunchDarkly SDK for AI" | ||
authors = ["LaunchDarkly <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is returning a dictionary, not an
AIConfig
type.Also just noticed there is a rogue print in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keelerm84 updated the logic to return an AIConfig