Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

[Fix]: 'SystemMessage' object is not subscriptable in LangChain (#661)

Patcher28a7f6a44364
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml
index 5d40742d..a4ff4b30 100644
--- a/sdk/python/pyproject.toml
+++ b/sdk/python/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openlit"
-version = "1.33.16"
+version = "1.33.17"
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/instrumentation/langchain/langchain.py b/sdk/python/src/openlit/instrumentation/langchain/langchain.py
index bdece4bb..65fc94d3 100644
--- a/sdk/python/src/openlit/instrumentation/langchain/langchain.py
+++ b/sdk/python/src/openlit/instrumentation/langchain/langchain.py
@@ -14,6 +14,7 @@ from openlit.__helpers import (
calculate_ttft,
calculate_tbt,
create_metrics_attributes,
+ extract_and_format_input,
)
from openlit.semcov import SemanticConvetion
@@ -249,34 +250,7 @@ def chat(gen_ai_endpoint, version, environment, application_name,
end_time = time.time()
try:
- # Format 'messages' into a single string
- message_prompt = kwargs.get("messages", "") or args[0]
- formatted_messages = []
-
- for message in message_prompt:
- # Handle the case where message is a tuple
- if isinstance(message, tuple) and len(message) == 2:
- role, content = message
- # Handle the case where message is a dictionary
- elif isinstance(message, dict):
- role = message["role"]
- content = message["content"]
- else:
- continue
-
- # Check if the content is a list
- if isinstance(content, list):
- content_str = ", ".join(
- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'
- if "type" in item else f'text: {item["text"]}'
- for item in content
- )
- formatted_messages.append(f"{role}: {content_str}")
- else:
- formatted_messages.append(f"{role}: {content}")
-
- # Join all formatted messages with newline
- prompt = "\n".join(formatted_messages)
+ prompt = str(kwargs.get('messages', '') or args[0])
input_tokens = general_tokens(str(prompt))
output_tokens = general_tokens(str(response))