Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.
TypeScript agent-harnessagent-harness-engineeringai-engineeringai-observabilityamd-gpuclaude-codeclickhousecodexcoding-agentcoding-agentscursorgenaigpu-monitoringllm-observabilityllmopsnvidia-smiobservabilityopen-sourceopenaiopentelemetry
[Feat]: Add text_to_speech as wrapped function for ElevenLabs Instrumentations (#326)
patcher9e2afa29bdb5f
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.tomlindex b405c1e5..60aafd41 100644--- a/sdk/python/pyproject.toml+++ b/sdk/python/pyproject.toml@@ -1,6 +1,6 @@[tool.poetry]name = "openlit"-version = "1.15.0"+version = "1.16.0"description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects"authors = ["OpenLIT"]repository = "https://github.com/openlit/openlit/tree/main/openlit/python"diff --git a/sdk/python/src/openlit/instrumentation/elevenlabs/__init__.py b/sdk/python/src/openlit/instrumentation/elevenlabs/__init__.pyindex 95c83f88..e1b9477e 100644--- a/sdk/python/src/openlit/instrumentation/elevenlabs/__init__.py+++ b/sdk/python/src/openlit/instrumentation/elevenlabs/__init__.py@@ -41,6 +41,14 @@ class ElevenLabsInstrumentor(BaseInstrumentor):tracer, pricing_info, trace_content, metrics, disable_metrics),)+ # sync text_to_speech.convert+ wrap_function_wrapper(+ "elevenlabs.text_to_speech.client",+ "TextToSpeechClient.convert",+ generate("elevenlabs.text_to_speech", version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics),+ )+# async generatewrap_function_wrapper("elevenlabs.client",@@ -49,6 +57,14 @@ class ElevenLabsInstrumentor(BaseInstrumentor):tracer, pricing_info, trace_content, metrics, disable_metrics),)+ # sync text_to_speech.convert+ wrap_function_wrapper(+ "elevenlabs.text_to_speech.client",+ "AsyncTextToSpeechClient.convert",+ generate("elevenlabs.text_to_speech", version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics),+ )+def _uninstrument(self, **kwargs):# Proper uninstrumentation logic to revert patched methodspassdiff --git a/sdk/python/src/openlit/instrumentation/elevenlabs/elevenlabs.py b/sdk/python/src/openlit/instrumentation/elevenlabs/elevenlabs.pyindex 92e17ff1..235c0463 100644--- a/sdk/python/src/openlit/instrumentation/elevenlabs/elevenlabs.py+++ b/sdk/python/src/openlit/instrumentation/elevenlabs/elevenlabs.py@@ -68,11 +68,17 @@ def generate(gen_ai_endpoint, version, environment, application_name,environment)span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,application_name)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,+ if gen_ai_endpoint == "elevenlabs.generate":+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,kwargs.get("model", "eleven_multilingual_v2"))- if isinstance(kwargs.get("voice", "Rachel"), str):+ if isinstance(kwargs.get("voice", "Rachel"), str):+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_AUDIO_VOICE,+ kwargs.get("voice", "Rachel"))+ else:+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,+ kwargs.get("model_id", "eleven_multilingual_v2"))span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_AUDIO_VOICE,- kwargs.get("voice", "Rachel"))+ kwargs.get("voice_id", ""))span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_AUDIO_RESPONSE_FORMAT,kwargs.get("output_format", "mp3"))span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_AUDIO_SETTINGS,diff --git a/sdk/python/tests/test_elevenlabs.py b/sdk/python/tests/test_elevenlabs.pyindex 2e63bc94..49308411 100644--- a/sdk/python/tests/test_elevenlabs.py+++ b/sdk/python/tests/test_elevenlabs.py@@ -61,6 +61,30 @@ def test_sync_elevenlabs_generate():else:raise+def test_sync_elevenlabs_t2s():+ """+ Tests synchronous text-to-speech with the 'eleven_multilingual_v2' model.++ Raises:+ AssertionError: If the text-to-speech response object is not as expected.+ """++ try:+ audio = sync_client.text_to_speech.convert(+ voice_id="21m00Tcm4TlvDq8ikWAM",+ output_format="mp3_22050_32",+ text="Say Monitoring LLM Applications",+ model_id="eleven_multilingual_v2",+ )+ assert isinstance(audio, types.GeneratorType)++ # pylint: disable=broad-exception-caught+ except Exception as e:+ if "rate limit" in str(e).lower():+ print("Rate Limited:", e)+ else:+ raise+@pytest.mark.asyncioasync def test_async_elevenlabs_generate():"""@@ -92,3 +116,28 @@ async def test_async_elevenlabs_generate():print("Rate Limited:", e)else:raise++async def test_async_elevenlabs_t2s():+ """+ Tests synchronous text-to-speech with the 'eleven_multilingual_v2' model.++ Raises:+ AssertionError: If the text-to-speech response object is not as expected.+ """++ try:+ audio = async_client.text_to_speech.convert(+ voice_id="21m00Tcm4TlvDq8ikWAM",+ output_format="mp3_22050_32",+ text="Say Monitoring LLM Applications",+ model_id="eleven_multilingual_v2",+ )+ assert isinstance(audio, types.AsyncGeneratorType)++ # pylint: disable=broad-exception-caught+ except Exception as e:+ if "rate limit" in str(e).lower():+ print("Rate Limited:", e)+ else:+ raise