langtrace-python-sdk 1.3.6__py3-none-any.whl → 2.0.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/anthropic_example/completion.py +6 -6
- examples/cohere_example/chat.py +5 -4
- examples/cohere_example/chat_stream.py +2 -4
- examples/cohere_example/{embed_create.py → embed.py} +4 -3
- examples/cohere_example/rerank.py +31 -0
- examples/cohere_example/tools.py +40 -0
- examples/openai_example/chat_completion.py +41 -0
- examples/{openai → openai_example}/embeddings_create.py +3 -2
- examples/{openai → openai_example}/function_calling.py +3 -5
- examples/{openai → openai_example}/images_generate.py +1 -1
- examples/openai_example/tool_calling.py +67 -0
- examples/{openai → openai_example}/tool_calling_nonstreaming.py +2 -1
- langtrace_python_sdk/__init__.py +14 -1
- langtrace_python_sdk/constants/instrumentation/cohere.py +6 -1
- langtrace_python_sdk/instrumentation/anthropic/instrumentation.py +16 -4
- langtrace_python_sdk/instrumentation/anthropic/patch.py +26 -6
- langtrace_python_sdk/instrumentation/chroma/instrumentation.py +14 -2
- langtrace_python_sdk/instrumentation/chroma/patch.py +16 -4
- langtrace_python_sdk/instrumentation/cohere/instrumentation.py +24 -7
- langtrace_python_sdk/instrumentation/cohere/patch.py +295 -95
- langtrace_python_sdk/instrumentation/langchain/instrumentation.py +14 -3
- langtrace_python_sdk/instrumentation/langchain/patch.py +16 -4
- langtrace_python_sdk/instrumentation/langchain_community/instrumentation.py +15 -2
- langtrace_python_sdk/instrumentation/langchain_community/patch.py +20 -3
- langtrace_python_sdk/instrumentation/langchain_core/instrumentation.py +14 -4
- langtrace_python_sdk/instrumentation/langchain_core/patch.py +19 -7
- langtrace_python_sdk/instrumentation/llamaindex/instrumentation.py +15 -11
- langtrace_python_sdk/instrumentation/llamaindex/patch.py +20 -10
- langtrace_python_sdk/instrumentation/openai/instrumentation.py +20 -9
- langtrace_python_sdk/instrumentation/openai/patch.py +112 -78
- langtrace_python_sdk/instrumentation/pinecone/instrumentation.py +14 -3
- langtrace_python_sdk/instrumentation/pinecone/patch.py +17 -4
- langtrace_python_sdk/langtrace.py +40 -35
- langtrace_python_sdk/utils/llm.py +17 -4
- langtrace_python_sdk/utils/with_root_span.py +21 -5
- langtrace_python_sdk/version.py +1 -1
- {langtrace_python_sdk-1.3.6.dist-info → langtrace_python_sdk-2.0.0.dist-info}/METADATA +2 -2
- {langtrace_python_sdk-1.3.6.dist-info → langtrace_python_sdk-2.0.0.dist-info}/RECORD +53 -45
- tests/anthropic/cassettes/test_anthropic.yaml +85 -0
- tests/anthropic/cassettes/test_anthropic_streaming.yaml +456 -0
- tests/anthropic/cassettes/test_async_anthropic_streaming.yaml +328 -0
- tests/anthropic/conftest.py +38 -0
- tests/anthropic/test_anthropic.py +108 -72
- tests/conftest.py +17 -0
- tests/openai/conftest.py +5 -13
- tests/openai/test_chat_completion.py +21 -0
- tests/openai/test_image_generation.py +20 -8
- examples/openai/chat_completion.py +0 -58
- /examples/{openai → openai_example}/__init__.py +0 -0
- /examples/{openai → openai_example}/async_tool_calling_nonstreaming.py +0 -0
- /examples/{openai → openai_example}/async_tool_calling_streaming.py +0 -0
- /examples/{openai → openai_example}/tool_calling_streaming.py +0 -0
- {langtrace_python_sdk-1.3.6.dist-info → langtrace_python_sdk-2.0.0.dist-info}/WHEEL +0 -0
- {langtrace_python_sdk-1.3.6.dist-info → langtrace_python_sdk-2.0.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -30,13 +30,19 @@ def test_image_generation(openai_client, exporter):
|
|
|
30
30
|
assert attributes.get("url.full") == "https://api.openai.com/v1/"
|
|
31
31
|
assert attributes.get("llm.api") == APIS["IMAGES_GENERATION"]["ENDPOINT"]
|
|
32
32
|
assert attributes.get("llm.model") == llm_model_value
|
|
33
|
-
|
|
33
|
+
prompts = json.loads(attributes.get("llm.prompts"))
|
|
34
|
+
assert prompts[0]["content"] == prompt
|
|
34
35
|
|
|
35
36
|
langtrace_responses = json.loads(attributes.get("llm.responses"))
|
|
37
|
+
assert isinstance(langtrace_responses, list)
|
|
36
38
|
for langtrace_response in langtrace_responses:
|
|
37
|
-
assert
|
|
38
|
-
assert
|
|
39
|
-
|
|
39
|
+
assert isinstance(langtrace_response, dict)
|
|
40
|
+
assert "role" in langtrace_response
|
|
41
|
+
assert "content" in langtrace_response
|
|
42
|
+
assert response.data[0].url == langtrace_response["content"]["url"]
|
|
43
|
+
assert (
|
|
44
|
+
response.data[0].revised_prompt
|
|
45
|
+
== langtrace_response["content"]["revised_prompt"]
|
|
40
46
|
)
|
|
41
47
|
|
|
42
48
|
|
|
@@ -67,11 +73,17 @@ async def test_async_image_generation(async_openai_client, exporter):
|
|
|
67
73
|
assert attributes.get("url.full") == "https://api.openai.com/v1/"
|
|
68
74
|
assert attributes.get("llm.api") == APIS["IMAGES_GENERATION"]["ENDPOINT"]
|
|
69
75
|
assert attributes.get("llm.model") == llm_model_value
|
|
70
|
-
|
|
76
|
+
prompts = json.loads(attributes.get("llm.prompts"))
|
|
77
|
+
assert prompts[0]["content"] == prompt
|
|
71
78
|
|
|
72
79
|
langtrace_responses = json.loads(attributes.get("llm.responses"))
|
|
80
|
+
assert isinstance(langtrace_responses, list)
|
|
73
81
|
for langtrace_response in langtrace_responses:
|
|
74
|
-
assert
|
|
75
|
-
assert
|
|
76
|
-
|
|
82
|
+
assert isinstance(langtrace_response, dict)
|
|
83
|
+
assert "role" in langtrace_response
|
|
84
|
+
assert "content" in langtrace_response
|
|
85
|
+
assert response.data[0].url == langtrace_response["content"]["url"]
|
|
86
|
+
assert (
|
|
87
|
+
response.data[0].revised_prompt
|
|
88
|
+
== langtrace_response["content"]["revised_prompt"]
|
|
77
89
|
)
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
from dotenv import find_dotenv, load_dotenv
|
|
2
|
-
from openai import OpenAI
|
|
3
|
-
|
|
4
|
-
from langtrace_python_sdk import langtrace
|
|
5
|
-
from langtrace_python_sdk.utils.with_root_span import (
|
|
6
|
-
with_additional_attributes, with_langtrace_root_span)
|
|
7
|
-
|
|
8
|
-
_ = load_dotenv(find_dotenv())
|
|
9
|
-
|
|
10
|
-
langtrace.init(write_to_langtrace_cloud=False)
|
|
11
|
-
client = OpenAI()
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@with_additional_attributes({"user.id": "1234", "user.feedback.rating": 1})
|
|
15
|
-
def api1():
|
|
16
|
-
response = client.chat.completions.create(
|
|
17
|
-
model="gpt-4",
|
|
18
|
-
messages=[{"role": "user", "content": "Say this is a test three times"}],
|
|
19
|
-
stream=False,
|
|
20
|
-
)
|
|
21
|
-
return response
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@with_additional_attributes({"user.id": "5678", "user.feedback.rating": -1})
|
|
25
|
-
def api2():
|
|
26
|
-
response = client.chat.completions.create(
|
|
27
|
-
model="gpt-4",
|
|
28
|
-
messages=[{"role": "user", "content": "Say this is a test three times"}],
|
|
29
|
-
stream=True,
|
|
30
|
-
)
|
|
31
|
-
return response
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@with_langtrace_root_span()
|
|
35
|
-
def chat_completion():
|
|
36
|
-
response = api1()
|
|
37
|
-
response = api2()
|
|
38
|
-
result = []
|
|
39
|
-
for chunk in response:
|
|
40
|
-
if chunk.choices[0].delta.content is not None:
|
|
41
|
-
content = [
|
|
42
|
-
choice.delta.content if choice.delta and
|
|
43
|
-
choice.delta.content else ""
|
|
44
|
-
for choice in chunk.choices]
|
|
45
|
-
result.append(
|
|
46
|
-
content[0] if len(content) > 0 else "")
|
|
47
|
-
|
|
48
|
-
print("".join(result))
|
|
49
|
-
# return response
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
# # print(response)
|
|
53
|
-
# stream = client.chat.completions.create(
|
|
54
|
-
# model="gpt-4",
|
|
55
|
-
# messages=[{"role": "user", "content": "Say this is a test three times"}, {"role": "assistant", "content": "This is a test. This is a test. This is a test"},
|
|
56
|
-
# {"role": "user", "content": "Say this is a mock 4 times"}],
|
|
57
|
-
# stream=False,
|
|
58
|
-
# )
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{langtrace_python_sdk-1.3.6.dist-info → langtrace_python_sdk-2.0.0.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|