openlit 1.10.0__tar.gz → 1.12.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. {openlit-1.10.0 → openlit-1.12.0}/PKG-INFO +14 -12
  2. {openlit-1.10.0 → openlit-1.12.0}/README.md +13 -11
  3. {openlit-1.10.0 → openlit-1.12.0}/pyproject.toml +1 -1
  4. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/__init__.py +3 -0
  5. openlit-1.12.0/src/openlit/instrumentation/gpt4all/__init__.py +52 -0
  6. openlit-1.12.0/src/openlit/instrumentation/gpt4all/gpt4all.py +352 -0
  7. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/groq/async_groq.py +1 -1
  8. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/groq/groq.py +1 -1
  9. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/openai/async_azure_openai.py +2 -2
  10. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/openai/async_openai.py +1 -1
  11. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/openai/azure_openai.py +2 -2
  12. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/openai/openai.py +1 -1
  13. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/transformers/transformers.py +1 -1
  14. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/semcov/__init__.py +4 -3
  15. {openlit-1.10.0 → openlit-1.12.0}/LICENSE +0 -0
  16. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/__helpers.py +0 -0
  17. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/anthropic/__init__.py +0 -0
  18. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/anthropic/anthropic.py +0 -0
  19. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/anthropic/async_anthropic.py +0 -0
  20. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/bedrock/__init__.py +0 -0
  21. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/bedrock/bedrock.py +0 -0
  22. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/chroma/__init__.py +0 -0
  23. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/chroma/chroma.py +0 -0
  24. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/cohere/__init__.py +0 -0
  25. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/cohere/cohere.py +0 -0
  26. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/embedchain/__init__.py +0 -0
  27. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/embedchain/embedchain.py +0 -0
  28. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/groq/__init__.py +0 -0
  29. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/haystack/__init__.py +0 -0
  30. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/haystack/haystack.py +0 -0
  31. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/langchain/__init__.py +0 -0
  32. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/langchain/langchain.py +0 -0
  33. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/llamaindex/__init__.py +0 -0
  34. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/llamaindex/llamaindex.py +0 -0
  35. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/milvus/__init__.py +0 -0
  36. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/milvus/milvus.py +0 -0
  37. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/mistral/__init__.py +0 -0
  38. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/mistral/async_mistral.py +0 -0
  39. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/mistral/mistral.py +0 -0
  40. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/ollama/__init__.py +0 -0
  41. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/ollama/async_ollama.py +0 -0
  42. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/ollama/ollama.py +0 -0
  43. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/openai/__init__.py +0 -0
  44. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/pinecone/__init__.py +0 -0
  45. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/pinecone/pinecone.py +0 -0
  46. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/qdrant/__init__.py +0 -0
  47. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/qdrant/qdrant.py +0 -0
  48. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/transformers/__init__.py +0 -0
  49. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/vertexai/__init__.py +0 -0
  50. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/vertexai/async_vertexai.py +0 -0
  51. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/instrumentation/vertexai/vertexai.py +0 -0
  52. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/otel/metrics.py +0 -0
  53. {openlit-1.10.0 → openlit-1.12.0}/src/openlit/otel/tracing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openlit
3
- Version: 1.10.0
3
+ Version: 1.12.0
4
4
  Summary: OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects
5
5
  Home-page: https://github.com/openlit/openlit/tree/main/openlit/python
6
6
  Keywords: OpenTelemetry,otel,otlp,llm,tracing,openai,anthropic,claude,cohere,llm monitoring,observability,monitoring,gpt,Generative AI,chatGPT
@@ -51,26 +51,28 @@ This project adheres to the [Semantic Conventions](https://github.com/open-telem
51
51
 
52
52
  ## Auto Instrumentation Capabilities
53
53
 
54
- | LLMs | Vector DBs | Frameworks |
55
- |----------------------------------------------------------|----------------------------------------------|----------------------------------------------|
56
- | [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai) | [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb) | [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain) |
57
- | [✅ Ollama](https://docs.openlit.io/latest/integrations/ollama) | [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone) | [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm) |
58
- | [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic) | [✅ Qdrant](https://docs.openlit.io/latest/integrations/qdrant) | [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index) |
59
- | [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) | [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus) | [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack) |
60
- | [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral) | |
61
- | [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai) | |
54
+ | LLMs | Vector DBs | Frameworks |
55
+ |-----------------------------------------------------------------|----------------------------------------------|----------------------------------------------|
56
+ | [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai) | [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb) | [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain) |
57
+ | [✅ Ollama](https://docs.openlit.io/latest/integrations/ollama) | [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone) | [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm) |
58
+ | [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic) | [✅ Qdrant](https://docs.openlit.io/latest/integrations/qdrant) | [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index) |
59
+ | [✅ GPT4All](https://docs.openlit.io/latest/integrations/gpt4all) | [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus) | [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack) |
60
+ | [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) | | [✅ EmbedChain](https://docs.openlit.io/latest/integrations/embedchain) |
61
+ | [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral) | |
62
+ | [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai) | |
62
63
  | [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface) | |
63
- | [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | |
64
+ | [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | |
64
65
  | [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai) | |
65
- | [✅ Groq](https://docs.openlit.io/latest/integrations/groq) | |
66
+ | [✅ Groq](https://docs.openlit.io/latest/integrations/groq) |
66
67
 
67
68
  ## Supported Destinations
68
69
  - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
69
70
  - [✅ Prometheus + Tempo](https://docs.openlit.io/latest/connections/prometheus-tempo)
70
71
  - [✅ Prometheus + Jaeger](https://docs.openlit.io/latest/connections/prometheus-jaeger)
71
72
  - [✅ Grafana Cloud](https://docs.openlit.io/latest/connections/grafanacloud)
72
- - [✅ DataDog](https://docs.openlit.io/latest/connections/datadog)
73
73
  - [✅ New Relic](https://docs.openlit.io/latest/connections/new-relic)
74
+ - [✅ Elastic](https://docs.openlit.io/latest/connections/elastic)
75
+ - [✅ DataDog](https://docs.openlit.io/latest/connections/datadog)
74
76
  - [✅ SigNoz](https://docs.openlit.io/latest/connections/signoz)
75
77
  - [✅ Dynatrace](https://docs.openlit.io/latest/connections/dynatrace)
76
78
  - [✅ OpenObserve](https://docs.openlit.io/latest/connections/openobserve)
@@ -26,26 +26,28 @@ This project adheres to the [Semantic Conventions](https://github.com/open-telem
26
26
 
27
27
  ## Auto Instrumentation Capabilities
28
28
 
29
- | LLMs | Vector DBs | Frameworks |
30
- |----------------------------------------------------------|----------------------------------------------|----------------------------------------------|
31
- | [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai) | [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb) | [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain) |
32
- | [✅ Ollama](https://docs.openlit.io/latest/integrations/ollama) | [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone) | [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm) |
33
- | [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic) | [✅ Qdrant](https://docs.openlit.io/latest/integrations/qdrant) | [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index) |
34
- | [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) | [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus) | [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack) |
35
- | [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral) | |
36
- | [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai) | |
29
+ | LLMs | Vector DBs | Frameworks |
30
+ |-----------------------------------------------------------------|----------------------------------------------|----------------------------------------------|
31
+ | [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai) | [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb) | [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain) |
32
+ | [✅ Ollama](https://docs.openlit.io/latest/integrations/ollama) | [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone) | [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm) |
33
+ | [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic) | [✅ Qdrant](https://docs.openlit.io/latest/integrations/qdrant) | [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index) |
34
+ | [✅ GPT4All](https://docs.openlit.io/latest/integrations/gpt4all) | [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus) | [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack) |
35
+ | [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) | | [✅ EmbedChain](https://docs.openlit.io/latest/integrations/embedchain) |
36
+ | [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral) | |
37
+ | [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai) | |
37
38
  | [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface) | |
38
- | [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | |
39
+ | [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | |
39
40
  | [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai) | |
40
- | [✅ Groq](https://docs.openlit.io/latest/integrations/groq) | |
41
+ | [✅ Groq](https://docs.openlit.io/latest/integrations/groq) |
41
42
 
42
43
  ## Supported Destinations
43
44
  - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
44
45
  - [✅ Prometheus + Tempo](https://docs.openlit.io/latest/connections/prometheus-tempo)
45
46
  - [✅ Prometheus + Jaeger](https://docs.openlit.io/latest/connections/prometheus-jaeger)
46
47
  - [✅ Grafana Cloud](https://docs.openlit.io/latest/connections/grafanacloud)
47
- - [✅ DataDog](https://docs.openlit.io/latest/connections/datadog)
48
48
  - [✅ New Relic](https://docs.openlit.io/latest/connections/new-relic)
49
+ - [✅ Elastic](https://docs.openlit.io/latest/connections/elastic)
50
+ - [✅ DataDog](https://docs.openlit.io/latest/connections/datadog)
49
51
  - [✅ SigNoz](https://docs.openlit.io/latest/connections/signoz)
50
52
  - [✅ Dynatrace](https://docs.openlit.io/latest/connections/dynatrace)
51
53
  - [✅ OpenObserve](https://docs.openlit.io/latest/connections/openobserve)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "openlit"
3
- version = "1.10.0"
3
+ version = "1.12.0"
4
4
  description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects"
5
5
  authors = ["OpenLIT"]
6
6
  repository = "https://github.com/openlit/openlit/tree/main/openlit/python"
@@ -21,6 +21,7 @@ from openlit.instrumentation.bedrock import BedrockInstrumentor
21
21
  from openlit.instrumentation.vertexai import VertexAIInstrumentor
22
22
  from openlit.instrumentation.groq import GroqInstrumentor
23
23
  from openlit.instrumentation.ollama import OllamaInstrumentor
24
+ from openlit.instrumentation.gpt4all import GPT4AllInstrumentor
24
25
  from openlit.instrumentation.langchain import LangChainInstrumentor
25
26
  from openlit.instrumentation.llamaindex import LlamaIndexInstrumentor
26
27
  from openlit.instrumentation.haystack import HaystackInstrumentor
@@ -161,6 +162,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
161
162
  "vertexai": "vertexai",
162
163
  "groq": "groq",
163
164
  "ollama": "ollama",
165
+ "gpt4all": "gpt4all",
164
166
  "langchain": "langchain",
165
167
  "llama_index": "llama_index",
166
168
  "haystack": "haystack",
@@ -216,6 +218,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
216
218
  "vertexai": VertexAIInstrumentor(),
217
219
  "groq": GroqInstrumentor(),
218
220
  "ollama": OllamaInstrumentor(),
221
+ "gpt4all": GPT4AllInstrumentor(),
219
222
  "langchain": LangChainInstrumentor(),
220
223
  "llama_index": LlamaIndexInstrumentor(),
221
224
  "haystack": HaystackInstrumentor(),
@@ -0,0 +1,52 @@
1
+ # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
+ """Initializer of Auto Instrumentation of GPT4All Functions"""
3
+
4
+ from typing import Collection
5
+ import importlib.metadata
6
+ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
7
+ from wrapt import wrap_function_wrapper
8
+
9
+ from openlit.instrumentation.gpt4all.gpt4all import (
10
+ embed, generate
11
+ )
12
+
13
+ _instruments = ("gpt4all >= 2.6.0",)
14
+
15
+ class GPT4AllInstrumentor(BaseInstrumentor):
16
+ """
17
+ An instrumentor for GPT4All's client library.
18
+ """
19
+
20
+ def instrumentation_dependencies(self) -> Collection[str]:
21
+ return _instruments
22
+
23
+ def _instrument(self, **kwargs):
24
+ application_name = kwargs.get("application_name", "default_application")
25
+ environment = kwargs.get("environment", "default_environment")
26
+ tracer = kwargs.get("tracer")
27
+ metrics = kwargs.get("metrics_dict")
28
+ pricing_info = kwargs.get("pricing_info", {})
29
+ trace_content = kwargs.get("trace_content", False)
30
+ disable_metrics = kwargs.get("disable_metrics")
31
+ version = importlib.metadata.version("gpt4all")
32
+
33
+ # generate
34
+ wrap_function_wrapper(
35
+ "gpt4all",
36
+ "GPT4All.generate",
37
+ generate("gpt4all.generate", version, environment, application_name,
38
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
39
+ )
40
+
41
+ # embed
42
+ wrap_function_wrapper(
43
+ "gpt4all",
44
+ "Embed4All.embed",
45
+ embed("gpt4all.embed", version, environment, application_name,
46
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
47
+ )
48
+
49
+
50
+ def _uninstrument(self, **kwargs):
51
+ # Proper uninstrumentation logic to revert patched methods
52
+ pass
@@ -0,0 +1,352 @@
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
2
+ """
3
+ Module for monitoring GPT4All API calls.
4
+ """
5
+
6
+ import logging
7
+ from opentelemetry.trace import SpanKind, Status, StatusCode
8
+ from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
9
+ from openlit.__helpers import handle_exception, general_tokens
10
+ from openlit.semcov import SemanticConvetion
11
+
12
+ # Initialize logger for logging potential issues and operations
13
+ logger = logging.getLogger(__name__)
14
+
15
+ def generate(gen_ai_endpoint, version, environment, application_name,
16
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
17
+ """
18
+ Generates a telemetry wrapper for generate to collect metrics.
19
+
20
+ Args:
21
+ gen_ai_endpoint: Endpoint identifier for logging and tracing.
22
+ version: Version of the monitoring package.
23
+ environment: Deployment environment (e.g., production, staging).
24
+ application_name: Name of the application using the GPT4All API.
25
+ tracer: OpenTelemetry tracer for creating spans.
26
+ pricing_info: Information used for calculating the cost of GPT4All usage.
27
+ trace_content: Flag indicating whether to trace the actual content.
28
+
29
+ Returns:
30
+ A function that wraps the generate method to add telemetry.
31
+ """
32
+
33
+ def wrapper(wrapped, instance, args, kwargs):
34
+ """
35
+ Wraps the 'generate' API call to add telemetry.
36
+
37
+ This collects metrics such as execution time, cost, and token usage, and handles errors
38
+ gracefully, adding details to the trace for observability.
39
+
40
+ Args:
41
+ wrapped: The original 'generate' method to be wrapped.
42
+ instance: The instance of the class where the original method is defined.
43
+ args: Positional arguments for the 'generate' method.
44
+ kwargs: Keyword arguments for the 'generate' method.
45
+
46
+ Returns:
47
+ The response from the original 'generate' method.
48
+ """
49
+
50
+ # Check if streaming is enabled for the API call
51
+ streaming = kwargs.get("streaming", False)
52
+
53
+ # pylint: disable=no-else-return
54
+ if streaming:
55
+ # Special handling for streaming response to accommodate the nature of data flow
56
+ def stream_generator():
57
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
58
+ # Placeholder for aggregating streaming response
59
+ llmresponse = ""
60
+
61
+ # Loop through streaming events capturing relevant details
62
+ for chunk in wrapped(*args, **kwargs):
63
+ # Collect aggregated response from events
64
+ llmresponse += chunk
65
+
66
+ yield chunk
67
+
68
+ # Handling exception ensure observability without disrupting operation
69
+ try:
70
+ # Calculate cost of the operation
71
+ cost = 0
72
+
73
+ # pylint: disable=line-too-long
74
+ model = str(instance.model.model_path).rsplit('/', maxsplit=1)[-1] or "orca-mini-3b-gguf2-q4_0.gguf"
75
+ prompt = kwargs.get("prompt") or args[0] or ""
76
+
77
+ # Calculate cost of the operation
78
+ cost = 0
79
+ prompt_tokens = general_tokens(prompt)
80
+ completion_tokens = general_tokens(llmresponse)
81
+ total_tokens = prompt_tokens + completion_tokens
82
+
83
+ # Set base span attribues
84
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
85
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
86
+ SemanticConvetion.GEN_AI_SYSTEM_GPT4ALL)
87
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
88
+ SemanticConvetion.GEN_AI_TYPE_CHAT)
89
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
90
+ gen_ai_endpoint)
91
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
92
+ environment)
93
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
94
+ application_name)
95
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
96
+ model)
97
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
98
+ kwargs.get("top_k", 40))
99
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
100
+ kwargs.get("top_p", 0.4))
101
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
102
+ kwargs.get("max_tokens", 200))
103
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
104
+ kwargs.get("temperature", 0.7))
105
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
106
+ kwargs.get("frequency_penalty", 1.18))
107
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
108
+ True)
109
+ if trace_content:
110
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
111
+ prompt)
112
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
113
+ llmresponse)
114
+
115
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
116
+ prompt_tokens)
117
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
118
+ completion_tokens)
119
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
120
+ total_tokens)
121
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
122
+ cost)
123
+
124
+ span.set_status(Status(StatusCode.OK))
125
+
126
+ if disable_metrics is False:
127
+ attributes = {
128
+ TELEMETRY_SDK_NAME:
129
+ "openlit",
130
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
131
+ application_name,
132
+ SemanticConvetion.GEN_AI_SYSTEM:
133
+ SemanticConvetion.GEN_AI_SYSTEM_GPT4ALL,
134
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
135
+ environment,
136
+ SemanticConvetion.GEN_AI_TYPE:
137
+ SemanticConvetion.GEN_AI_TYPE_CHAT,
138
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
139
+ model
140
+ }
141
+
142
+ metrics["genai_requests"].add(1, attributes)
143
+ metrics["genai_total_tokens"].add(total_tokens, attributes)
144
+ metrics["genai_completion_tokens"].add(completion_tokens, attributes)
145
+ metrics["genai_prompt_tokens"].add(prompt_tokens, attributes)
146
+ metrics["genai_cost"].record(cost, attributes)
147
+
148
+ except Exception as e:
149
+ handle_exception(span, e)
150
+ logger.error("Error in trace creation: %s", e)
151
+
152
+ return stream_generator()
153
+
154
+ # Handling for non-streaming responses
155
+ else:
156
+ # pylint: disable=line-too-long
157
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
158
+ response = wrapped(*args, **kwargs)
159
+
160
+ # pylint: disable=line-too-long
161
+ model = str(instance.model.model_path).rsplit('/', maxsplit=1)[-1] or "orca-mini-3b-gguf2-q4_0.gguf"
162
+ prompt = kwargs.get("prompt") or args[0] or ""
163
+
164
+ # Calculate cost of the operation
165
+ cost = 0
166
+ prompt_tokens = general_tokens(prompt)
167
+ completion_tokens = general_tokens(response)
168
+ total_tokens = prompt_tokens + completion_tokens
169
+
170
+ try:
171
+ # Set base span attribues
172
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
173
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
174
+ SemanticConvetion.GEN_AI_SYSTEM_GPT4ALL)
175
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
176
+ SemanticConvetion.GEN_AI_TYPE_CHAT)
177
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
178
+ gen_ai_endpoint)
179
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
180
+ environment)
181
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
182
+ application_name)
183
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
184
+ model)
185
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
186
+ kwargs.get("top_k", 40))
187
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
188
+ kwargs.get("top_p", 0.4))
189
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
190
+ kwargs.get("max_tokens", 200))
191
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
192
+ kwargs.get("temperature", 0.7))
193
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
194
+ kwargs.get("frequency_penalty", 1.18))
195
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
196
+ False)
197
+ if trace_content:
198
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
199
+ prompt)
200
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
201
+ response)
202
+
203
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
204
+ prompt_tokens)
205
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
206
+ completion_tokens)
207
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
208
+ total_tokens)
209
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
210
+ cost)
211
+
212
+ span.set_status(Status(StatusCode.OK))
213
+
214
+ if disable_metrics is False:
215
+ attributes = {
216
+ TELEMETRY_SDK_NAME:
217
+ "openlit",
218
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
219
+ application_name,
220
+ SemanticConvetion.GEN_AI_SYSTEM:
221
+ SemanticConvetion.GEN_AI_SYSTEM_GPT4ALL,
222
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
223
+ environment,
224
+ SemanticConvetion.GEN_AI_TYPE:
225
+ SemanticConvetion.GEN_AI_TYPE_CHAT,
226
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
227
+ model
228
+ }
229
+
230
+ metrics["genai_requests"].add(1, attributes)
231
+ metrics["genai_total_tokens"].add(total_tokens, attributes)
232
+ metrics["genai_completion_tokens"].add(completion_tokens, attributes)
233
+ metrics["genai_prompt_tokens"].add(prompt_tokens, attributes)
234
+ metrics["genai_cost"].record(cost, attributes)
235
+
236
+ # Return original response
237
+ return response
238
+
239
+ except Exception as e:
240
+ handle_exception(span, e)
241
+ logger.error("Error in trace creation: %s", e)
242
+
243
+ # Return original response
244
+ return response
245
+
246
+ return wrapper
247
+
248
+ def embed(gen_ai_endpoint, version, environment, application_name,
249
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
250
+ """
251
+ Generates a telemetry wrapper for embeddings to collect metrics.
252
+
253
+ Args:
254
+ gen_ai_endpoint: Endpoint identifier for logging and tracing.
255
+ version: Version of the monitoring package.
256
+ environment: Deployment environment (e.g., production, staging).
257
+ application_name: Name of the application using the GPT4All API.
258
+ tracer: OpenTelemetry tracer for creating spans.
259
+ pricing_info: Information used for calculating the cost of GPT4All usage.
260
+ trace_content: Flag indicating whether to trace the actual content.
261
+
262
+ Returns:
263
+ A function that wraps the embeddings method to add telemetry.
264
+ """
265
+
266
+ def wrapper(wrapped, instance, args, kwargs):
267
+ """
268
+ Wraps the 'embeddings' API call to add telemetry.
269
+
270
+ This collects metrics such as execution time, cost, and token usage, and handles errors
271
+ gracefully, adding details to the trace for observability.
272
+
273
+ Args:
274
+ wrapped: The original 'embeddings' method to be wrapped.
275
+ instance: The instance of the class where the original method is defined.
276
+ args: Positional arguments for the 'embeddings' method.
277
+ kwargs: Keyword arguments for the 'embeddings' method.
278
+
279
+ Returns:
280
+ The response from the original 'embeddings' method.
281
+ """
282
+
283
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
284
+ response = wrapped(*args, **kwargs)
285
+
286
+ try:
287
+ # pylint: disable=line-too-long
288
+ model = str(instance.gpt4all.model.model_path).rsplit('/', maxsplit=1)[-1] or "all-MiniLM-L6-v2.gguf2.f16.gguf"
289
+ prompt = kwargs.get("prompt") or args[0] or ""
290
+
291
+ # Calculate cost of the operation
292
+ cost = 0
293
+ prompt_tokens = general_tokens(prompt)
294
+
295
+ # Set Span attributes
296
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
297
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
298
+ SemanticConvetion.GEN_AI_SYSTEM_GPT4ALL)
299
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
300
+ SemanticConvetion.GEN_AI_TYPE_EMBEDDING)
301
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
302
+ gen_ai_endpoint)
303
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
304
+ environment)
305
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
306
+ application_name)
307
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
308
+ model)
309
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
310
+ prompt_tokens)
311
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
312
+ prompt_tokens)
313
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
314
+ cost)
315
+ if trace_content:
316
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
317
+ prompt)
318
+
319
+ span.set_status(Status(StatusCode.OK))
320
+
321
+ if disable_metrics is False:
322
+ attributes = {
323
+ TELEMETRY_SDK_NAME:
324
+ "openlit",
325
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
326
+ application_name,
327
+ SemanticConvetion.GEN_AI_SYSTEM:
328
+ SemanticConvetion.GEN_AI_SYSTEM_GPT4ALL,
329
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
330
+ environment,
331
+ SemanticConvetion.GEN_AI_TYPE:
332
+ SemanticConvetion.GEN_AI_TYPE_EMBEDDING,
333
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
334
+ model
335
+ }
336
+
337
+ metrics["genai_requests"].add(1, attributes)
338
+ metrics["genai_total_tokens"].add(prompt_tokens, attributes)
339
+ metrics["genai_prompt_tokens"].add(prompt_tokens, attributes)
340
+ metrics["genai_cost"].record(cost, attributes)
341
+
342
+ # Return original response
343
+ return response
344
+
345
+ except Exception as e:
346
+ handle_exception(span, e)
347
+ logger.error("Error in trace creation: %s", e)
348
+
349
+ # Return original response
350
+ return response
351
+
352
+ return wrapper
@@ -268,7 +268,7 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
268
268
  else:
269
269
  i = 0
270
270
  while i < kwargs["n"] and trace_content is True:
271
- attribute_name = f"gen_ai.content.completion.{i}"
271
+ attribute_name = f"gen_ai.completion.{i}"
272
272
  span.set_attribute(attribute_name,
273
273
  response.choices[i].message.content)
274
274
  i += 1
@@ -268,7 +268,7 @@ def chat(gen_ai_endpoint, version, environment, application_name,
268
268
  else:
269
269
  i = 0
270
270
  while i < kwargs["n"] and trace_content is True:
271
- attribute_name = f"gen_ai.content.completion.{i}"
271
+ attribute_name = f"gen_ai.completion.{i}"
272
272
  span.set_attribute(attribute_name,
273
273
  response.choices[i].message.content)
274
274
  i += 1
@@ -269,7 +269,7 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicat
269
269
  else:
270
270
  i = 0
271
271
  while i < kwargs["n"] and trace_content is True:
272
- attribute_name = f"gen_ai.content.completion.{i}"
272
+ attribute_name = f"gen_ai.completion.{i}"
273
273
  span.set_attribute(attribute_name,
274
274
  response.choices[i].message.content)
275
275
  i += 1
@@ -550,7 +550,7 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_n
550
550
  else:
551
551
  i = 0
552
552
  while i < kwargs["n"] and trace_content is True:
553
- attribute_name = f"gen_ai.content.completion.{i}"
553
+ attribute_name = f"gen_ai.completion.{i}"
554
554
  span.set_attribute(attribute_name,
555
555
  response.choices[i].text)
556
556
  i += 1
@@ -273,7 +273,7 @@ def async_chat_completions(gen_ai_endpoint, version, environment, application_na
273
273
  else:
274
274
  i = 0
275
275
  while i < kwargs["n"] and trace_content is True:
276
- attribute_name = f"gen_ai.content.completion.{i}"
276
+ attribute_name = f"gen_ai.completion.{i}"
277
277
  span.set_attribute(attribute_name,
278
278
  response.choices[i].message.content)
279
279
  i += 1
@@ -269,7 +269,7 @@ def azure_chat_completions(gen_ai_endpoint, version, environment, application_na
269
269
  else:
270
270
  i = 0
271
271
  while i < kwargs["n"] and trace_content is True:
272
- attribute_name = f"gen_ai.content.completion.{i}"
272
+ attribute_name = f"gen_ai.completion.{i}"
273
273
  span.set_attribute(attribute_name,
274
274
  response.choices[i].message.content)
275
275
  i += 1
@@ -548,7 +548,7 @@ def azure_completions(gen_ai_endpoint, version, environment, application_name,
548
548
  else:
549
549
  i = 0
550
550
  while i < kwargs["n"] and trace_content is True:
551
- attribute_name = f"gen_ai.content.completion.{i}"
551
+ attribute_name = f"gen_ai.completion.{i}"
552
552
  span.set_attribute(attribute_name,
553
553
  response.choices[i].text)
554
554
  i += 1
@@ -272,7 +272,7 @@ def chat_completions(gen_ai_endpoint, version, environment, application_name,
272
272
  else:
273
273
  i = 0
274
274
  while i < kwargs["n"] and trace_content is True:
275
- attribute_name = f"gen_ai.content.completion.{i}"
275
+ attribute_name = f"gen_ai.completion.{i}"
276
276
  span.set_attribute(attribute_name,
277
277
  response.choices[i].message.content)
278
278
  i += 1
@@ -98,7 +98,7 @@ def text_wrap(gen_ai_endpoint, version, environment, application_name,
98
98
  completion_tokens = 0
99
99
  for completion in response:
100
100
  if len(response) > 1:
101
- attribute_name = f"gen_ai.content.completion.{i}"
101
+ attribute_name = f"gen_ai.completion.{i}"
102
102
  else:
103
103
  attribute_name = SemanticConvetion.GEN_AI_CONTENT_COMPLETION
104
104
  if i == 0:
@@ -21,7 +21,7 @@ class SemanticConvetion:
21
21
  GEN_AI_SYSTEM = "gen_ai.system"
22
22
  GEN_AI_ENVIRONMENT = "gen_ai.environment"
23
23
  GEN_AI_APPLICATION_NAME = "gen_ai.application_name"
24
- GEN_AI_TYPE = "gen_ai.type"
24
+ GEN_AI_TYPE = "gen_ai.operation.name"
25
25
  GEN_AI_HUB_OWNER = "gen_ai.hub.owner"
26
26
  GEN_AI_HUB_REPO = "gen_ai.hub.repo"
27
27
  GEN_AI_RETRIEVAL_SOURCE = "gen_ai.retrieval.source"
@@ -68,8 +68,8 @@ class SemanticConvetion:
68
68
  GEN_AI_RESPONSE_IMAGE_STYLE = "gen_ai.request.image_style"
69
69
 
70
70
  # GenAI Content
71
- GEN_AI_CONTENT_PROMPT = "gen_ai.content.prompt"
72
- GEN_AI_CONTENT_COMPLETION = "gen_ai.content.completion"
71
+ GEN_AI_CONTENT_PROMPT = "gen_ai.prompt"
72
+ GEN_AI_CONTENT_COMPLETION = "gen_ai.completion"
73
73
  GEN_AI_CONTENT_REVISED_PROMPT = "gen_ai.content.revised_prompt"
74
74
 
75
75
  # GenAI Evaluation Metrics
@@ -95,6 +95,7 @@ class SemanticConvetion:
95
95
  GEN_AI_SYSTEM_VERTEXAI = "vertexai"
96
96
  GEN_AI_SYSTEM_GROQ = "groq"
97
97
  GEN_AI_SYSTEM_OLLAMA = "ollama"
98
+ GEN_AI_SYSTEM_GPT4ALL = "gpt4all"
98
99
  GEN_AI_SYSTEM_LANGCHAIN = "langchain"
99
100
  GEN_AI_SYSTEM_LLAMAINDEX = "llama_index"
100
101
  GEN_AI_SYSTEM_HAYSTACK = "haystack"
File without changes