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]: Refactor HuggingFace Transformers OpenTelemetry Instrumentation (#716)
Patcher2e99449b6d6a
diff --git a/docs/latest/integrations/huggingface.mdx b/docs/latest/integrations/huggingface.mdxindex 5a2d7e00..5a68865b 100644--- a/docs/latest/integrations/huggingface.mdx+++ b/docs/latest/integrations/huggingface.mdx@@ -12,7 +12,7 @@ OpenLIT uses OpenTelemetry Auto-Instrumentation to help you monitor LLM applicatAuto-instrumentation means you don't have to set up monitoring manually for different LLMs, frameworks, or databases. By simply adding OpenLIT in your application, all the necessary monitoring configurations are automatically set up.The integration is compatible with-- HuggingFace Trasnformers Python SDK client `>= 4.39.3`+- HuggingFace Trasnformers Python SDK client `>= 4.48.0`## Get Starteddiff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.tomlindex 24e09aa2..042557ce 100644--- a/sdk/python/pyproject.toml+++ b/sdk/python/pyproject.toml@@ -1,6 +1,6 @@[tool.poetry]name = "openlit"-version = "1.33.20"+version = "1.33.21"description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects"authors = ["OpenLIT"]license = "Apache-2.0"diff --git a/sdk/python/src/openlit/__helpers.py b/sdk/python/src/openlit/__helpers.pyindex b8851d60..417e61cc 100644--- a/sdk/python/src/openlit/__helpers.py+++ b/sdk/python/src/openlit/__helpers.py@@ -240,6 +240,11 @@ def extract_and_format_input(messages):fixed_roles = ['user', 'assistant', 'system', 'tool', 'developer']formatted_messages = {role_key: {'role': '', 'content': ''} for role_key in fixed_roles}+ # Check if input is a simple string+ if isinstance(messages, str):+ formatted_messages['user'] = {'role': 'user', 'content': messages}+ return formatted_messages+for message in messages:message = response_as_dict(message)@@ -276,3 +281,55 @@ def concatenate_all_contents(formatted_messages):for message_data in formatted_messages.values()if message_data['content'])++def format_and_concatenate(messages):+ """+ Process a list of messages to extract content, categorize them by role,+ and concatenate all 'content' fields into a single string with role: content format.+ """++ formatted_messages = {}++ # Check if input is a simple string+ if isinstance(messages, str):+ formatted_messages['user'] = {'role': 'user', 'content': messages}+ elif isinstance(messages, list) and all(isinstance(m, str) for m in messages):+ # If it's a list of strings, each string is 'user' input+ user_content = ' '.join(messages)+ formatted_messages['user'] = {'role': 'user', 'content': user_content}+ else:+ for message in messages:+ message = response_as_dict(message)+ role = message.get('role', 'unknown') # Default to 'unknown' if no role is specified+ content = message.get('content', '')++ # Initialize role in formatted messages if not present+ if role not in formatted_messages:+ formatted_messages[role] = {'role': role, 'content': ''}++ # Handle list of dictionaries in content+ if isinstance(content, list):+ content_str = []+ for item in content:+ if isinstance(item, dict):+ # Collect text or other attributes as needed+ text = item.get('text', '')+ image_url = item.get('image_url', '')+ content_str.append(text)+ content_str.append(image_url)+ content_str = ", ".join(filter(None, content_str))+ else:+ content_str = content++ # Concatenate content+ if formatted_messages[role]['content']:+ formatted_messages[role]['content'] += ' ' + content_str+ else:+ formatted_messages[role]['content'] = content_str++ # Concatenate role and content for all messages+ return ' '.join(+ f"{message_data['role']}: {message_data['content']}"+ for message_data in formatted_messages.values()+ if message_data['content']+ )diff --git a/sdk/python/src/openlit/instrumentation/transformers/__init__.py b/sdk/python/src/openlit/instrumentation/transformers/__init__.pyindex d38d8f47..24a17af2 100644--- a/sdk/python/src/openlit/instrumentation/transformers/__init__.py+++ b/sdk/python/src/openlit/instrumentation/transformers/__init__.py@@ -1,16 +1,20 @@-# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code-"""Initializer of Auto Instrumentation of HuggingFace Transformer Functions"""+"""+Initializer of Auto Instrumentation of HuggingFace Transformer Functions+"""+from typing import Collectionimport importlib.metadatafrom opentelemetry.instrumentation.instrumentor import BaseInstrumentorfrom wrapt import wrap_function_wrapper-from openlit.instrumentation.transformers.transformers import text_wrap+from openlit.instrumentation.transformers.transformers import pipeline_wrapper-_instruments = ("transformers >= 4.39.3",)+_instruments = ("transformers >= 4.48.0",)class TransformersInstrumentor(BaseInstrumentor):- """An instrumentor for HuggingFace Transformer Functions."""+ """+ An instrumentor for HuggingFace Transformer library.+ """def instrumentation_dependencies(self) -> Collection[str]:return _instruments@@ -28,10 +32,10 @@ class TransformersInstrumentor(BaseInstrumentor):wrap_function_wrapper("transformers","TextGenerationPipeline.__call__",- text_wrap(version, environment, application_name,+ pipeline_wrapper(version, environment, application_name,tracer, pricing_info, capture_message_content, metrics, disable_metrics),)- @staticmethoddef _uninstrument(self, **kwargs):+ # Proper uninstrumentation logic to revert patched methodspassdiff --git a/sdk/python/src/openlit/instrumentation/transformers/transformers.py b/sdk/python/src/openlit/instrumentation/transformers/transformers.pyindex d5a6f20f..bba9a9a2 100644--- a/sdk/python/src/openlit/instrumentation/transformers/transformers.py+++ b/sdk/python/src/openlit/instrumentation/transformers/transformers.py@@ -1,63 +1,31 @@"""-Module for monitoring ChromaDB.+Module for monitoring HF Transformers API calls."""import loggingimport time-from opentelemetry.trace import SpanKind, Status, StatusCode-from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT+from opentelemetry.trace import SpanKindfrom openlit.__helpers import (- get_chat_model_cost,- handle_exception,- general_tokens,- create_metrics_attributes,set_server_address_and_port)++from openlit.instrumentation.transformers.utils import (+ process_chat_response,+)from openlit.semcov import SemanticConvention# Initialize logger for logging potential issues and operationslogger = logging.getLogger(__name__)-def text_wrap(version, environment, application_name,- tracer, pricing_info, capture_message_content, metrics, disable_metrics):+def pipeline_wrapper(version, environment, application_name,+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""- Creates a wrapper around a function call to trace and log its execution metrics.-- This function wraps any given function to measure its execution time,- log its operation, and trace its execution using OpenTelemetry.-- Parameters:- - version (str): The version of the Langchain application.- - environment (str): The deployment environment (e.g., 'production', 'development').- - application_name (str): Name of the Langchain application.- - tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- - pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - capture_message_content (bool): Flag indicating whether to trace the content of the response.-- Returns:- - function: A higher-order function that takes a function 'wrapped' and returns- a new function that wraps 'wrapped' with additional tracing and logging.+ Generates a telemetry wrapper for GenAI function call"""def wrapper(wrapped, instance, args, kwargs):"""- An inner wrapper function that executes the wrapped function, measures execution- time, and records trace data using OpenTelemetry.-- Parameters:- - wrapped (Callable): The original function that this wrapper will execute.- - instance (object): The instance to which the wrapped function belongs. This- is used for instance methods. For static and classmethods,- this may be None.- - args (tuple): Positional arguments passed to the wrapped function.- - kwargs (dict): Keyword arguments passed to the wrapped function.-- Returns:- - The result of the wrapped function call.-- The wrapper initiates a span with the provided tracer, sets various attributes- on the span based on the function's execution and response, and ensures- errors are handled and logged appropriately.+ Wraps the GenAI function call."""server_address, server_port = set_server_address_and_port(instance, "127.0.0.1", 80)@@ -68,130 +36,26 @@ def text_wrap(version, environment, application_name,with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:start_time = time.time()response = wrapped(*args, **kwargs)- end_time = time.time()-- # pylint: disable=protected-access- forward_params = instance._forward_params-- try:- if args and len(args) > 0:- prompt = args[0]- else:- prompt = kwargs.get("args", "")-- input_tokens = general_tokens(prompt[0])-- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")- span.set_attribute(SemanticConvention.GEN_AI_OPERATION,- SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)- span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,- SemanticConvention.GEN_AI_SYSTEM_HUGGING_FACE)- span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,- request_model)- span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,- forward_params.get("temperature", "null"))- span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,- forward_params.get("top_p", "null"))- span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,- forward_params.get("max_length", -1))- span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,- input_tokens)- span.set_attribute(SemanticConvention.SERVER_ADDRESS,- server_address)- span.set_attribute(SemanticConvention.SERVER_PORT,- server_port)- span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,- request_model)-- span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- span.set_attribute(SERVICE_NAME,- application_name)- span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,- False)- span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,- end_time - start_time)- span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,- version)- if capture_message_content:- span.add_event(- name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,- attributes={- SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,- },- )-- i = 0- output_tokens = 0- for completion in response:- if len(response) > 1:- attribute_name = f"gen_ai.content.completion.{i}"- else:- attribute_name = SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT- if capture_message_content:- # pylint: disable=bare-except- try:- llm_response = completion.get('generated_text', '')- except:- llm_response = completion[i].get('generated_text', '')-- span.add_event(- name=attribute_name,- attributes={- SemanticConvention.GEN_AI_CONTENT_COMPLETION: llm_response,- },- )- output_tokens += general_tokens(llm_response)-- i=i+1- span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,- output_tokens)- span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,- input_tokens + output_tokens)-- # Calculate cost of the operation- cost = get_chat_model_cost(request_model,- pricing_info, input_tokens,- output_tokens)- span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,- cost)-- span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,- system=SemanticConvention.GEN_AI_SYSTEM_HUGGING_FACE,- request_model=request_model,- server_address=server_address,- server_port=server_port,- response_model=request_model,- )-- metrics["genai_client_usage_tokens"].record(- input_tokens + output_tokens, attributes- )- metrics["genai_client_operation_duration"].record(- end_time - start_time, attributes- )- metrics["genai_server_ttft"].record(- end_time - start_time, attributes- )- metrics["genai_requests"].add(1, attributes)- metrics["genai_completion_tokens"].add(output_tokens, attributes)- metrics["genai_prompt_tokens"].add(input_tokens, attributes)- metrics["genai_cost"].record(cost, attributes)-- # 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+ response = process_chat_response(+ instance = instance,+ response=response,+ request_model=request_model,+ pricing_info=pricing_info,+ server_port=server_port,+ server_address=server_address,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ start_time=start_time,+ span=span,+ args=args,+ kwargs=kwargs,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version,+ )++ return responsereturn wrapperdiff --git a/sdk/python/src/openlit/instrumentation/transformers/utils.py b/sdk/python/src/openlit/instrumentation/transformers/utils.pynew file mode 100644index 00000000..b437095e--- /dev/null+++ b/sdk/python/src/openlit/instrumentation/transformers/utils.py@@ -0,0 +1,183 @@+"""+HF Transformers OpenTelemetry instrumentation utility functions+"""+import time++from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT+from opentelemetry.trace import Status, StatusCode++from openlit.__helpers import (+ response_as_dict,+ calculate_tbt,+ general_tokens,+ get_chat_model_cost,+ create_metrics_attributes,+ format_and_concatenate+)+from openlit.semcov import SemanticConvention++def common_chat_logic(scope, pricing_info, environment, application_name, metrics,+ capture_message_content, disable_metrics, version, args, kwargs, is_stream):++ """+ Process chat request and generate Telemetry+ """++ scope._end_time = time.time()+ if len(scope._timestamps) > 1:+ scope._tbt = calculate_tbt(scope._timestamps)++ forward_params = scope._instance._forward_params+ request_model = scope._instance.model.config.name_or_path++ input_tokens = general_tokens(scope._prompt)+ output_tokens = general_tokens(scope._llmresponse)++ cost = get_chat_model_cost(request_model, pricing_info, input_tokens, output_tokens)++ # Set Span attributes (OTel Semconv)+ scope._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")+ scope._span.set_attribute(SemanticConvention.GEN_AI_OPERATION, SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)+ scope._span.set_attribute(SemanticConvention.GEN_AI_SYSTEM, SemanticConvention.GEN_AI_SYSTEM_HUGGING_FACE)+ scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL, request_model)+ scope._span.set_attribute(SemanticConvention.SERVER_PORT, scope._server_port)++ # List of attributes and their config keys+ attributes = [+ (SemanticConvention.GEN_AI_REQUEST_TEMPERATURE, "temperature"),+ (SemanticConvention.GEN_AI_REQUEST_TOP_K, "top_k"),+ (SemanticConvention.GEN_AI_REQUEST_TOP_P, "top_p"),+ (SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS, "max_length"),+ ]++ # Set each attribute if the corresponding value exists and is not None+ for attribute, key in attributes:+ value = forward_params.get(key)+ if value is not None:+ scope._span.set_attribute(attribute, value)++ scope._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL, request_model)+ scope._span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)+ scope._span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS, output_tokens)+ scope._span.set_attribute(SemanticConvention.SERVER_ADDRESS, scope._server_address)+ scope._span.set_attribute(DEPLOYMENT_ENVIRONMENT, environment)+ scope._span.set_attribute(SERVICE_NAME, application_name)+ scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM, is_stream)+ scope._span.set_attribute(SemanticConvention.GEN_AI_CLIENT_TOKEN_USAGE, input_tokens + output_tokens)+ scope._span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST, cost)+ scope._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TBT, scope._tbt)+ scope._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT, scope._ttft)+ scope._span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION, version)++ # To be removed one the change to span_attributes (from span events) is complete+ if capture_message_content:+ scope._span.set_attribute(SemanticConvention.GEN_AI_CONTENT_PROMPT, scope._prompt)+ scope._span.set_attribute(SemanticConvention.GEN_AI_CONTENT_COMPLETION, scope._llmresponse,)++ scope._span.add_event(+ name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvention.GEN_AI_CONTENT_PROMPT: scope._prompt,+ },+ )+ scope._span.add_event(+ name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvention.GEN_AI_CONTENT_COMPLETION: scope._llmresponse,+ },+ )++ scope._span.set_status(Status(StatusCode.OK))++ if not disable_metrics:+ metrics_attributes = create_metrics_attributes(+ service_name=application_name,+ deployment_environment=environment,+ operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,+ system=SemanticConvention.GEN_AI_SYSTEM_HUGGING_FACE,+ request_model=request_model,+ server_address=scope._server_address,+ server_port=scope._server_port,+ response_model=request_model,+ )++ metrics["genai_client_usage_tokens"].record(input_tokens + output_tokens, metrics_attributes)+ metrics["genai_client_operation_duration"].record(scope._end_time - scope._start_time, metrics_attributes)+ metrics["genai_server_tbt"].record(scope._tbt, metrics_attributes)+ metrics["genai_server_ttft"].record(scope._ttft, metrics_attributes)+ metrics["genai_requests"].add(1, metrics_attributes)+ metrics["genai_completion_tokens"].add(output_tokens, metrics_attributes)+ metrics["genai_prompt_tokens"].add(input_tokens, metrics_attributes)+ metrics["genai_cost"].record(cost, metrics_attributes)++def process_chat_response(instance, response, request_model, pricing_info, server_port, server_address,+ environment, application_name, metrics, start_time,+ span, args, kwargs, capture_message_content=False, disable_metrics=False, version="1.0.0"):+ """+ Process chat request and generate Telemetry+ """++ self = type("GenericScope", (), {})()+ response_dict = response_as_dict(response)++ # pylint: disable = no-member+ self._instance = instance+ self._start_time = start_time+ self._end_time = time.time()+ self._span = span+ self._timestamps = []+ self._ttft, self._tbt = self._end_time - self._start_time, 0+ self._server_address, self._server_port = server_address, server_port+ self._kwargs = kwargs+ self._args = args++ if self._args and len(self._args) > 0:+ self._prompt = args[0]+ else:+ self._prompt = (+ kwargs.get("text_inputs") or+ (kwargs.get("image") and kwargs.get("question") and+ ("image: " + kwargs.get("image") + " question:" + kwargs.get("question"))) or+ kwargs.get("fallback") or+ ""+ )+ self._prompt = format_and_concatenate(self._prompt)++ self._llmresponse = []+ if self._kwargs.get("task", "text-generation") == "text-generation":+ first_entry = response_dict[0]++ if isinstance(first_entry, dict) and isinstance(first_entry.get("generated_text"), list):+ last_element = first_entry.get("generated_text")[-1]+ self._llmresponse = last_element.get("content", last_element)+ else:+ def extract_text(entry):+ if isinstance(entry, dict):+ return entry.get("generated_text")+ if isinstance(entry, list):+ return " ".join(+ extract_text(sub_entry) for sub_entry in entry if isinstance(sub_entry, dict)+ )+ return ""++ # Process and collect all generated texts+ self._llmresponse = [+ extract_text(entry) for entry in response_dict+ ]++ # Join all non-empty responses into a single string+ self._llmresponse = " ".join(filter(None, self._llmresponse))++ elif self._kwargs.get("task", "text-generation") == "automatic-speech-recognition":+ self._llmresponse = response_dict.get("text", "")++ elif self._kwargs.get("task", "text-generation") == "image-classification":+ self._llmresponse = str(response_dict[0])++ elif self._kwargs.get("task", "text-generation") == "visual-question-answering":+ self._llmresponse = str(response_dict[0]).get("answer")++ common_chat_logic(self, pricing_info, environment, application_name, metrics,+ capture_message_content, disable_metrics, version, args, kwargs, is_stream=False)++ return responsediff --git a/sdk/python/tests/requirements.txt b/sdk/python/tests/requirements.txtindex f20eb254..e64108f7 100644--- a/sdk/python/tests/requirements.txt+++ b/sdk/python/tests/requirements.txt@@ -10,12 +10,8 @@ cohereopenaianthropicmistralai-transformersboto3botocore-google-cloud-aiplatform-groq-elevenlabsgoogle-generativeaiazure-ai-inferencereka-api@@ -27,6 +23,9 @@ controlflowassemblyaifirecrawl-pytogether+transformers+groq+elevenlabs# Vector DBschromadb@@ -45,8 +44,7 @@ xmltodict# Utilitiesbs4-tensorflow-tf_keras+torchaiohttppyyamldiff --git a/sdk/python/tests/test_ai21.py b/sdk/python/tests/test_ai21.pyindex 32f76071..45e2a2e3 100644--- a/sdk/python/tests/test_ai21.py+++ b/sdk/python/tests/test_ai21.py@@ -40,7 +40,7 @@ def test_sync_ai21_chat():response = sync_client.chat.completions.create(messages=MESSAGES,- model="jamba-1.5-mini",+ model="jamba-mini",max_tokens=1,)assert isinstance(response.id, str)@@ -55,7 +55,7 @@ def test_sync_ai21_chat_stream():responses = sync_client.chat.completions.create(messages=MESSAGES,- model="jamba-1.5-mini",+ model="jamba-mini",stream=True,max_tokens=1,)@@ -93,14 +93,14 @@ async def test_async_ai21_test():response = await async_client.chat.completions.create(messages=MESSAGES,- model="jamba-1.5-mini",+ model="jamba-mini",max_tokens=1,)assert isinstance(response.id, str)responses = await async_client.chat.completions.create(messages=MESSAGES,- model="jamba-1.5-mini",+ model="jamba-mini",stream=True,max_tokens=1,)diff --git a/sdk/python/tests/test_firecrawl.py b/sdk/python/tests/test_firecrawl.pyindex 3b8813ed..218f9ca3 100644--- a/sdk/python/tests/test_firecrawl.py+++ b/sdk/python/tests/test_firecrawl.py@@ -32,7 +32,7 @@ def test_sync_scarpe_url():response = sync_client.scrape_url('https://openlit.io',- params={'formats': ['markdown', 'html'],}+ formats=['markdown', 'html'],)- assert isinstance(response, dict)+ assert response.success is Truediff --git a/sdk/python/tests/test_qdrant.py b/sdk/python/tests/test_qdrant.pyindex 44e836f1..a38e6e6b 100644--- a/sdk/python/tests/test_qdrant.py+++ b/sdk/python/tests/test_qdrant.py@@ -154,6 +154,12 @@ def test_db_qdrant():)assert isinstance(retrieve, list)+ client.create_payload_index(+ collection_name=COLLECTION_NAME,+ field_name="city",+ field_schema="keyword",+ )+# Scroll vectors from the collectionscroll = client.scroll(collection_name=COLLECTION_NAME,diff --git a/sdk/python/tests/test_transformers.py b/sdk/python/tests/test_transformers.pynew file mode 100644index 00000000..feeb9bd6--- /dev/null+++ b/sdk/python/tests/test_transformers.py@@ -0,0 +1,34 @@+# pylint: disable=duplicate-code, no-name-in-module+"""+This module contains tests for Text Generation functionality in HuggingFace Transformers library.++Tests cover the usage of the Transformers' pipeline for generating text.+These tests validate integration with OpenLIT.++Note: Ensure the environment is properly configured for Transformers and OpenLIT monitoring+prior to running these tests.+"""++from transformers import pipeline+import openlit++# Initialize environment and application name for OpenLIT monitoring+openlit.init(environment="openlit-testing", application_name="openlit-python-test")++def test_text_transformers():+ """+ Test text generation capabilities from HuggingFace Transformers library.+ """++ pipe= pipeline(task="text-generation", model="Qwen/Qwen2.5-1.5B")+ response = pipe("LLM Observability")+ assert isinstance(response[0]["generated_text"], str)++ chat = [+ {"role": "system", "content": "You are an OpenTelemetry AI Observability expert"},+ {"role": "user", "content": "What is Agent Observability?"}+ ]++ response = pipe(chat, max_new_tokens=100)++ assert isinstance(response[0]["generated_text"][-1]["content"], str)diff --git a/sdk/python/tests/test_transformers.py.hold b/sdk/python/tests/test_transformers.py.holddeleted file mode 100644index 0b2417d3..00000000--- a/sdk/python/tests/test_transformers.py.hold+++ /dev/null@@ -1,33 +0,0 @@-# pylint: disable=duplicate-code, no-name-in-module-"""-This module contains tests for Text Generation functionality in HuggingFace Transformers library.--Tests cover the usage of the Transformers' pipeline for generating text.-These tests validate integration with OpenLIT.--Note: Ensure the environment is properly configured for Transformers and OpenLIT monitoring-prior to running these tests.-"""--from transformers import pipeline-import openlit--# Initialize environment and application name for OpenLIT monitoring-openlit.init(environment="openlit-testing", application_name="openlit-python-test")--def test_text_trasnformers():- """- Test text generation capabilities using the GPT-2 model from HuggingFace Transformers library.-- This test sends a prompt to a pre-specified model and verifies that the response contains- generated text matching expected criteria.- In this case, simply the presence of the 'generated_text' field in the response object.-- Raises:- AssertionError: If the 'generated_text' field is missing from any part of the response.- """-- generator = pipeline(model="openai-community/gpt2")- response = generator("My tart needs some", num_return_sequences=1, return_full_text=False)- for output in response:- assert 'generated_text' in output