-
Notifications
You must be signed in to change notification settings - Fork 53
fix: flatten core model params #168
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,35 @@ def get_model_params(kwargs: Dict[str, Any]) -> Dict[str, Any]: | |||||||||
| return model_params | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def extract_core_model_params(kwargs: Dict[str, Any], provider: str) -> Dict[str, Any]: | ||||||||||
| """ | ||||||||||
| Extracts core model parameters from the kwargs dictionary. | ||||||||||
| """ | ||||||||||
| output = {} | ||||||||||
| if provider == "anthropic": | ||||||||||
|
Member
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. To track AI cost processing's case-insensitive behavior:
Suggested change
|
||||||||||
| if "temperature" in kwargs: | ||||||||||
| output["$ai_temperature"] = kwargs.get("temperature") | ||||||||||
| if "max_tokens" in kwargs: | ||||||||||
| output["$ai_max_tokens"] = kwargs.get("max_tokens") | ||||||||||
| if "stream" in kwargs: | ||||||||||
| output["$ai_stream"] = kwargs.get("stream") | ||||||||||
| elif provider == "openai": | ||||||||||
| if "temperature" in kwargs: | ||||||||||
| output["$ai_temperature"] = kwargs.get("temperature") | ||||||||||
| if "max_completion_tokens" in kwargs: | ||||||||||
| output["$ai_max_tokens"] = kwargs.get("max_completion_tokens") | ||||||||||
|
Comment on lines
+47
to
+48
Member
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. Might also be clearest to standardize on |
||||||||||
| if "stream" in kwargs: | ||||||||||
| output["$ai_stream"] = kwargs.get("stream") | ||||||||||
| else: # default to openai params | ||||||||||
| if "temperature" in kwargs: | ||||||||||
| output["$ai_temperature"] = kwargs.get("temperature") | ||||||||||
| if "max_tokens" in kwargs: | ||||||||||
| output["$ai_max_tokens"] = kwargs.get("max_completion_tokens") | ||||||||||
| if "stream" in kwargs: | ||||||||||
| output["$ai_stream"] = kwargs.get("stream") | ||||||||||
| return output | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def get_usage(response, provider: str) -> Dict[str, Any]: | ||||||||||
| if provider == "anthropic": | ||||||||||
| return { | ||||||||||
|
|
@@ -148,6 +177,7 @@ def call_llm_and_track_usage( | |||||||||
| "$ai_latency": latency, | ||||||||||
| "$ai_trace_id": posthog_trace_id, | ||||||||||
| "$ai_base_url": str(base_url), | ||||||||||
| **extract_core_model_params(kwargs, provider), | ||||||||||
| **(posthog_properties or {}), | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -218,6 +248,7 @@ async def call_llm_and_track_usage_async( | |||||||||
| "$ai_latency": latency, | ||||||||||
| "$ai_trace_id": posthog_trace_id, | ||||||||||
| "$ai_base_url": str(base_url), | ||||||||||
| **extract_core_model_params(kwargs, provider), | ||||||||||
| **(posthog_properties or {}), | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
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.
Let's do this in the plugin server, so that we only have to update one place to cover all SDKs!