langtrace-python-sdk 3.0.2__py3-none-any.whl → 3.1.1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- 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 +59 -11
- langtrace_python_sdk/version.py +1 -1
- {langtrace_python_sdk-3.0.2.dist-info → langtrace_python_sdk-3.1.1.dist-info}/METADATA +1 -1
- {langtrace_python_sdk-3.0.2.dist-info → langtrace_python_sdk-3.1.1.dist-info}/RECORD +10 -8
- {langtrace_python_sdk-3.0.2.dist-info → langtrace_python_sdk-3.1.1.dist-info}/WHEEL +0 -0
- {langtrace_python_sdk-3.0.2.dist-info → langtrace_python_sdk-3.1.1.dist-info}/entry_points.txt +0 -0
- {langtrace_python_sdk-3.0.2.dist-info → langtrace_python_sdk-3.1.1.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,51 @@ 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
|
+
host = f"{host}/api/trace" if host == LANGTRACE_REMOTE_URL else host
|
151
|
+
if "http" in host.lower() or "https" in host.lower():
|
152
|
+
return HTTPExporter(endpoint=host, headers=headers)
|
153
|
+
else:
|
154
|
+
return GRPCExporter(endpoint=host, headers=headers)
|
116
155
|
|
117
156
|
|
118
157
|
def add_span_processor(provider: TracerProvider, config: LangtraceConfig, exporter):
|
@@ -200,6 +239,15 @@ def init(
|
|
200
239
|
+ Fore.RESET
|
201
240
|
)
|
202
241
|
|
242
|
+
if host == LANGTRACE_REMOTE_URL and not config.api_key:
|
243
|
+
print(Fore.RED)
|
244
|
+
print(
|
245
|
+
"Missing Langtrace API key, proceed to https://langtrace.ai to create one"
|
246
|
+
)
|
247
|
+
print("Set the API key as an environment variable LANGTRACE_API_KEY")
|
248
|
+
print(Fore.RESET)
|
249
|
+
return
|
250
|
+
|
203
251
|
provider = setup_tracer_provider(config, host)
|
204
252
|
exporter = get_exporter(config, host)
|
205
253
|
|
langtrace_python_sdk/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "3.
|
1
|
+
__version__ = "3.1.1"
|
@@ -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=3lq12_arp6g22qDuO8lh2wNtHZBqrHuofZJUxR1teCQ,12244
|
102
|
+
langtrace_python_sdk/version.py,sha256=14eImCCNxRh4pWMIfkKe4h5OCS1ICfRjHSj2AfgEXa0,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
|
@@ -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.
|
245
|
-
langtrace_python_sdk-3.
|
246
|
-
langtrace_python_sdk-3.
|
247
|
-
langtrace_python_sdk-3.
|
248
|
-
langtrace_python_sdk-3.
|
246
|
+
langtrace_python_sdk-3.1.1.dist-info/METADATA,sha256=edsnZ8aLtWS9wlM2unHIHZWFSntw8PkDt06X1obiH6w,15868
|
247
|
+
langtrace_python_sdk-3.1.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
248
|
+
langtrace_python_sdk-3.1.1.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
|
249
|
+
langtrace_python_sdk-3.1.1.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
250
|
+
langtrace_python_sdk-3.1.1.dist-info/RECORD,,
|
File without changes
|
{langtrace_python_sdk-3.0.2.dist-info → langtrace_python_sdk-3.1.1.dist-info}/entry_points.txt
RENAMED
File without changes
|
{langtrace_python_sdk-3.0.2.dist-info → langtrace_python_sdk-3.1.1.dist-info}/licenses/LICENSE
RENAMED
File without changes
|