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.
Files changed (54) hide show
  1. examples/anthropic_example/completion.py +6 -6
  2. examples/cohere_example/chat.py +5 -4
  3. examples/cohere_example/chat_stream.py +2 -4
  4. examples/cohere_example/{embed_create.py → embed.py} +4 -3
  5. examples/cohere_example/rerank.py +31 -0
  6. examples/cohere_example/tools.py +40 -0
  7. examples/openai_example/chat_completion.py +41 -0
  8. examples/{openai → openai_example}/embeddings_create.py +3 -2
  9. examples/{openai → openai_example}/function_calling.py +3 -5
  10. examples/{openai → openai_example}/images_generate.py +1 -1
  11. examples/openai_example/tool_calling.py +67 -0
  12. examples/{openai → openai_example}/tool_calling_nonstreaming.py +2 -1
  13. langtrace_python_sdk/__init__.py +14 -1
  14. langtrace_python_sdk/constants/instrumentation/cohere.py +6 -1
  15. langtrace_python_sdk/instrumentation/anthropic/instrumentation.py +16 -4
  16. langtrace_python_sdk/instrumentation/anthropic/patch.py +26 -6
  17. langtrace_python_sdk/instrumentation/chroma/instrumentation.py +14 -2
  18. langtrace_python_sdk/instrumentation/chroma/patch.py +16 -4
  19. langtrace_python_sdk/instrumentation/cohere/instrumentation.py +24 -7
  20. langtrace_python_sdk/instrumentation/cohere/patch.py +295 -95
  21. langtrace_python_sdk/instrumentation/langchain/instrumentation.py +14 -3
  22. langtrace_python_sdk/instrumentation/langchain/patch.py +16 -4
  23. langtrace_python_sdk/instrumentation/langchain_community/instrumentation.py +15 -2
  24. langtrace_python_sdk/instrumentation/langchain_community/patch.py +20 -3
  25. langtrace_python_sdk/instrumentation/langchain_core/instrumentation.py +14 -4
  26. langtrace_python_sdk/instrumentation/langchain_core/patch.py +19 -7
  27. langtrace_python_sdk/instrumentation/llamaindex/instrumentation.py +15 -11
  28. langtrace_python_sdk/instrumentation/llamaindex/patch.py +20 -10
  29. langtrace_python_sdk/instrumentation/openai/instrumentation.py +20 -9
  30. langtrace_python_sdk/instrumentation/openai/patch.py +112 -78
  31. langtrace_python_sdk/instrumentation/pinecone/instrumentation.py +14 -3
  32. langtrace_python_sdk/instrumentation/pinecone/patch.py +17 -4
  33. langtrace_python_sdk/langtrace.py +40 -35
  34. langtrace_python_sdk/utils/llm.py +17 -4
  35. langtrace_python_sdk/utils/with_root_span.py +21 -5
  36. langtrace_python_sdk/version.py +1 -1
  37. {langtrace_python_sdk-1.3.6.dist-info → langtrace_python_sdk-2.0.0.dist-info}/METADATA +2 -2
  38. {langtrace_python_sdk-1.3.6.dist-info → langtrace_python_sdk-2.0.0.dist-info}/RECORD +53 -45
  39. tests/anthropic/cassettes/test_anthropic.yaml +85 -0
  40. tests/anthropic/cassettes/test_anthropic_streaming.yaml +456 -0
  41. tests/anthropic/cassettes/test_async_anthropic_streaming.yaml +328 -0
  42. tests/anthropic/conftest.py +38 -0
  43. tests/anthropic/test_anthropic.py +108 -72
  44. tests/conftest.py +17 -0
  45. tests/openai/conftest.py +5 -13
  46. tests/openai/test_chat_completion.py +21 -0
  47. tests/openai/test_image_generation.py +20 -8
  48. examples/openai/chat_completion.py +0 -58
  49. /examples/{openai → openai_example}/__init__.py +0 -0
  50. /examples/{openai → openai_example}/async_tool_calling_nonstreaming.py +0 -0
  51. /examples/{openai → openai_example}/async_tool_calling_streaming.py +0 -0
  52. /examples/{openai → openai_example}/tool_calling_streaming.py +0 -0
  53. {langtrace_python_sdk-1.3.6.dist-info → langtrace_python_sdk-2.0.0.dist-info}/WHEEL +0 -0
  54. {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
- assert attributes.get("llm.prompts") == json.dumps([prompt])
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 response.data[0].url == langtrace_response.get("url")
38
- assert response.data[0].revised_prompt == langtrace_response.get(
39
- "revised_prompt"
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
- assert attributes.get("llm.prompts") == json.dumps([prompt])
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 response.data[0].url == langtrace_response.get("url")
75
- assert response.data[0].revised_prompt == langtrace_response.get(
76
- "revised_prompt"
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