Skip to content

Commit

Permalink
actually don't introduce new funciton for now
Browse files Browse the repository at this point in the history
  • Loading branch information
lievan committed Oct 30, 2024
1 parent 56f657e commit 60cde3d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 36 deletions.
1 change: 1 addition & 0 deletions ddtrace/llmobs/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@
RAGAS_ML_APP_PREFIX = "dd-ragas"

ANNOTATIONS_CONTEXT_ID = "annotations_context_id"
INTERNAL_CONTEXT_VARIABLE_KEYS = "_dd_context_variable_keys"
33 changes: 0 additions & 33 deletions ddtrace/llmobs/_llmobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import time
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import Union

Expand Down Expand Up @@ -269,38 +268,6 @@ def disable(cls) -> None:

log.debug("%s disabled", cls.__name__)

@classmethod
def using_prompt(
cls,
prompt_id: Optional[str] = None,
template: Optional[str] = None,
variables: Optional[Dict] = None,
context_variable_keys: Optional[List[str]] = None,
tags: Optional[Dict[str, object]] = None,
):
"""
Sets LLM-specific attributes on LLMObs spans created while the returned context is active.
Annotations are applied in the order in which contexts are entered.
:param str name: span names of any LLM spans started within the returned context
:param dict prompt: A dictionary that represents the prompt used for an LLM call in the following form:
`{"template": "...", "id": "...", "version": "...", "variables": {"variable_1": "...", ...}}`.
Can also be set using the `ddtrace.llmobs.utils.Prompt` constructor class.
:param list context_variable_keys: list of variable names in the prompt that hold ground truth
context information
"""
if context_variable_keys is None:
context_variable_keys = ["context"]
return cls.annotation_context(
prompt={
"id": prompt_id,
"template": template,
"variables": variables,
"_dd_context_variable_keys": context_variable_keys,
},
tags=tags,
)

@classmethod
def annotation_context(
cls, tags: Optional[Dict[str, Any]] = None, prompt: Optional[dict] = None, name: Optional[str] = None
Expand Down
5 changes: 3 additions & 2 deletions ddtrace/llmobs/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ddtrace.ext import SpanTypes
from ddtrace.internal.logger import get_logger
from ddtrace.llmobs._constants import GEMINI_APM_SPAN_NAME
from ddtrace.llmobs._constants import INTERNAL_CONTEXT_VARIABLE_KEYS
from ddtrace.llmobs._constants import LANGCHAIN_APM_SPAN_NAME
from ddtrace.llmobs._constants import ML_APP
from ddtrace.llmobs._constants import OPENAI_APM_SPAN_NAME
Expand All @@ -29,7 +30,7 @@ def validate_prompt(prompt: dict) -> Dict[str, Union[str, dict, List[str]]]:
template = prompt.get("template")
version = prompt.get("version")
prompt_id = prompt.get("id")
ctx_variable_keys = prompt.get("_dd_context_variable_keys")
ctx_variable_keys = prompt.get("context_variable_keys")
if variables is not None:
if not isinstance(variables, dict):
raise TypeError("Prompt variables must be a dictionary.")
Expand All @@ -53,7 +54,7 @@ def validate_prompt(prompt: dict) -> Dict[str, Union[str, dict, List[str]]]:
raise TypeError("Prompt `context_variable_keys` must be a list.")
if not all(isinstance(k, str) for k in ctx_variable_keys):
raise TypeError("Prompt `context_variable_keys` must be a list of strings.")
validated_prompt["_dd_context_variable_keys"] = ctx_variable_keys
validated_prompt[INTERNAL_CONTEXT_VARIABLE_KEYS] = ctx_variable_keys
return validated_prompt


Expand Down
2 changes: 1 addition & 1 deletion ddtrace/llmobs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Message = TypedDict("Message", {"content": str, "role": str}, total=False)
Prompt = TypedDict(
"Prompt",
{"variables": Dict[str, str], "template": str, "id": str, "version": str, "_dd_context_variable_keys": List[str]},
{"variables": Dict[str, str], "template": str, "id": str, "version": str, "context_variable_keys": List[str]},
total=False,
)

Expand Down

0 comments on commit 60cde3d

Please sign in to comment.