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 Testing for OpenTelemetry Instrumentations (#520)
Patcherb5e6ac4d52ab
diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.ymlindex 20c47a7a..1c55fae5 100644--- a/.github/workflows/pylint.yml+++ b/.github/workflows/pylint.yml@@ -49,7 +49,7 @@ jobs:needs: checkstrategy:matrix:- python-version: ["3.9", "3.10", "3.11"]+ python-version: ["3.10", "3.11", "3.12", "3.13"]steps:- name: Checkout base codediff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.ymlindex 8fb8a771..5e67d98e 100644--- a/.github/workflows/python-tests.yml+++ b/.github/workflows/python-tests.yml@@ -14,19 +14,23 @@ on:- cron: '0 0 1-31/15 * *'env:- OPENAI_API_TOKEN: ${{ secrets.OPENAI_API_TOKEN }}- COHERE_API_TOKEN: ${{ secrets.COHERE_API_TOKEN }}- ANTHROPIC_API_TOKEN: ${{ secrets.ANTHROPIC_API_TOKEN }}- MISTRAL_API_TOKEN: ${{ secrets.MISTRAL_API_TOKEN }}- PINECONE_API_TOKEN: ${{ secrets.PINECONE_API_TOKEN }}- GROQ_API_TOKEN: ${{ secrets.GROQ_API_TOKEN }}+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_TOKEN }}+ CO_API_KEY: ${{ secrets.CO_API_KEY }}+ ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}+ MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}+ PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}+ GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}QDRANT_URL: ${{ secrets.QDRANT_URL }}QDRANT_API_TOKEN: ${{ secrets.QDRANT_API_TOKEN }}MILVUS_URL: ${{ secrets.MILVUS_URL }}MILVUS_API_TOKEN: ${{ secrets.MILVUS_API_TOKEN }}- ELEVENLABS_API_TOKEN: ${{ secrets.ELEVENLABS_API_TOKEN }}+ ELEVEN_API_KEY: ${{ secrets.ELEVEN_API_KEY }}GOOGLE_AI_STUDIO_API_TOKEN: ${{ secrets.GOOGLE_AI_STUDIO_API_TOKEN }}AZURE_AI_INFERENCE_API_TOKEN: ${{ secrets.AZURE_AI_INFERENCE_API_TOKEN }}+ REKA_API_KEY: ${{ secrets.REKA_API_KEY }}+ PREM_API_KEY: ${{ secrets.PREM_API_KEY }}+ MULTION_API_KEY: ${{ secrets.MULTION_API_KEY }}+ XAI_API_KEY: ${{ secrets.XAI_API_KEY }}jobs:build:@@ -34,7 +38,7 @@ jobs:strategy:fail-fast: falsematrix:- python-version: ["3.9", "3.10", "3.11"]+ python-version: ["3.10", "3.11", "3.12"]steps:- name: Checkout base codediff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.tomlindex ae886b70..f8cd0df1 100644--- a/sdk/python/pyproject.toml+++ b/sdk/python/pyproject.toml@@ -1,6 +1,6 @@[tool.poetry]name = "openlit"-version = "1.32.0"+version = "1.32.1"description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, 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/multion/__init__.py b/sdk/python/src/openlit/instrumentation/multion/__init__.pyindex ee85c688..65a4bb65 100644--- a/sdk/python/src/openlit/instrumentation/multion/__init__.py+++ b/sdk/python/src/openlit/instrumentation/multion/__init__.py@@ -10,6 +10,10 @@ from openlit.instrumentation.multion.multion import (multion_wrap)+from openlit.instrumentation.multion.async_multion import (+ async_multion_wrap+)+_instruments = ("multion >= 1.3.8",)class MultiOnInstrumentor(BaseInstrumentor):@@ -30,20 +34,19 @@ class MultiOnInstrumentor(BaseInstrumentor):disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("multion")+ # Synchronuswrap_function_wrapper("multion.client","MultiOn.browse",multion_wrap("multion.browse", version, environment, application_name,tracer, pricing_info, trace_content, metrics, disable_metrics),)-wrap_function_wrapper("multion.client","MultiOn.retrieve",multion_wrap("multion.retrieve", version, environment, application_name,tracer, pricing_info, trace_content, metrics, disable_metrics),)-wrap_function_wrapper("multion.sessions.client","SessionsClient.create",@@ -51,6 +54,26 @@ class MultiOnInstrumentor(BaseInstrumentor):tracer, pricing_info, trace_content, metrics, disable_metrics),)+ # Asynchronus+ wrap_function_wrapper(+ "multion.client",+ "AsyncMultiOn.browse",+ async_multion_wrap("multion.browse", version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics),+ )+ wrap_function_wrapper(+ "multion.client",+ "AsyncMultiOn.retrieve",+ async_multion_wrap("multion.retrieve", version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics),+ )+ wrap_function_wrapper(+ "multion.sessions.client",+ "AsyncSessionsClient.create",+ async_multion_wrap("multion.sessions.create", version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics),+ )+def _uninstrument(self, **kwargs):# Proper uninstrumentation logic to revert patched methodsdiff --git a/sdk/python/src/openlit/instrumentation/multion/async_multion.py b/sdk/python/src/openlit/instrumentation/multion/async_multion.pynew file mode 100644index 00000000..683b76b6--- /dev/null+++ b/sdk/python/src/openlit/instrumentation/multion/async_multion.py@@ -0,0 +1,131 @@+# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, too-many-branches+"""+Module for monitoring multion calls.+"""++import logging+from opentelemetry.trace import SpanKind, Status, StatusCode+from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME+from openlit.__helpers import (+ handle_exception,+)+from openlit.semcov import SemanticConvetion++# Initialize logger for logging potential issues and operations+logger = logging.getLogger(__name__)++def async_multion_wrap(gen_ai_endpoint, version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics):+ """+ Generates a telemetry wrapper for chat completions to collect metrics.++ Args:+ gen_ai_endpoint: Endpoint identifier for logging and tracing.+ version: Version of the monitoring package.+ environment: Deployment environment (e.g., production, staging).+ application_name: Name of the application using the multion Agent.+ tracer: OpenTelemetry tracer for creating spans.+ pricing_info: Information used for calculating the cost of multion usage.+ trace_content: Flag indicating whether to trace the actual content.++ Returns:+ A function that wraps the chat completions method to add telemetry.+ """++ async def wrapper(wrapped, instance, args, kwargs):+ """+ Wraps the 'chat.completions' API call to add telemetry.++ This collects metrics such as execution time, cost, and token usage, and handles errors+ gracefully, adding details to the trace for observability.++ Args:+ wrapped: The original 'chat.completions' method to be wrapped.+ instance: The instance of the class where the original method is defined.+ args: Positional arguments for the 'chat.completions' method.+ kwargs: Keyword arguments for the 'chat.completions' method.++ Returns:+ The response from the original 'chat.completions' method.+ """++ # pylint: disable=line-too-long+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:+ response = await wrapped(*args, **kwargs)++ try:+ # Set base span attribues+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,+ SemanticConvetion.GEN_AI_SYSTEM_MULTION)+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,+ SemanticConvetion.GEN_AI_TYPE_AGENT)+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,+ gen_ai_endpoint)+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,+ application_name)++ if gen_ai_endpoint == "multion.browse":+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_BROWSE_URL,+ kwargs.get("url", ""))+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_STEP_COUNT,+ response.metadata.step_count)+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_RESPONSE_TIME,+ response.metadata.processing_time)++ if trace_content:+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("cmd", ""),+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.message,+ },+ )+ elif gen_ai_endpoint == "multion.retrieve":+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_BROWSE_URL,+ kwargs.get("url", ""))++ if trace_content:+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("cmd", ""),+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.message,+ },+ )++ elif gen_ai_endpoint == "multion.sessions.create":+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_BROWSE_URL,+ kwargs.get("url", ""))++ if trace_content:+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.message,+ },+ )++ span.set_status(Status(StatusCode.OK))++ # Return original response+ return response++ except Exception as e:+ handle_exception(span, e)+ logger.error("Error in trace creation: %s", e)++ # Return original response+ return response++ return wrapperdiff --git a/sdk/python/src/openlit/instrumentation/multion/multion.py b/sdk/python/src/openlit/instrumentation/multion/multion.pyindex 1ef26650..fad67349 100644--- a/sdk/python/src/openlit/instrumentation/multion/multion.py+++ b/sdk/python/src/openlit/instrumentation/multion/multion.py@@ -4,7 +4,6 @@ Module for monitoring multion calls."""import logging-import jsonfrom opentelemetry.trace import SpanKind, Status, StatusCodefrom opentelemetry.sdk.resources import TELEMETRY_SDK_NAMEfrom openlit.__helpers import (@@ -15,18 +14,6 @@ from openlit.semcov import SemanticConvetion# Initialize logger for logging potential issues and operationslogger = logging.getLogger(__name__)-def _parse_tools(tools):- result = []- for tool in tools:- res = {}- if hasattr(tool, "name") and tool.name is not None:- res["name"] = tool.name- if hasattr(tool, "description") and tool.description is not None:- res["description"] = tool.description- if res:- result.append(res)- return json.dumps(result)-def multion_wrap(gen_ai_endpoint, version, environment, application_name,tracer, pricing_info, trace_content, metrics, disable_metrics):"""@@ -129,40 +116,6 @@ def multion_wrap(gen_ai_endpoint, version, environment, application_name,},)- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TASK_ID,- # task.get('id', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TASK,- # task.get('description', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_EXPECTED_OUTPUT,- # task.get('expected_output', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ACTUAL_OUTPUT,- # task.get('output', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_HUMAN_INPUT,- # task.get('human_input', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TASK_ASSOCIATION,- # str(task.get('processed_by_agents', '')))-- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ID,- # agent.get('id', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ROLE,- # agent.get('role', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_GOAL,- # agent.get('goal', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_CONTEXT,- # agent.get('backstory', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ENABLE_CACHE,- # agent.get('cache', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ALLOW_DELEGATION,- # agent.get('allow_delegation', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ALLOW_CODE_EXECUTION,- # agent.get('allow_code_execution', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_MAX_RETRY_LIMIT,- # agent.get('max_retry_limit', ''))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TOOLS,- # str(agent.get('tools', '')))- # span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TOOL_RESULTS,- # str(agent.get('tools_results', '')))-span.set_status(Status(StatusCode.OK))# Return original responsediff --git a/sdk/python/tests/requirements.txt b/sdk/python/tests/requirements.txtindex 2fd68417..85957e0c 100644--- a/sdk/python/tests/requirements.txt+++ b/sdk/python/tests/requirements.txt@@ -1,47 +1,51 @@# Development-pytest>=7.4.0-pytest-asyncio>=0.23.6-requests>=2.31.0-schedule>=1.2.2-pylint>=3.0.2+pytest+pytest-asyncio+requests+schedule+pylint# Gen AI-cohere>=5.0.0-openai>=1.1.1-anthropic>=0.21.0-mistralai>=1.0.0-transformers>=4.39.3-boto3>=1.34.93-botocore>=1.34.93-google-cloud-aiplatform >= 1.38.1-groq >= 0.5.0-elevenlabs >= 1.4.0-google-generativeai >= 0.7.2-azure-ai-inference >= 1.0.0b4+cohere+openai+anthropic+mistralai+transformers+boto3+botocore+google-cloud-aiplatform+groq+elevenlabs+google-generativeai+azure-ai-inference+reka-api+premai+multion+mem0ai# Vector DBs-chromadb>=0.4.0-pinecone-client>=2.2.0-qdrant-client>=1.9.0-pymilvus>=2.4.3+chromadb+pinecone-client+qdrant-client+pymilvus# Frameworks-langchain>=0.1.20-langchainhub>=0.1.20-embedchain>=0.1.104+langchain+langchainhub+embedchain# GPU-xmltodict>=0.13.0+xmltodict# Utilitiesbs4-tiktoken>=0.7.0-tensorflow>=2.16.1-tf_keras>=2.16.0-aiohttp >= 3.10.5+tiktoken+tensorflow+tf_keras+aiohttp# OpenTelemetry-opentelemetry-api>=1.24.0-opentelemetry-sdk>=1.24.0-opentelemetry-exporter-otlp>=1.24.0-opentelemetry-instrumentation>=0.45b0+opentelemetry-api+opentelemetry-sdk+opentelemetry-exporter-otlp+opentelemetry-instrumentationdiff --git a/sdk/python/tests/test_anthropic.py b/sdk/python/tests/test_anthropic.pyindex 8b46258c..1ecbdc8d 100644--- a/sdk/python/tests/test_anthropic.py+++ b/sdk/python/tests/test_anthropic.py@@ -6,29 +6,24 @@ Tests cover various API endpoints, including chat.These tests validate integration with OpenLIT.Environment Variables:- - ANTHROPIC_API_TOKEN: Anthropic API api_key for authentication.+ - ANTHROPIC_API_KEY: Anthropic API key for authentication.Note: Ensure the environment is properly configured for Anthropic access and OpenLIT monitoringprior to running these tests."""-import osimport pytestfrom anthropic import Anthropic, AsyncAnthropicimport openlit# Initialize synchronous Anthropic client-sync_client = Anthropic(- api_key=os.getenv("ANTHROPIC_API_TOKEN")-)+sync_client = Anthropic()# Initialize asynchronous Anthropic client-async_client = AsyncAnthropic(- api_key=os.getenv("ANTHROPIC_API_TOKEN")-)+async_client = AsyncAnthropic()# Initialize environment and application name for OpenLIT monitoring-openlit.init(environment="openlit-testing", application_name="openlit-python-test")+openlit.init(environment="openlit-python-testing", application_name="openlit-python-anthropic-test")def test_sync_anthropic_messages():"""diff --git a/sdk/python/tests/test_cohere.py b/sdk/python/tests/test_cohere.pyindex 06f7d5cd..07bb430b 100644--- a/sdk/python/tests/test_cohere.py+++ b/sdk/python/tests/test_cohere.py@@ -6,26 +6,25 @@ Tests cover various API endpoints, including chat and embeddings.These tests validate integration with OpenLIT.Environment Variables:- - COHERE_API_TOKEN: Cohere API api_key for authentication.+ - CO_API_KEY: Cohere API key for authentication.Note: Ensure the environment is properly configured for Cohere access and OpenLIT monitoringprior to running these tests."""-import osimport cohereimport openlit# Initialize synchronous Cohere client-sync_client = cohere.Client(os.getenv("COHERE_API_TOKEN"))+sync_client = cohere.Client()# Initialize environment and application name for OpenLIT monitoring-openlit.init(environment="openlit-testing", application_name="openlit-python-test")+openlit.init(environment="openlit-python-testing", application_name="openlit-python-cohere-test")def test_embed():"""- Tests synchronous embedding creation with the 'embed-english-v3.0' model.+ Tests synchronous embedding creation.Raises:AssertionError: If the embedding response object is not as expected.@@ -46,7 +45,7 @@ def test_embed():def test_chat():"""- Tests synchronous chat with the 'command' model.+ Tests synchronous chat.Raises:AssertionError: If the chat response object is not as expected.diff --git a/sdk/python/tests/test_elevenlabs.py b/sdk/python/tests/test_elevenlabs.pyindex 694f19b9..0ef7c21c 100644--- a/sdk/python/tests/test_elevenlabs.py+++ b/sdk/python/tests/test_elevenlabs.py@@ -2,33 +2,31 @@"""This module contains tests for ElevenLabs functionality using the ElevenLabs Python library.-Tests cover various API endpoints, including chat.+Tests cover various API endpoints.These tests validate integration with OpenLIT.Environment Variables:- - ELEVENLABS_API_TOKEN: GroElevenLabsq API api_key for authentication.+ - ELEVEN_API_KEY: ElevenLabs API key for authentication.Note: Ensure the environment is properly configured for ElevenLabs access and OpenLIT monitoringprior to running these tests."""-import osimport typesimport pytestfrom elevenlabs.client import ElevenLabs, AsyncElevenLabsimport openlit# Initialize synchronous ElevenLabs client-sync_client = ElevenLabs(- api_key=os.getenv("ELEVENLABS_API_TOKEN")-)+sync_client = ElevenLabs()-async_client = AsyncElevenLabs(- api_key=os.getenv("ELEVENLABS_API_TOKEN")-)+async_client = AsyncElevenLabs()# Initialize environment and application name for OpenLIT monitoring-openlit.init(environment="openlit-testing", application_name="openlit-python-test")+openlit.init(+ environment="openlit-python-testing",+ application_name="openlit-python-elevenlabs-test"+)def test_sync_elevenlabs_generate():"""diff --git a/sdk/python/tests/test_mem0.py b/sdk/python/tests/test_mem0.pynew file mode 100644index 00000000..4c2bc490--- /dev/null+++ b/sdk/python/tests/test_mem0.py@@ -0,0 +1,89 @@+# pylint: disable=duplicate-code, no-name-in-module+"""+This module contains tests for mem0 functionality using the mem0ai Python library.++Tests cover various SDK functions.+These tests validate integration with OpenLIT.++Environment Variables:+ - OPENAI_API_KEY: OpenAI API key for authentication.++Note: Ensure the environment is properly configured for mem0 and OpenLIT monitoring+prior to running these tests.+"""++from mem0 import Memory+import openlit++# Initialize synchronous mem0 client+sync_memory = Memory()++# Initialize environment and application name for OpenLIT monitoring+openlit.init(environment="openlit-python-testing", application_name="openlit-python-mem0-test")++def test_sync_memory_add():+ """+ Tests synchronous addition to memory++ Raises:+ AssertionError: If the memory add response object is not as expected.+ """++ try:+ response = sync_memory.add(+ "OpenLIT provides LLM Observability and Agent Observability",+ user_id="openlit",+ metadata={"category": "devtool"})+ assert response[0]["event"] == "ADD"++ # pylint: disable=broad-exception-caught, try-except-raise+ except Exception:+ raise++def test_sync_memory_get_all():+ """+ Tests synchronous get all memory++ Raises:+ AssertionError: If the get all memory response object is not as expected.+ """++ try:+ response = sync_memory.get_all(user_id="openlit")+ assert response[0]["user_id"] == "openlit"++ # pylint: disable=broad-exception-caught, try-except-raise+ except Exception:+ raise++def test_sync_memory_get():+ """+ Tests synchronous get memory++ Raises:+ AssertionError: If the get memory response object is not as expected.+ """++ try:+ response = sync_memory.get("bf4d4092-cf91-4181-bfeb-b6fa2ed3061b")+ assert response is None++ # pylint: disable=broad-exception-caught, try-except-raise+ except Exception:+ raise++def test_sync_memory_search():+ """+ Tests synchronous search memory++ Raises:+ AssertionError: If the search memory response object is not as expected.+ """++ try:+ response = sync_memory.search(query="What does OpenLIT give?", user_id="openlit")+ assert isinstance(response, list)++ # pylint: disable=broad-exception-caught, try-except-raise+ except Exception:+ raisediff --git a/sdk/python/tests/test_mistral.py b/sdk/python/tests/test_mistral.pyindex efe0141d..3dda3526 100644--- a/sdk/python/tests/test_mistral.py+++ b/sdk/python/tests/test_mistral.py@@ -6,24 +6,21 @@ Tests cover various API endpoints, including chat and embeddings.These tests validate integration with OpenLIT.Environment Variables:- - Mistral_API_TOKEN: Mistral API api_key for authentication.+ - MISTRAL_API_KEY: Mistral API key for authentication.Note: Ensure the environment is properly configured for Mistral access and OpenLIT monitoringprior to running these tests."""-import osimport pytestfrom mistralai import Mistralimport openlit# Initialize synchronous Mistral client-client = Mistral(- api_key=os.getenv("MISTRAL_API_TOKEN")-)+client = Mistral()# Initialize environment and application name for OpenLIT monitoring-openlit.init(environment="openlit-testing", application_name="openlit-python-test")+openlit.init(environment="openlit-python-testing", application_name="openlit-python-mistral-test")def test_sync_mistral_chat():"""diff --git a/sdk/python/tests/test_multion.py b/sdk/python/tests/test_multion.pynew file mode 100644index 00000000..0db60476--- /dev/null+++ b/sdk/python/tests/test_multion.py@@ -0,0 +1,71 @@+# pylint: disable=duplicate-code, no-name-in-module+"""+This module contains tests for MultiOn functionality using the MultiOn Python library.++Tests cover various API endpoints.+These tests validate integration with OpenLIT.++Environment Variables:+ - MULTION_API_KEY: MultiOn API key for authentication.++Note: Ensure the environment is properly configured for MultiOn access and OpenLIT monitoring+prior to running these tests.+"""++import pytest+from multion.client import MultiOn, AsyncMultiOn+import openlit++# Initialize synchronous MultiOn client+sync_client = MultiOn()++# Initialize asynchronous MultiOn client+async_client = AsyncMultiOn()++# Initialize environment and application name for OpenLIT monitoring+openlit.init(environment="openlit-python-testing", application_name="openlit-python-multion-test")++def test_sync_multion_browse():+ """+ Tests synchronous Agent Browse.++ Raises:+ AssertionError: If the Agent Browse response object is not as expected.+ """++ try:+ response = sync_client.browse(+ url="https://openlit.io",+ cmd="say hi"+ )+ assert response.status == 'DONE'++ # pylint: disable=broad-exception-caught+ except Exception as e:+ if e.status_code == 402:+ print("Insufficient balance:", e)+ else:+ raise++async def test_async_multion_browse():+ """+ Tests asynchronous Agent Browse++ Raises:+ AssertionError: If the Agent Browse response object is not as expected.+ """++ try:+ response = async_client.browse(+ url="https://docs.openlit.io",+ cmd="say hi"+ )+ assert response.status == 'DONE'++ # pylint: disable=broad-exception-caught+ except Exception as e:+ if e.status_code == 402:+ print("Insufficient balance:", e)+ else:+ raisediff --git a/sdk/python/tests/test_openai.py b/sdk/python/tests/test_openai.pyindex e1db22de..3a47718b 100644--- a/sdk/python/tests/test_openai.py+++ b/sdk/python/tests/test_openai.py@@ -7,29 +7,24 @@ embeddings, fine-tuning job creation, image generation, image variation creationand audio speech generation. These tests validate integration with OpenLIT.Environment Variables:- - OPENAI_API_TOKEN: OpenAI API key for authentication.+ - OPENAI_API_KEY: OpenAI API key for authentication.Note: Ensure the environment is properly configured for OpenAI access and OpenLIT monitoringprior to running these tests."""-import osimport pytestfrom openai import OpenAI, AsyncOpenAIimport openlit# Initialize synchronous OpenAI client-sync_client = OpenAI(- api_key=os.getenv("OPENAI_API_TOKEN"),-)+sync_client = OpenAI()# Initialize asynchronous OpenAI client-async_client = AsyncOpenAI(- api_key=os.getenv("OPENAI_API_TOKEN"),-)+async_client = AsyncOpenAI()# Initialize environment and application name for OpenLIT monitoring-openlit.init(environment="openlit-testing", application_name="openlit-python-test")+openlit.init(environment="openlit-python-testing", application_name="openlit-python-openai-test")def test_sync_openai_chat_completions():"""diff --git a/sdk/python/tests/test_pinecone.py b/sdk/python/tests/test_pinecone.pyindex a1c57bb6..6c6f6bb2 100644--- a/sdk/python/tests/test_pinecone.py+++ b/sdk/python/tests/test_pinecone.py@@ -6,22 +6,21 @@ Tests cover various API endpoints, including upsert, query and delete.These tests validate integration with OpenLIT.Environment Variables:- - PINECONE_API_TOKEN: Pinecone API api_key for authentication.+ - PINECONE_API_KEY: Pinecone API key for authentication.Note: Ensure the environment is properly configured for Pinecone access and OpenLIT monitoringprior to running these tests."""-import osfrom pinecone import Pineconeimport openlit# Initialize the Chroma client-pc = Pinecone(api_key=os.getenv("PINECONE_API_TOKEN"))+pc = Pinecone()index = pc.Index("openlit-tests")# Initialize environment and application name for OpenLIT monitoring-openlit.init(environment="openlit-testing", application_name="openlit-python-test")+openlit.init(environment="openlit-python-testing", application_name="openlit-python-piencone-test")def test_db_pinecone():"""diff --git a/sdk/python/tests/test_prem.py b/sdk/python/tests/test_prem.pynew file mode 100644index 00000000..aa3a2cc0--- /dev/null+++ b/sdk/python/tests/test_prem.py@@ -0,0 +1,77 @@+# pylint: disable=duplicate-code, no-name-in-module+"""+This module contains tests for Prem AI functionality using the Prem Python library.++Tests cover various API endpoints, including chat.+These tests validate integration with OpenLIT.++Environment Variables:+ - PREM_API_KEY: Prem API key for authentication.++Note: Ensure the environment is properly configured for Prem access and OpenLIT monitoring+prior to running these tests.+"""++import os+from premai import Prem+import openlit++# Initialize synchronous Prem client+sync_client = Prem(+ api_key=os.getenv("PREM_API_KEY")+)++PROJECT_ID = 7438++# Initialize environment and application name for OpenLIT monitoring+openlit.init(environment="openlit-python-testing", application_name="openlit-python-prem-test")++def test_sync_prem_chat():+ """+ Tests synchronous Chat Completions.++ Raises:+ AssertionError: If the Chat Completions response object is not as expected.+ """++ try:+ response = sync_client.chat.completions.create(+ project_id=PROJECT_ID,+ system_prompt="You're an helpful assistant",+ max_tokens = 1,+ model = "gpt-4o-mini",+ messages = [+ {"role": "user", "content": "Monitor AI Agents with OpenTelemetry"},+ ],+ )+ assert response.additional_properties["status_code"] == 200++ # pylint: disable=broad-exception-caught+ except Exception as e:+ if "insufficient balance" in str(e).lower():+ print("Insufficient balance:", e)+ else:+ raise++def test_sync_prem_embeddings():+ """+ Tests synchronous Embeddings.++ Raises:+ AssertionError: If the Embeddings response object is not as expected.+ """++ try:+ response = sync_client.embeddings.create(+ project_id=PROJECT_ID,+ input = ["LLM Observability"],+ model = "text-embedding-3-large"+ )+ assert response.additional_properties["status_code"] == 200++ # pylint: disable=broad-exception-caught+ except Exception as e:+ if "insufficient balance" in str(e).lower():+ print("Insufficient balance:", e)+ else:+ raisediff --git a/sdk/python/tests/test_reka.py b/sdk/python/tests/test_reka.pynew file mode 100644index 00000000..729ecf8d--- /dev/null+++ b/sdk/python/tests/test_reka.py@@ -0,0 +1,84 @@+# pylint: disable=duplicate-code, no-name-in-module, import-error, no-member+"""+This module contains tests for Reka AI functionality using the Reka Python library.++Tests cover various API endpoints, including chat.+These tests validate integration with OpenLIT.++Environment Variables:+ - REKA_API_KEY: Reka API key for authentication.++Note: Ensure the environment is properly configured for Reka access and OpenLIT monitoring+prior to running these tests.+"""++import pytest+from reka import ChatMessage+from reka.client import Reka, AsyncReka+import openlit++# Initialize synchronous Reka client+sync_client = Reka()++# Initialize asynchronous Reka client+async_client = AsyncReka()++# Initialize environment and application name for OpenLIT monitoring+openlit.init(environment="openlit-python-testing", application_name="openlit-python-reka-test")++def test_sync_reka_chat():+ """+ Tests synchronous Chat Create.++ Raises:+ AssertionError: If the Chat Create response object is not as expected.+ """++ try:+ response = sync_client.chat.create(+ messages=[+ ChatMessage(+ content="How to monitor AI Agents?",+ role="user",+ )+ ],+ model="reka-core",+ max_tokens=1,+ )+ assert response.model == 'reka-core'++ # pylint: disable=broad-exception-caught+ except Exception as e:+ if e.status_code == 429:+ print("Insufficient balance:", e)+ else:+ raise++async def test_async_reka_chat():+ """+ Tests asynchronous Chat Create++ Raises:+ AssertionError: If the Chat Create response object is not as expected.+ """++ try:+ response = await async_client.chat.create(+ messages=[+ ChatMessage(+ content="How to monitor AI Agents?",+ role="user",+ )+ ],+ model="reka-core",+ max_tokens=1,+ )+ assert response.model == 'reka-core'++ # pylint: disable=broad-exception-caught+ except Exception as e:+ if e.status_code == 429:+ print("Insufficient balance:", e)+ else:+ raisediff --git a/sdk/python/tests/test_xai.py b/sdk/python/tests/test_xai.pynew file mode 100644index 00000000..476f9e6d--- /dev/null+++ b/sdk/python/tests/test_xai.py@@ -0,0 +1,70 @@+# pylint: disable=duplicate-code, consider-using-with, no-name-in-module+"""+This module contains tests for xAI functionality using the OpenAI Python library.++Tests cover various API endpoints, including completions, chat completions,+embeddings, fine-tuning job creation, image generation, image variation creation,+and audio speech generation. These tests validate integration with OpenLIT.++Environment Variables:+ - XAI_API_KEY: xAI API key for authentication.++Note: Ensure the environment is properly configured for xAI access and OpenLIT monitoring+prior to running these tests.+"""++import os+import pytest+from openai import OpenAI, AsyncOpenAI+import openlit++# Initialize synchronous OpenAI client+sync_client = OpenAI(+ api_key=os.getenv("XAI_API_KEY"),+ base_url="https://api.x.ai/v1",+)++# Initialize asynchronous OpenAI client+async_client = AsyncOpenAI(+ api_key=os.getenv("XAI_API_KEY"),+ base_url="https://api.x.ai/v1",+)++# Initialize environment and application name for OpenLIT monitoring+openlit.init(environment="openlit-python-testing", application_name="openlit-python-xai-test")++def test_sync_xai_chat_completions():+ """+ Tests synchronous chat completions++ Raises:+ AssertionError: If the chat completion response object is not as expected.+ """++ response = sync_client.chat.completions.create(+ model="grok-beta",+ messages=[+ {"role": "user", "content": "Hi"},+ ],+ max_tokens=1,+ )+ assert response.object == 'chat.completion'+++async def test_async_xai_chat_completions():+ """+ Tests asynchronous chat completions.++ Raises:+ AssertionError: If the chat completion response object is not as expected.+ """++ response = async_client.chat.completions.create(+ model="grok-beta",+ messages=[+ {"role": "user", "content": "Hi"},+ ],+ max_tokens=1,+ )+ assert response.object == 'chat.completion'