Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions packages/sdk/server-ai/src/ldai/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
import warnings
from typing import Any, Callable, Dict, List, Optional, Tuple

import chevron
Expand Down Expand Up @@ -169,6 +170,7 @@ def config(
:param variables: Additional variables for the model configuration.
:return: The value of the model configuration along with a tracker used for gathering metrics.
"""
warnings.warn("config() is deprecated, use completion_config() instead", DeprecationWarning, stacklevel=2)
return self.completion_config(key, context, default, variables)

def _judge_config(
Expand Down Expand Up @@ -417,12 +419,9 @@ async def create_chat(
default_ai_provider: Optional[str] = None,
) -> Optional[ManagedModel]:
"""
.. deprecated:: Use :meth:`create_model` instead.

Creates and returns a ManagedModel for AI conversations.
This method is a deprecated alias for :meth:`create_model`.
.. deprecated:: Use :meth:`create_model` instead. This method will be removed in a future version.
"""
log.warning('create_chat() is deprecated, use create_model() instead')
warnings.warn("create_chat() is deprecated, use create_model() instead", DeprecationWarning, stacklevel=2)
return await self.create_model(key, context, default, variables, default_ai_provider)

async def create_agent(
Expand Down Expand Up @@ -545,6 +544,7 @@ def agent(
:param context: The context to evaluate the agent configuration in.
:return: Configured AIAgentConfig instance.
"""
warnings.warn("agent() is deprecated, use agent_config() instead", DeprecationWarning, stacklevel=2)
return self.agent_config(config.key, context, config.default, config.variables)

def agent_configs(
Expand Down Expand Up @@ -791,6 +791,7 @@ def agents(
:param context: The context to evaluate the agent configurations in.
:return: Dictionary mapping agent keys to their AIAgentConfig configurations.
"""
warnings.warn("agents() is deprecated, use agent_configs() instead", DeprecationWarning, stacklevel=2)
return self.agent_configs(agent_configs, context)

def __evaluate(
Expand Down
10 changes: 10 additions & 0 deletions packages/sdk/server-ai/src/ldai/tracker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
import json
import time
import warnings
from dataclasses import dataclass
from enum import Enum
from typing import Any, Callable, Dict, Iterable, List, Optional
Expand Down Expand Up @@ -391,6 +392,9 @@ def track_openai_metrics(self, func):
"""
Track OpenAI-specific operations.

.. deprecated:: Use :meth:`track_metrics_of` with ``get_ai_metrics_from_response``
from ``ldai_openai`` instead. This method will be removed in a future version.

This function will track the duration of the operation, the token
usage, and the success or error status.

Expand All @@ -404,6 +408,12 @@ def track_openai_metrics(self, func):
:param func: Function to track.
:return: Result of the tracked function.
"""
warnings.warn(
"track_openai_metrics is deprecated. Use track_metrics_of with "
"get_ai_metrics_from_response from ldai_openai instead.",
DeprecationWarning,
stacklevel=2,
)
start_ns = time.perf_counter_ns()
try:
result = func()
Expand Down
14 changes: 8 additions & 6 deletions packages/sdk/server-ai/tests/test_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ def to_dict(self):
def get_result():
return Result()

tracker.track_openai_metrics(get_result)
with pytest.warns(DeprecationWarning, match="track_openai_metrics is deprecated"):
tracker.track_openai_metrics(get_result)

calls = [
call(
Expand Down Expand Up @@ -335,11 +336,12 @@ def test_tracks_openai_metrics_with_exception(client: LDClient):
def raise_exception():
raise ValueError("Something went wrong")

try:
tracker.track_openai_metrics(raise_exception)
assert False, "Should have thrown an exception"
except ValueError:
pass
with pytest.warns(DeprecationWarning, match="track_openai_metrics is deprecated"):
try:
tracker.track_openai_metrics(raise_exception)
assert False, "Should have thrown an exception"
except ValueError:
pass

calls = [
call(
Expand Down
Loading