langtrace-python-sdk 1.3.6__tar.gz → 2.0.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 (113) hide show
  1. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/PKG-INFO +2 -2
  2. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/pyproject.toml +1 -1
  3. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/anthropic_example/completion.py +6 -6
  4. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/cohere_example/chat.py +5 -4
  5. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/cohere_example/chat_stream.py +2 -4
  6. langtrace_python_sdk-1.3.6/src/examples/cohere_example/embed_create.py → langtrace_python_sdk-2.0.0/src/examples/cohere_example/embed.py +4 -3
  7. langtrace_python_sdk-2.0.0/src/examples/cohere_example/rerank.py +31 -0
  8. langtrace_python_sdk-2.0.0/src/examples/cohere_example/tools.py +40 -0
  9. langtrace_python_sdk-2.0.0/src/examples/openai_example/chat_completion.py +41 -0
  10. {langtrace_python_sdk-1.3.6/src/examples/openai → langtrace_python_sdk-2.0.0/src/examples/openai_example}/embeddings_create.py +3 -2
  11. {langtrace_python_sdk-1.3.6/src/examples/openai → langtrace_python_sdk-2.0.0/src/examples/openai_example}/function_calling.py +3 -5
  12. {langtrace_python_sdk-1.3.6/src/examples/openai → langtrace_python_sdk-2.0.0/src/examples/openai_example}/images_generate.py +1 -1
  13. langtrace_python_sdk-2.0.0/src/examples/openai_example/tool_calling.py +67 -0
  14. {langtrace_python_sdk-1.3.6/src/examples/openai → langtrace_python_sdk-2.0.0/src/examples/openai_example}/tool_calling_nonstreaming.py +2 -1
  15. langtrace_python_sdk-2.0.0/src/langtrace_python_sdk/__init__.py +20 -0
  16. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/constants/instrumentation/cohere.py +6 -1
  17. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/anthropic/instrumentation.py +16 -4
  18. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/anthropic/patch.py +26 -6
  19. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/chroma/instrumentation.py +14 -2
  20. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/chroma/patch.py +16 -4
  21. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/cohere/instrumentation.py +24 -7
  22. langtrace_python_sdk-2.0.0/src/langtrace_python_sdk/instrumentation/cohere/patch.py +597 -0
  23. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/langchain/instrumentation.py +14 -3
  24. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/langchain/patch.py +16 -4
  25. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/langchain_community/instrumentation.py +15 -2
  26. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/langchain_community/patch.py +20 -3
  27. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/langchain_core/instrumentation.py +14 -4
  28. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/langchain_core/patch.py +19 -7
  29. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/llamaindex/instrumentation.py +15 -11
  30. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/llamaindex/patch.py +20 -10
  31. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/openai/instrumentation.py +20 -9
  32. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/openai/patch.py +112 -78
  33. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/pinecone/instrumentation.py +14 -3
  34. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/pinecone/patch.py +17 -4
  35. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/langtrace.py +40 -35
  36. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/utils/llm.py +17 -4
  37. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/utils/with_root_span.py +21 -5
  38. langtrace_python_sdk-2.0.0/src/langtrace_python_sdk/version.py +1 -0
  39. langtrace_python_sdk-2.0.0/src/run_example.py +56 -0
  40. langtrace_python_sdk-2.0.0/src/tests/anthropic/cassettes/test_anthropic.yaml +85 -0
  41. langtrace_python_sdk-2.0.0/src/tests/anthropic/cassettes/test_anthropic_streaming.yaml +456 -0
  42. langtrace_python_sdk-2.0.0/src/tests/anthropic/cassettes/test_async_anthropic_streaming.yaml +328 -0
  43. langtrace_python_sdk-2.0.0/src/tests/anthropic/conftest.py +38 -0
  44. langtrace_python_sdk-2.0.0/src/tests/anthropic/test_anthropic.py +109 -0
  45. langtrace_python_sdk-2.0.0/src/tests/conftest.py +17 -0
  46. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/openai/conftest.py +5 -13
  47. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/openai/test_chat_completion.py +21 -0
  48. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/openai/test_image_generation.py +20 -8
  49. langtrace_python_sdk-1.3.6/src/examples/openai/chat_completion.py +0 -58
  50. langtrace_python_sdk-1.3.6/src/langtrace_python_sdk/__init__.py +0 -7
  51. langtrace_python_sdk-1.3.6/src/langtrace_python_sdk/instrumentation/cohere/patch.py +0 -397
  52. langtrace_python_sdk-1.3.6/src/langtrace_python_sdk/version.py +0 -1
  53. langtrace_python_sdk-1.3.6/src/run_example.py +0 -44
  54. langtrace_python_sdk-1.3.6/src/tests/anthropic/test_anthropic.py +0 -73
  55. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/.gitignore +0 -0
  56. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/LICENSE +0 -0
  57. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/README.md +0 -0
  58. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/__init__.py +0 -0
  59. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/__init__.py +0 -0
  60. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/anthropic_example/__init__.py +0 -0
  61. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/chroma_example/__init__.py +0 -0
  62. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/chroma_example/basic.py +0 -0
  63. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/cohere_example/__init__.py +0 -0
  64. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/fastapi_example/basic_route.py +0 -0
  65. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/hiveagent_example/basic.py +0 -0
  66. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/langchain_example/__init__.py +0 -0
  67. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/langchain_example/basic.py +0 -0
  68. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/langchain_example/tool.py +0 -0
  69. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/llamaindex_example/__init__.py +0 -0
  70. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/llamaindex_example/agent.py +0 -0
  71. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/llamaindex_example/basic.py +0 -0
  72. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/llamaindex_example/data/abramov.txt +0 -0
  73. {langtrace_python_sdk-1.3.6/src/examples/openai → langtrace_python_sdk-2.0.0/src/examples/openai_example}/__init__.py +0 -0
  74. {langtrace_python_sdk-1.3.6/src/examples/openai → langtrace_python_sdk-2.0.0/src/examples/openai_example}/async_tool_calling_nonstreaming.py +0 -0
  75. {langtrace_python_sdk-1.3.6/src/examples/openai → langtrace_python_sdk-2.0.0/src/examples/openai_example}/async_tool_calling_streaming.py +0 -0
  76. {langtrace_python_sdk-1.3.6/src/examples/openai → langtrace_python_sdk-2.0.0/src/examples/openai_example}/tool_calling_streaming.py +0 -0
  77. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/perplexity_example/basic.py +0 -0
  78. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/pinecone_example/__init__.py +0 -0
  79. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/examples/pinecone_example/basic.py +0 -0
  80. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/constants/__init__.py +0 -0
  81. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/constants/exporter/langtrace_exporter.py +0 -0
  82. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/constants/instrumentation/__init__.py +0 -0
  83. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/constants/instrumentation/anthropic.py +0 -0
  84. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/constants/instrumentation/chroma.py +0 -0
  85. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/constants/instrumentation/common.py +0 -0
  86. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/constants/instrumentation/openai.py +0 -0
  87. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/constants/instrumentation/pinecone.py +0 -0
  88. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/extensions/__init__.py +0 -0
  89. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/extensions/langtrace_exporter.py +0 -0
  90. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/__init__.py +0 -0
  91. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/anthropic/__init__.py +0 -0
  92. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/chroma/__init__.py +0 -0
  93. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/cohere/__init__.py +0 -0
  94. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/langchain/__init__.py +0 -0
  95. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/langchain_community/__init__.py +0 -0
  96. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/langchain_core/__init__.py +0 -0
  97. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/llamaindex/__init__.py +0 -0
  98. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/openai/__init__.py +0 -0
  99. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/instrumentation/pinecone/__init__.py +0 -0
  100. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/langtrace_python_sdk/utils/__init__.py +0 -0
  101. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/__init__.py +0 -0
  102. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/chroma/test_chroma.py +0 -0
  103. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/langchain/test_langchain.py +0 -0
  104. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/langchain/test_langchain_community.py +0 -0
  105. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/langchain/test_langchain_core.py +0 -0
  106. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/openai/cassettes/test_async_chat_completion_streaming.yaml +0 -0
  107. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/openai/cassettes/test_async_image_generation.yaml +0 -0
  108. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/openai/cassettes/test_chat_completion.yaml +0 -0
  109. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/openai/cassettes/test_chat_completion_streaming.yaml +0 -0
  110. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/openai/cassettes/test_image_generation.yaml +0 -0
  111. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/openai/test_embeddings.py +0 -0
  112. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/pinecone/test_pinecone.py +0 -0
  113. {langtrace_python_sdk-1.3.6 → langtrace_python_sdk-2.0.0}/src/tests/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: langtrace-python-sdk
3
- Version: 1.3.6
3
+ Version: 2.0.0
4
4
  Summary: Python SDK for LangTrace
5
5
  Project-URL: Homepage, https://github.com/Scale3-Labs/langtrace-python-sdk
6
6
  Author-email: Scale3 Labs <engineering@scale3labs.com>
@@ -15,7 +15,7 @@ Requires-Dist: opentelemetry-instrumentation
15
15
  Requires-Dist: opentelemetry-sdk
16
16
  Requires-Dist: pinecone-client
17
17
  Requires-Dist: tiktoken
18
- Requires-Dist: trace-attributes==1.0.32
18
+ Requires-Dist: trace-attributes==3.0.2
19
19
  Provides-Extra: dev
20
20
  Requires-Dist: anthropic; extra == 'dev'
21
21
  Requires-Dist: chromadb; extra == 'dev'
@@ -18,7 +18,7 @@ classifiers=[
18
18
  "Operating System :: OS Independent",
19
19
  ]
20
20
  dependencies = [
21
- 'trace-attributes==1.0.32',
21
+ 'trace-attributes==3.0.2',
22
22
  'opentelemetry-api',
23
23
  'opentelemetry-sdk',
24
24
  'opentelemetry-instrumentation',
@@ -3,13 +3,13 @@
3
3
  import anthropic
4
4
  from dotenv import find_dotenv, load_dotenv
5
5
 
6
- from langtrace_python_sdk import langtrace
7
- from langtrace_python_sdk import with_langtrace_root_span
6
+ from langtrace_python_sdk import langtrace, with_langtrace_root_span
8
7
 
9
8
  _ = load_dotenv(find_dotenv())
10
9
 
11
10
  langtrace.init(write_to_langtrace_cloud=False)
12
11
 
12
+
13
13
  @with_langtrace_root_span("messages_create")
14
14
  def messages_create():
15
15
 
@@ -21,10 +21,10 @@ def messages_create():
21
21
  temperature=0.0,
22
22
  system="Respond only in Yoda-speak.",
23
23
  messages=[{"role": "user", "content": "How are you today?"}],
24
- stream=False,
24
+ stream=True,
25
25
  )
26
26
 
27
- print(message)
27
+ # print(message)
28
28
 
29
- # for response in message:
30
- # pass
29
+ for response in message:
30
+ pass
@@ -1,7 +1,8 @@
1
- from dotenv import find_dotenv, load_dotenv
2
1
  import cohere
2
+ from dotenv import find_dotenv, load_dotenv
3
3
 
4
4
  from langtrace_python_sdk import langtrace
5
+
5
6
  # from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
6
7
 
7
8
  _ = load_dotenv(find_dotenv())
@@ -18,9 +19,9 @@ def chat_comp():
18
19
  {"role": "USER", "message": "Who discovered gravity?"},
19
20
  {"role": "CHATBOT", "message": "The man who is widely credited with discovering gravity is Sir Isaac Newton"}
20
21
  ],
21
- message="What is today's news?",
22
- # preamble="answer like yoda",
22
+ message="Tell me a story in 3 sentences or less?",
23
+ preamble="answer like a pirate",
23
24
  # perform web search before answering the question. You can also use your own custom connector.
24
- # connectors=[{"id": "web-search"}]
25
+ connectors=[{"id": "web-search"}]
25
26
  )
26
27
  print(response)
@@ -1,10 +1,8 @@
1
- from dotenv import find_dotenv, load_dotenv
2
1
  import cohere
2
+ from dotenv import find_dotenv, load_dotenv
3
3
 
4
4
  from langtrace_python_sdk import langtrace
5
5
 
6
- # from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
7
-
8
6
  _ = load_dotenv(find_dotenv())
9
7
 
10
8
  langtrace.init(write_to_langtrace_cloud=False)
@@ -15,7 +13,7 @@ co = cohere.Client()
15
13
  # @with_langtrace_root_span("chat_stream")
16
14
  def chat_stream():
17
15
  result = []
18
- for event in co.chat_stream(message="Tell me a short story in 2 lines"):
16
+ for event in co.chat_stream(message="Tell me a short story in 2 lines", preamble="Respond like a pirate", max_tokens=100):
19
17
  if event.event_type == "text-generation":
20
18
  result.append(event.text)
21
19
  elif event.event_type == "stream-end":
@@ -1,5 +1,5 @@
1
- from dotenv import find_dotenv, load_dotenv
2
1
  import cohere
2
+ from dotenv import find_dotenv, load_dotenv
3
3
 
4
4
  from langtrace_python_sdk import langtrace
5
5
 
@@ -13,10 +13,11 @@ co = cohere.Client()
13
13
 
14
14
 
15
15
  # @with_langtrace_root_span("embed_create")
16
- def embed_create():
16
+ def embed():
17
17
  response = co.embed(
18
18
  texts=["hello", "goodbye"],
19
19
  model="embed-english-v3.0",
20
20
  input_type="classification",
21
21
  )
22
- # print(response)
22
+ print(response)
23
+ return response
@@ -0,0 +1,31 @@
1
+ import cohere
2
+ from dotenv import find_dotenv, load_dotenv
3
+
4
+ from langtrace_python_sdk import langtrace
5
+
6
+ # from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
7
+
8
+ _ = load_dotenv(find_dotenv())
9
+
10
+ langtrace.init(write_to_langtrace_cloud=False)
11
+
12
+ co = cohere.Client()
13
+
14
+
15
+ # @with_langtrace_root_span("embed_create")
16
+ def rerank():
17
+ docs = [
18
+ "Carson City is the capital city of the American state of Nevada.",
19
+ "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
20
+ "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
21
+ "Capital punishment (the death penalty) has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states.",
22
+ ]
23
+
24
+ response = co.rerank(
25
+ model="rerank-english-v2.0",
26
+ query="What is the capital of the United States?",
27
+ documents=docs,
28
+ top_n=3,
29
+ )
30
+ print(response)
31
+ return response
@@ -0,0 +1,40 @@
1
+ # import json
2
+
3
+ import cohere
4
+ from dotenv import find_dotenv, load_dotenv
5
+
6
+ from langtrace_python_sdk import langtrace
7
+
8
+ _ = load_dotenv(find_dotenv())
9
+
10
+ langtrace.init(write_to_langtrace_cloud=False)
11
+
12
+ co = cohere.Client()
13
+
14
+
15
+ student_custom_functions = [
16
+ {
17
+ "name": "extract_student_info",
18
+ "description": "Get the student information from the body of the input text",
19
+ "parameter_definitions": {
20
+ "name": {"type": "string", "description": "Name of the person", "required": True},
21
+ "major": {"type": "string", "description": "Major subject.", "required": True},
22
+ "school": {"type": "string", "description": "The university name.", "required": True},
23
+ "grades": {"type": "integer", "description": "GPA of the student.", "required": True},
24
+ "club": {
25
+ "type": "string",
26
+ "description": "School club for extracurricular activities. ",
27
+ "required": False,
28
+ },
29
+ },
30
+ }
31
+ ]
32
+
33
+
34
+ def tool_calling():
35
+ response = co.chat(
36
+ message="John is a grad student in computer science at Stanford University. He is an American and has a 3.8 GPA. John is known for his programming skills and is an active member of the university's Robotics Club. He hopes to pursue a career in artificial intelligence after graduating.",
37
+ tools=student_custom_functions,
38
+ )
39
+ print(response)
40
+ return response
@@ -0,0 +1,41 @@
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 api():
16
+ response = client.chat.completions.create(
17
+ model="gpt-4",
18
+ messages=[{"role": "system", "content": "Talk like a pirate"}, {"role": "user", "content": "Tell me a story in 3 sentences or less."}],
19
+ stream=True,
20
+ # stream=False,
21
+ )
22
+ return response
23
+
24
+
25
+ # @with_langtrace_root_span()
26
+ def chat_completion():
27
+ response = api()
28
+ # print(response)
29
+ # Uncomment this for streaming
30
+ result = []
31
+ for chunk in response:
32
+ if chunk.choices[0].delta.content is not None:
33
+ content = [
34
+ choice.delta.content if choice.delta and
35
+ choice.delta.content else ""
36
+ for choice in chunk.choices]
37
+ result.append(
38
+ content[0] if len(content) > 0 else "")
39
+
40
+ print("".join(result))
41
+ return response
@@ -6,7 +6,7 @@ from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
6
6
 
7
7
  _ = load_dotenv(find_dotenv())
8
8
 
9
- langtrace.init(batch=True, log_spans_to_console=True, write_to_remote_url=False)
9
+ langtrace.init(write_to_langtrace_cloud=False)
10
10
  client = OpenAI()
11
11
 
12
12
 
@@ -14,5 +14,6 @@ client = OpenAI()
14
14
  def embeddings_create():
15
15
  result = client.embeddings.create(
16
16
  model="text-embedding-ada-002",
17
- input="Once upon a time, there was a frog.",
17
+ input="Once upon a time, there was a pirate.",
18
18
  )
19
+ return result
@@ -1,10 +1,9 @@
1
- import json
1
+ # import json
2
2
 
3
3
  from dotenv import find_dotenv, load_dotenv
4
4
  from openai import OpenAI
5
5
 
6
6
  from langtrace_python_sdk import langtrace
7
- from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
8
7
 
9
8
  _ = load_dotenv(find_dotenv())
10
9
 
@@ -34,20 +33,19 @@ student_custom_functions = [
34
33
  ]
35
34
 
36
35
 
37
- # @with_langtrace_root_span()
38
36
  def function_calling():
39
37
  response = client.chat.completions.create(
40
38
  model="gpt-3.5-turbo",
41
39
  messages=[
42
40
  {
43
41
  "role": "user",
44
- "content": "David Nguyen is a sophomore majoring in computer science at Stanford University. He is Asian American and has a 3.8 GPA. David is known for his programming skills and is an active member of the university's Robotics Club. He hopes to pursue a career in artificial intelligence after graduating.",
42
+ "content": "John is a grad student in computer science at Stanford University. He is an American and has a 3.8 GPA. John is known for his programming skills and is an active member of the university's Robotics Club. He hopes to pursue a career in artificial intelligence after graduating.",
45
43
  }
46
44
  ],
47
45
  functions=student_custom_functions,
48
- function_call="auto",
49
46
  stream=True,
50
47
  )
48
+ # return response
51
49
 
52
50
  result = []
53
51
  for chunk in response:
@@ -6,7 +6,7 @@ from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
6
6
 
7
7
  _ = load_dotenv(find_dotenv())
8
8
 
9
- langtrace.init(batch=True, log_spans_to_console=True, write_to_remote_url=False)
9
+ langtrace.init(write_to_langtrace_cloud=False)
10
10
 
11
11
  client = OpenAI()
12
12
 
@@ -0,0 +1,67 @@
1
+ # import json
2
+
3
+ from dotenv import find_dotenv, load_dotenv
4
+ from openai import OpenAI
5
+
6
+ from langtrace_python_sdk import langtrace
7
+
8
+ _ = load_dotenv(find_dotenv())
9
+
10
+ langtrace.init(write_to_langtrace_cloud=False)
11
+
12
+ client = OpenAI()
13
+
14
+
15
+ student_custom_functions = [
16
+ {
17
+ "type": "function",
18
+ "function": {
19
+ "name": "extract_student_info",
20
+ "description": "Get the student information from the body of the input text",
21
+ "parameters": {
22
+ "type": "object",
23
+ "properties": {
24
+ "name": {"type": "string", "description": "Name of the person"},
25
+ "major": {"type": "string", "description": "Major subject."},
26
+ "school": {"type": "string", "description": "The university name."},
27
+ "grades": {"type": "integer", "description": "GPA of the student."},
28
+ "club": {
29
+ "type": "string",
30
+ "description": "School club for extracurricular activities. ",
31
+ },
32
+ },
33
+ },
34
+ },
35
+ }
36
+ ]
37
+
38
+
39
+ def tool_calling():
40
+ response = client.chat.completions.create(
41
+ model="gpt-3.5-turbo",
42
+ messages=[
43
+ {
44
+ "role": "user",
45
+ "content": "John is a grad student in computer science at Stanford University. He is an American and has a 3.8 GPA. John is known for his programming skills and is an active member of the university's Robotics Club. He hopes to pursue a career in artificial intelligence after graduating.",
46
+ }
47
+ ],
48
+ tools=student_custom_functions,
49
+ stream=False,
50
+ )
51
+ return response
52
+
53
+ # result = []
54
+ # for chunk in response:
55
+ # if chunk.choices[0].delta.function_call is not None:
56
+ # content = [
57
+ # choice.delta.function_call.arguments if choice.delta.function_call and
58
+ # choice.delta.function_call.arguments else ""
59
+ # for choice in chunk.choices]
60
+ # result.append(
61
+ # content[0] if len(content) > 0 else "")
62
+
63
+ # print("".join(result))
64
+
65
+ # Loading the response as a JSON object
66
+ # json_response = json.loads(response.choices[0].message.function_call.arguments)
67
+ # print(json_response)
@@ -13,6 +13,7 @@ langtrace.init(write_to_langtrace_cloud=False)
13
13
 
14
14
  client = OpenAI()
15
15
 
16
+
16
17
  # Example dummy function hard coded to return the same weather
17
18
  # In production, this could be your backend API or an external API
18
19
  def get_current_weather(location, unit="fahrenheit"):
@@ -89,4 +90,4 @@ def run_conversation():
89
90
  messages=messages,
90
91
  ) # get a new response from the model where it can see the function response
91
92
  # print(second_response)
92
- return second_response
93
+ return second_response
@@ -0,0 +1,20 @@
1
+ """
2
+ Copyright (c) 2024 Scale3 Labs
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ """
16
+
17
+ from langtrace_python_sdk import langtrace
18
+ from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
19
+
20
+ __all__ = ["langtrace", "with_langtrace_root_span"]
@@ -4,7 +4,7 @@ APIS = {
4
4
  "METHOD": "cohere.client.chat",
5
5
  "ENDPOINT": "/v1/chat",
6
6
  },
7
- "EMBED_CREATE": {
7
+ "EMBED": {
8
8
  "URL": "https://api.cohere.ai",
9
9
  "METHOD": "cohere.client.embed",
10
10
  "ENDPOINT": "/v1/embed",
@@ -14,4 +14,9 @@ APIS = {
14
14
  "METHOD": "cohere.client.chat_stream",
15
15
  "ENDPOINT": "/v1/messages",
16
16
  },
17
+ "RERANK": {
18
+ "URL": "https://api.cohere.ai",
19
+ "METHOD": "cohere.client.rerank",
20
+ "ENDPOINT": "/v1/rerank",
21
+ },
17
22
  }
@@ -1,17 +1,29 @@
1
1
  """
2
- Instrumentation for Anthropic
2
+ Copyright (c) 2024 Scale3 Labs
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
3
15
  """
4
16
 
5
17
  import importlib.metadata
18
+ import logging
6
19
  from typing import Collection
7
20
 
8
21
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
9
22
  from opentelemetry.trace import get_tracer
10
23
  from wrapt import wrap_function_wrapper
11
24
 
12
- from langtrace_python_sdk.instrumentation.anthropic.patch import messages_create
13
-
14
- import logging
25
+ from langtrace_python_sdk.instrumentation.anthropic.patch import \
26
+ messages_create
15
27
 
16
28
  logging.basicConfig(level=logging.FATAL)
17
29
 
@@ -1,5 +1,18 @@
1
1
  """
2
- This module contains the patching logic for the Anthropic library."""
2
+ Copyright (c) 2024 Scale3 Labs
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ """
3
16
 
4
17
  import json
5
18
 
@@ -58,6 +71,8 @@ def messages_create(original_method, version, tracer):
58
71
  attributes.llm_top_p = kwargs.get("top_k")
59
72
  if kwargs.get("user") is not None:
60
73
  attributes.llm_user = kwargs.get("user")
74
+ if kwargs.get("max_tokens") is not None:
75
+ attributes.llm_max_tokens = str(kwargs.get("max_tokens"))
61
76
 
62
77
  span = tracer.start_span(
63
78
  APIS["MESSAGES_CREATE"]["METHOD"], kind=SpanKind.CLIENT
@@ -70,12 +85,14 @@ def messages_create(original_method, version, tracer):
70
85
  result = wrapped(*args, **kwargs)
71
86
  if kwargs.get("stream") is False:
72
87
  if hasattr(result, "content") and result.content is not None:
88
+ span.set_attribute("llm.model", result.model if result.model else kwargs.get("model"))
73
89
  span.set_attribute(
74
90
  "llm.responses",
75
91
  json.dumps(
76
92
  [
77
93
  {
78
- "text": result.content[0].text,
94
+ "role": result.role if result.role else "assistant",
95
+ "content": result.content[0].text,
79
96
  "type": result.content[0].type,
80
97
  }
81
98
  ]
@@ -106,11 +123,11 @@ def messages_create(original_method, version, tracer):
106
123
  return result
107
124
  else:
108
125
  return handle_streaming_response(result, span)
109
- except Exception as e:
126
+ except Exception as err:
110
127
  # Record the exception in the span
111
- span.record_exception(e)
128
+ span.record_exception(err)
112
129
  # Set the span status to indicate an error
113
- span.set_status(Status(StatusCode.ERROR, str(e)))
130
+ span.set_status(Status(StatusCode.ERROR, str(err)))
114
131
  # Reraise the exception to ensure it's not swallowed
115
132
  span.end()
116
133
  raise
@@ -123,6 +140,8 @@ def messages_create(original_method, version, tracer):
123
140
  output_tokens = 0
124
141
  try:
125
142
  for chunk in result:
143
+ if hasattr(chunk, "message") and chunk.message is not None and hasattr(chunk.message, "model") and chunk.message.model is not None:
144
+ span.set_attribute("llm.model", chunk.message.model)
126
145
  content = ""
127
146
  if hasattr(chunk, "delta") and chunk.delta is not None:
128
147
  content = chunk.delta.text if hasattr(chunk.delta, "text") else ""
@@ -165,7 +184,8 @@ def messages_create(original_method, version, tracer):
165
184
  ),
166
185
  )
167
186
  span.set_attribute(
168
- "llm.responses", json.dumps([{"text": "".join(result_content)}])
187
+ "llm.responses",
188
+ json.dumps([{"role": "assistant", "content": "".join(result_content)}]),
169
189
  )
170
190
  span.set_status(StatusCode.OK)
171
191
  span.end()
@@ -1,8 +1,21 @@
1
1
  """
2
- Instrumentation for ChromaDB
2
+ Copyright (c) 2024 Scale3 Labs
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
3
15
  """
4
16
 
5
17
  import importlib.metadata
18
+ import logging
6
19
  from typing import Collection
7
20
 
8
21
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
@@ -11,7 +24,6 @@ from wrapt import wrap_function_wrapper
11
24
 
12
25
  from langtrace_python_sdk.constants.instrumentation.chroma import APIS
13
26
  from langtrace_python_sdk.instrumentation.chroma.patch import collection_patch
14
- import logging
15
27
 
16
28
  logging.basicConfig(level=logging.FATAL)
17
29
 
@@ -1,5 +1,17 @@
1
1
  """
2
- This module contains the patching logic for the Chroma client.
2
+ Copyright (c) 2024 Scale3 Labs
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
3
15
  """
4
16
 
5
17
  from langtrace.trace_attributes import DatabaseSpanAttributes
@@ -47,12 +59,12 @@ def collection_patch(method, version, tracer):
47
59
  result = wrapped(*args, **kwargs)
48
60
  span.set_status(StatusCode.OK)
49
61
  return result
50
- except Exception as e:
62
+ except Exception as err:
51
63
  # Record the exception in the span
52
- span.record_exception(e)
64
+ span.record_exception(err)
53
65
 
54
66
  # Set the span status to indicate an error
55
- span.set_status(Status(StatusCode.ERROR, str(e)))
67
+ span.set_status(Status(StatusCode.ERROR, str(err)))
56
68
 
57
69
  # Reraise the exception to ensure it's not swallowed
58
70
  raise
@@ -1,5 +1,17 @@
1
1
  """
2
- Instrumentation for Cohere
2
+ Copyright (c) 2024 Scale3 Labs
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
3
15
  """
4
16
 
5
17
  import importlib.metadata
@@ -9,11 +21,10 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
9
21
  from opentelemetry.trace import get_tracer
10
22
  from wrapt import wrap_function_wrapper
11
23
 
12
- from langtrace_python_sdk.instrumentation.cohere.patch import (
13
- chat_create,
14
- chat_stream,
15
- embed_create
16
- )
24
+ from langtrace_python_sdk.instrumentation.cohere.patch import (chat_create,
25
+ chat_stream,
26
+ embed, rerank)
27
+
17
28
 
18
29
  class CohereInstrumentation(BaseInstrumentor):
19
30
  """
@@ -43,7 +54,13 @@ class CohereInstrumentation(BaseInstrumentor):
43
54
  wrap_function_wrapper(
44
55
  "cohere.client",
45
56
  "Client.embed",
46
- embed_create("cohere.client.embed", version, tracer),
57
+ embed("cohere.client.embed", version, tracer),
58
+ )
59
+
60
+ wrap_function_wrapper(
61
+ "cohere.client",
62
+ "Client.rerank",
63
+ rerank("cohere.client.rerank", version, tracer),
47
64
  )
48
65
 
49
66
  def _instrument_module(self, module_name):