From 6bd49c608761605bb8c066f32ef8d09cf0980929 Mon Sep 17 00:00:00 2001 From: Vivek Aditya Date: Sat, 23 Mar 2024 12:42:07 +0530 Subject: [PATCH 1/2] Athina docs updated with information about additional fields and a minor fix in the callback --- .../docs/observability/athina_integration.md | 30 +++++++++++++++++++ litellm/integrations/athina.py | 4 +-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/docs/my-website/docs/observability/athina_integration.md b/docs/my-website/docs/observability/athina_integration.md index 4754555012..ef8902ea58 100644 --- a/docs/my-website/docs/observability/athina_integration.md +++ b/docs/my-website/docs/observability/athina_integration.md @@ -41,6 +41,36 @@ response = completion( ) ``` +## Additional information in metadata +You can send some additional information to Athina by using the `metadata` field in completion. This can be useful for sending metadata about the request, such as the user ID, the request ID, or any other information you want to track. + +```python +#openai call with additional metadata +response = completion( + model="gpt-3.5-turbo", + messages=[ + {"role": "user", "content": "Hi 👋 - i'm openai"} + ], + metadata={ + "environment": "staging", + "prompt_slug": "my_prompt_slug/v1" + } +) + +``` + +Following are the allowed fields in metadata, their types, and their descriptions: + +* `environment: Optional[str]` - Environment your app is running in (ex: production, staging, etc). This is useful for segmenting inference calls by environment. +* `prompt_slug: Optional[str]` - Identifier for the prompt used for inference. This is useful for segmenting inference calls by prompt. +* `customer_id: Optional[str]` - This is your customer ID. This is useful for segmenting inference calls by customer. +* `customer_user_id: Optional[str]` - This is the end user ID. This is useful for segmenting inference calls by the end user. +* `session_id: Optional[str]` - is the session or conversation ID. This is used for grouping different inferences into a conversation or chain. [Read more].(https://docs.athina.ai/logging/grouping_inferences) +* `external_reference_id: Optional[str]` - This is useful if you want to associate your own internal identifier with the inference logged to Athina. +* `context: Optional[Union[dict, str]]` - This is the context used as information for the prompt. For RAG applications, this is the "retrieved" data. You may log context as a string or as an object (dictionary). +* `expected_response: Optional[str]` - This is the reference response to compare against for evaluation purposes. This is useful for segmenting inference calls by expected response. +* `user_query: Optional[str]` - This is the user's query. For conversational applications, this is the user's last message. + ## Support & Talk with Athina Team - [Schedule Demo 👋](https://cal.com/shiv-athina/30min) diff --git a/litellm/integrations/athina.py b/litellm/integrations/athina.py index f957384ea6..897cf6c8d5 100644 --- a/litellm/integrations/athina.py +++ b/litellm/integrations/athina.py @@ -10,7 +10,7 @@ class AthinaLogger: "Content-Type": "application/json" } self.athina_logging_url = "https://log.athina.ai/api/v1/log/inference" - self.additional_keys = ["environment", "prompt_slug", "customer_id", "customer_user_id", "session_id", "external_reference_id", "context", "expected_response"] + self.additional_keys = ["environment", "prompt_slug", "customer_id", "customer_user_id", "session_id", "external_reference_id", "context", "expected_response", "user_query"] def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose): import requests @@ -32,8 +32,6 @@ class AthinaLogger: if "messages" in kwargs: data["prompt"] = kwargs.get("messages", None) - if kwargs.get("messages") and len(kwargs.get("messages")) > 0: - data["user_query"] = kwargs.get("messages")[0].get("content", None) # Directly add tools or functions if present optional_params = kwargs.get("optional_params", {}) From efc90b04c7400cd70b32b73a10073398fd066bec Mon Sep 17 00:00:00 2001 From: Vivek Aditya Date: Sat, 23 Mar 2024 12:50:46 +0530 Subject: [PATCH 2/2] minor fix --- docs/my-website/docs/observability/athina_integration.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/my-website/docs/observability/athina_integration.md b/docs/my-website/docs/observability/athina_integration.md index ef8902ea58..62c8897518 100644 --- a/docs/my-website/docs/observability/athina_integration.md +++ b/docs/my-website/docs/observability/athina_integration.md @@ -42,7 +42,7 @@ response = completion( ``` ## Additional information in metadata -You can send some additional information to Athina by using the `metadata` field in completion. This can be useful for sending metadata about the request, such as the user ID, the request ID, or any other information you want to track. +You can send some additional information to Athina by using the `metadata` field in completion. This can be useful for sending metadata about the request, such as the customer_id, prompt_slug, or any other information you want to track. ```python #openai call with additional metadata @@ -56,7 +56,6 @@ response = completion( "prompt_slug": "my_prompt_slug/v1" } ) - ``` Following are the allowed fields in metadata, their types, and their descriptions: