langtrace-python-sdk 3.0.1__py3-none-any.whl → 3.1.0__py3-none-any.whl
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.
- examples/litellm_example/basic.py +1 -5
- examples/litellm_example/config.yaml +10 -0
- examples/litellm_example/proxy_basic.py +16 -0
- langtrace_python_sdk/langtrace.py +58 -11
- langtrace_python_sdk/types/__init__.py +21 -15
- langtrace_python_sdk/version.py +1 -1
- {langtrace_python_sdk-3.0.1.dist-info → langtrace_python_sdk-3.1.0.dist-info}/METADATA +1 -1
- {langtrace_python_sdk-3.0.1.dist-info → langtrace_python_sdk-3.1.0.dist-info}/RECORD +11 -9
- {langtrace_python_sdk-3.0.1.dist-info → langtrace_python_sdk-3.1.0.dist-info}/WHEEL +0 -0
- {langtrace_python_sdk-3.0.1.dist-info → langtrace_python_sdk-3.1.0.dist-info}/entry_points.txt +0 -0
- {langtrace_python_sdk-3.0.1.dist-info → langtrace_python_sdk-3.1.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,3 @@
|
|
1
|
-
from langtrace_python_sdk import with_langtrace_root_span, langtrace
|
2
1
|
from dotenv import load_dotenv
|
3
2
|
from litellm import completion, acompletion
|
4
3
|
import litellm
|
@@ -8,11 +7,9 @@ load_dotenv()
|
|
8
7
|
|
9
8
|
|
10
9
|
litellm.success_callback = ["langtrace"]
|
11
|
-
langtrace.init()
|
12
10
|
litellm.set_verbose = False
|
13
11
|
|
14
12
|
|
15
|
-
@with_langtrace_root_span("Litellm Example OpenAI")
|
16
13
|
def openAI(streaming=False):
|
17
14
|
response = completion(
|
18
15
|
model="gpt-3.5-turbo",
|
@@ -56,7 +53,6 @@ def anthropic(streaming=False):
|
|
56
53
|
print("ERORRRR", e)
|
57
54
|
|
58
55
|
|
59
|
-
# @with_langtrace_root_span("Litellm Example OpenAI Async Streaming")
|
60
56
|
async def async_anthropic(streaming=False):
|
61
57
|
response = await acompletion(
|
62
58
|
model="claude-2.1",
|
@@ -93,6 +89,6 @@ def cohere(streaming=False):
|
|
93
89
|
|
94
90
|
if __name__ == "__main__":
|
95
91
|
# openAI()
|
96
|
-
anthropic(streaming=False)
|
92
|
+
# anthropic(streaming=False)
|
97
93
|
cohere(streaming=True)
|
98
94
|
# asyncio.run(async_anthropic(streaming=True))
|
@@ -0,0 +1,10 @@
|
|
1
|
+
model_list:
|
2
|
+
- model_name: "gpt-4" # all requests where model not in your config go to this deployment
|
3
|
+
litellm_params:
|
4
|
+
model: openai/gpt-4 # set `openai/` to use the openai route
|
5
|
+
|
6
|
+
litellm_settings:
|
7
|
+
success_callback: ["langtrace"]
|
8
|
+
|
9
|
+
environment_variables:
|
10
|
+
LANGTRACE_API_KEY: "fake-api-key"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import openai
|
2
|
+
from dotenv import load_dotenv
|
3
|
+
|
4
|
+
load_dotenv()
|
5
|
+
|
6
|
+
client = openai.OpenAI(base_url="http://0.0.0.0:4000")
|
7
|
+
|
8
|
+
# request sent to model set on litellm proxy, `litellm --model`
|
9
|
+
response = client.chat.completions.create(
|
10
|
+
model="gpt-4",
|
11
|
+
messages=[
|
12
|
+
{"role": "user", "content": "this is a test request, write a short poem"}
|
13
|
+
],
|
14
|
+
)
|
15
|
+
|
16
|
+
print(response)
|
@@ -31,10 +31,15 @@ from opentelemetry.sdk.trace.export import (
|
|
31
31
|
SimpleSpanProcessor,
|
32
32
|
)
|
33
33
|
|
34
|
+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
|
35
|
+
OTLPSpanExporter as GRPCExporter,
|
36
|
+
)
|
37
|
+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
|
38
|
+
OTLPSpanExporter as HTTPExporter,
|
39
|
+
)
|
34
40
|
from langtrace_python_sdk.constants.exporter.langtrace_exporter import (
|
35
41
|
LANGTRACE_REMOTE_URL,
|
36
42
|
)
|
37
|
-
from langtrace_python_sdk.extensions.langtrace_exporter import LangTraceExporter
|
38
43
|
from langtrace_python_sdk.instrumentation import (
|
39
44
|
AnthropicInstrumentation,
|
40
45
|
ChromaInstrumentation,
|
@@ -59,6 +64,8 @@ from langtrace_python_sdk.instrumentation import (
|
|
59
64
|
VertexAIInstrumentation,
|
60
65
|
WeaviateInstrumentation,
|
61
66
|
)
|
67
|
+
from opentelemetry.util.re import parse_env_headers
|
68
|
+
|
62
69
|
from langtrace_python_sdk.types import DisableInstrumentations, InstrumentationMethods
|
63
70
|
from langtrace_python_sdk.utils import (
|
64
71
|
check_if_sdk_is_outdated,
|
@@ -74,7 +81,7 @@ logging.disable(level=logging.INFO)
|
|
74
81
|
|
75
82
|
class LangtraceConfig:
|
76
83
|
def __init__(self, **kwargs):
|
77
|
-
self.api_key = kwargs.get("api_key")
|
84
|
+
self.api_key = kwargs.get("api_key") or os.environ.get("LANGTRACE_API_KEY")
|
78
85
|
self.batch = kwargs.get("batch", True)
|
79
86
|
self.write_spans_to_console = kwargs.get("write_spans_to_console", False)
|
80
87
|
self.custom_remote_exporter = kwargs.get("custom_remote_exporter")
|
@@ -83,7 +90,11 @@ class LangtraceConfig:
|
|
83
90
|
self.disable_tracing_for_functions = kwargs.get("disable_tracing_for_functions")
|
84
91
|
self.service_name = kwargs.get("service_name")
|
85
92
|
self.disable_logging = kwargs.get("disable_logging", False)
|
86
|
-
self.headers =
|
93
|
+
self.headers = (
|
94
|
+
kwargs.get("headers")
|
95
|
+
or os.environ.get("LANGTRACE_HEADERS")
|
96
|
+
or os.environ.get("OTEL_EXPORTER_OTLP_HEADERS")
|
97
|
+
)
|
87
98
|
|
88
99
|
|
89
100
|
def get_host(config: LangtraceConfig) -> str:
|
@@ -96,23 +107,50 @@ def get_host(config: LangtraceConfig) -> str:
|
|
96
107
|
)
|
97
108
|
|
98
109
|
|
110
|
+
def get_service_name(config: LangtraceConfig):
|
111
|
+
service_name = os.environ.get("OTEL_SERVICE_NAME")
|
112
|
+
if service_name:
|
113
|
+
return service_name
|
114
|
+
|
115
|
+
resource_attributes = os.environ.get("OTEL_RESOURCE_ATTRIBUTES")
|
116
|
+
if resource_attributes:
|
117
|
+
attrs = dict(attr.split("=") for attr in resource_attributes.split(","))
|
118
|
+
if "service.name" in attrs:
|
119
|
+
return attrs["service.name"]
|
120
|
+
|
121
|
+
if config.service_name:
|
122
|
+
return config.service_name
|
123
|
+
|
124
|
+
return sys.argv[0]
|
125
|
+
|
126
|
+
|
99
127
|
def setup_tracer_provider(config: LangtraceConfig, host: str) -> TracerProvider:
|
100
128
|
sampler = LangtraceSampler(disabled_methods=config.disable_tracing_for_functions)
|
101
|
-
resource = Resource.create(
|
102
|
-
attributes={
|
103
|
-
SERVICE_NAME: os.environ.get("OTEL_SERVICE_NAME")
|
104
|
-
or config.service_name
|
105
|
-
or sys.argv[0]
|
106
|
-
}
|
107
|
-
)
|
129
|
+
resource = Resource.create(attributes={SERVICE_NAME: get_service_name(config)})
|
108
130
|
return TracerProvider(resource=resource, sampler=sampler)
|
109
131
|
|
110
132
|
|
133
|
+
def get_headers(config: LangtraceConfig):
|
134
|
+
if not config.headers:
|
135
|
+
return {
|
136
|
+
"x-api-key": config.api_key,
|
137
|
+
}
|
138
|
+
|
139
|
+
if isinstance(config.headers, str):
|
140
|
+
return parse_env_headers(config.headers, liberal=True)
|
141
|
+
|
142
|
+
return config.headers
|
143
|
+
|
144
|
+
|
111
145
|
def get_exporter(config: LangtraceConfig, host: str):
|
112
146
|
if config.custom_remote_exporter:
|
113
147
|
return config.custom_remote_exporter
|
114
148
|
|
115
|
-
|
149
|
+
headers = get_headers(config)
|
150
|
+
if "http" in host.lower() or "https" in host.lower():
|
151
|
+
return HTTPExporter(endpoint=host, headers=headers)
|
152
|
+
else:
|
153
|
+
return GRPCExporter(endpoint=host, headers=headers)
|
116
154
|
|
117
155
|
|
118
156
|
def add_span_processor(provider: TracerProvider, config: LangtraceConfig, exporter):
|
@@ -200,6 +238,15 @@ def init(
|
|
200
238
|
+ Fore.RESET
|
201
239
|
)
|
202
240
|
|
241
|
+
if host == LANGTRACE_REMOTE_URL and not config.api_key:
|
242
|
+
print(Fore.RED)
|
243
|
+
print(
|
244
|
+
"Missing Langtrace API key, proceed to https://langtrace.ai to create one"
|
245
|
+
)
|
246
|
+
print("Set the API key as an environment variable LANGTRACE_API_KEY")
|
247
|
+
print(Fore.RESET)
|
248
|
+
return
|
249
|
+
|
203
250
|
provider = setup_tracer_provider(config, host)
|
204
251
|
exporter = get_exporter(config, host)
|
205
252
|
|
@@ -3,27 +3,33 @@ from enum import Enum
|
|
3
3
|
|
4
4
|
|
5
5
|
class InstrumentationType(Enum):
|
6
|
-
OPENAI = "openai"
|
7
|
-
COHERE = "cohere"
|
8
6
|
ANTHROPIC = "anthropic"
|
9
|
-
|
10
|
-
MISTRAL = "mistral"
|
11
|
-
PINECONE = "pinecone-client"
|
12
|
-
LLAMAINDEX = "llama-index"
|
7
|
+
AUTOGEN = "autogen"
|
13
8
|
CHROMADB = "chromadb"
|
14
|
-
|
9
|
+
COHERE = "cohere"
|
10
|
+
CREW_AI = "crewai"
|
11
|
+
CREWAI = "crewai"
|
12
|
+
DSPY = "dspy-ai"
|
13
|
+
EMBEDCHAIN = "embedchain"
|
14
|
+
GEMINI = "google-generativeai"
|
15
|
+
GOOGLE_CLOUD_AI_PLATFORM = "google-cloud-aiplatform"
|
16
|
+
GOOGLE_GENERATIVEAI = "google-generativeai"
|
17
|
+
GROQ = "groq"
|
15
18
|
LANGCHAIN = "langchain"
|
16
|
-
LANGCHAIN_CORE = "langchain-core"
|
17
19
|
LANGCHAIN_COMMUNITY = "langchain-community"
|
20
|
+
LANGCHAIN_CORE = "langchain-core"
|
18
21
|
LANGGRAPH = "langgraph"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
DSPY = "dspy-ai"
|
23
|
-
CREWAI = "crewai"
|
24
|
-
GEMINI = "google-generativeai"
|
25
|
-
VERTEXAI = "google-cloud-aiplatform"
|
22
|
+
LITELLM = "litellm"
|
23
|
+
LLAMAINDEX = "llama-index"
|
24
|
+
MISTRAL = "mistral"
|
26
25
|
MISTRALAI = "mistralai"
|
26
|
+
OLLAMA = "ollama"
|
27
|
+
OPENAI = "openai"
|
28
|
+
PINECONE = "pinecone-client"
|
29
|
+
QDRANT = "qdrant"
|
30
|
+
SQLALCHEMY = "sqlalchemy"
|
31
|
+
VERTEXAI = "vertexai"
|
32
|
+
WEAVIATE = "weaviate"
|
27
33
|
|
28
34
|
@staticmethod
|
29
35
|
def from_string(value: str):
|
langtrace_python_sdk/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "3.0
|
1
|
+
__version__ = "3.1.0"
|
@@ -57,7 +57,9 @@ examples/langchain_example/langgraph_example.py,sha256=7C2a4Sg0PKbbab03CVkStO3Mz
|
|
57
57
|
examples/langchain_example/langgraph_example_tools.py,sha256=rFwgQYRngeyCz9PuBxnllp5t5PIHk8d-UDKwCQTgkxw,4208
|
58
58
|
examples/langchain_example/sagemaker.py,sha256=V-rTZRyaErHCuo3kfrrZD8AELHJVi3wF7n1YrixfF1s,2330
|
59
59
|
examples/langchain_example/tool.py,sha256=8T8_IDbgA58XbsfyH5_xhA8ZKQfyfyFxF8wor-PsRjA,2556
|
60
|
-
examples/litellm_example/basic.py,sha256=
|
60
|
+
examples/litellm_example/basic.py,sha256=UDbv6-SV7H5_Ogk_IOL22ZX4hv5I_CKCyEHl3r8pf7c,2338
|
61
|
+
examples/litellm_example/config.yaml,sha256=kSAAspBhibtc4D7Abd2vYqm3uIqHR1kjE8nZrSTJqYQ,303
|
62
|
+
examples/litellm_example/proxy_basic.py,sha256=glQvcQ3rYD1QTyQfTwmzlPdzGMiIceRhAzE3_O94_1U,366
|
61
63
|
examples/llamaindex_example/__init__.py,sha256=4w8Hz5pfmMzhkHAbBim6jwxHxMicaN4xi1Of9pODO8g,252
|
62
64
|
examples/llamaindex_example/agent.py,sha256=JNK6xDX17HOFRShBK7a71HPWD05LwzPES9YVyl_azIQ,2767
|
63
65
|
examples/llamaindex_example/basic.py,sha256=aFZngkye95sjUr4wc2Uo_Je0iEexXpNcdlV0BTv_F4g,726
|
@@ -96,8 +98,8 @@ examples/vertexai_example/main.py,sha256=gndId5X5ksD-ycxnAWMdEqIDbLc3kz5Vt8vm4YP
|
|
96
98
|
examples/weaviate_example/__init__.py,sha256=8JMDBsRSEV10HfTd-YC7xb4txBjD3la56snk-Bbg2Kw,618
|
97
99
|
examples/weaviate_example/query_text.py,sha256=wPHQTc_58kPoKTZMygVjTj-2ZcdrIuaausJfMxNQnQc,127162
|
98
100
|
langtrace_python_sdk/__init__.py,sha256=VZM6i71NR7pBQK6XvJWRelknuTYUhqwqE7PlicKa5Wg,1166
|
99
|
-
langtrace_python_sdk/langtrace.py,sha256=
|
100
|
-
langtrace_python_sdk/version.py,sha256=
|
101
|
+
langtrace_python_sdk/langtrace.py,sha256=EmkE2bgojuj9o7_TOwprv5kctxumKmTDI1VialJSXDs,12171
|
102
|
+
langtrace_python_sdk/version.py,sha256=YVoF76lT0p3dIsqphNnDWuqSia3gZP1S1eQYXZ9FbSE,22
|
101
103
|
langtrace_python_sdk/constants/__init__.py,sha256=3CNYkWMdd1DrkGqzLUgNZXjdAlM6UFMlf_F-odAToyc,146
|
102
104
|
langtrace_python_sdk/constants/exporter/langtrace_exporter.py,sha256=d-3Qn5C_NTy1NkmdavZvy-6vePwTC5curN6QMy2haHc,50
|
103
105
|
langtrace_python_sdk/constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -189,7 +191,7 @@ langtrace_python_sdk/instrumentation/vertexai/patch.py,sha256=mLMmmmovYBaDXgnSSJ
|
|
189
191
|
langtrace_python_sdk/instrumentation/weaviate/__init__.py,sha256=Mc-Je6evPo-kKQzerTG7bd1XO5JOh4YGTE3wBxaUBwg,99
|
190
192
|
langtrace_python_sdk/instrumentation/weaviate/instrumentation.py,sha256=Kwq5QQTUQNRHrWrMnNe9X0TcqtXGiNpBidsuToRTqG0,2417
|
191
193
|
langtrace_python_sdk/instrumentation/weaviate/patch.py,sha256=aWLDbNGz35V6XQUv4lkMD0O689suqh6KdTa33VDtUkE,6905
|
192
|
-
langtrace_python_sdk/types/__init__.py,sha256=
|
194
|
+
langtrace_python_sdk/types/__init__.py,sha256=F3zef0ovPIr9hxmF8XK9tW3DKmq6eFrj3bZo3HCbNqA,4484
|
193
195
|
langtrace_python_sdk/utils/__init__.py,sha256=O-Ra9IDd1MnxihdQUC8HW_wYFhk7KbTCK2BIl02yacQ,2935
|
194
196
|
langtrace_python_sdk/utils/langtrace_sampler.py,sha256=BupNndHbU9IL_wGleKetz8FdcveqHMBVz1bfKTTW80w,1753
|
195
197
|
langtrace_python_sdk/utils/llm.py,sha256=mA7nEpndjKwPY3LfYV8hv-83xrDlD8MSTW8mItp5tXI,14953
|
@@ -241,8 +243,8 @@ tests/pinecone/cassettes/test_query.yaml,sha256=b5v9G3ssUy00oG63PlFUR3JErF2Js-5A
|
|
241
243
|
tests/pinecone/cassettes/test_upsert.yaml,sha256=neWmQ1v3d03V8WoLl8FoFeeCYImb8pxlJBWnFd_lITU,38607
|
242
244
|
tests/qdrant/conftest.py,sha256=9n0uHxxIjWk9fbYc4bx-uP8lSAgLBVx-cV9UjnsyCHM,381
|
243
245
|
tests/qdrant/test_qdrant.py,sha256=pzjAjVY2kmsmGfrI2Gs2xrolfuaNHz7l1fqGQCjp5_o,3353
|
244
|
-
langtrace_python_sdk-3.0.
|
245
|
-
langtrace_python_sdk-3.0.
|
246
|
-
langtrace_python_sdk-3.0.
|
247
|
-
langtrace_python_sdk-3.0.
|
248
|
-
langtrace_python_sdk-3.0.
|
246
|
+
langtrace_python_sdk-3.1.0.dist-info/METADATA,sha256=sCkeDBR9zzW4QW-Z4AmOunXl6fcuYp721bklg3bz4io,15868
|
247
|
+
langtrace_python_sdk-3.1.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
248
|
+
langtrace_python_sdk-3.1.0.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
|
249
|
+
langtrace_python_sdk-3.1.0.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
250
|
+
langtrace_python_sdk-3.1.0.dist-info/RECORD,,
|
File without changes
|
{langtrace_python_sdk-3.0.1.dist-info → langtrace_python_sdk-3.1.0.dist-info}/entry_points.txt
RENAMED
File without changes
|
{langtrace_python_sdk-3.0.1.dist-info → langtrace_python_sdk-3.1.0.dist-info}/licenses/LICENSE
RENAMED
File without changes
|