langtrace-python-sdk 2.2.1__py3-none-any.whl → 2.2.2__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.
@@ -0,0 +1,59 @@
1
+ import dspy
2
+ from dspy.datasets.gsm8k import GSM8K, gsm8k_metric
3
+ from dspy.teleprompt import BootstrapFewShot
4
+ from concurrent.futures import ThreadPoolExecutor
5
+ from opentelemetry.context import get_current, attach, detach
6
+
7
+ # flake8: noqa
8
+ from langtrace_python_sdk import langtrace, with_langtrace_root_span
9
+
10
+ langtrace.init()
11
+
12
+ turbo = dspy.OpenAI(model="gpt-3.5-turbo", max_tokens=250)
13
+ dspy.settings.configure(lm=turbo)
14
+
15
+ # Load math questions from the GSM8K dataset
16
+ gsm8k = GSM8K()
17
+ gsm8k_trainset, gsm8k_devset = gsm8k.train[:10], gsm8k.dev[:10]
18
+
19
+ class CoT(dspy.Module):
20
+ def __init__(self):
21
+ super().__init__()
22
+ self.prog = dspy.ChainOfThought("question -> answer")
23
+
24
+ def forward(self, question):
25
+ return self.prog(question=question)
26
+
27
+ @with_langtrace_root_span(name="parallel_example")
28
+ def example():
29
+ # Set up the optimizer: we want to "bootstrap" (i.e., self-generate) 4-shot examples of our CoT program.
30
+ config = dict(max_bootstrapped_demos=4, max_labeled_demos=4)
31
+
32
+ # Optimize! Use the `gsm8k_metric` here. In general, the metric is going to tell the optimizer how well it's doing.
33
+ teleprompter = BootstrapFewShot(metric=gsm8k_metric, **config)
34
+ optimized_cot = teleprompter.compile(CoT(), trainset=gsm8k_trainset)
35
+
36
+ questions = [
37
+ "What is the cosine of 0?",
38
+ "What is the tangent of 0?",
39
+ ]
40
+
41
+ current_context = get_current()
42
+
43
+ def run_with_context(context, func, *args, **kwargs):
44
+ token = attach(context)
45
+ try:
46
+ return func(*args, **kwargs)
47
+ finally:
48
+ detach(token)
49
+
50
+ with ThreadPoolExecutor(max_workers=2) as executor:
51
+ futures = [executor.submit(run_with_context, current_context, optimized_cot, question=q) for q in questions]
52
+
53
+ for future in futures:
54
+ ans = future.result()
55
+ print(ans)
56
+
57
+
58
+ if __name__ == "__main__":
59
+ example()
@@ -27,12 +27,12 @@ class DspyInstrumentation(BaseInstrumentor):
27
27
  The DspyInstrumentor class represents the DSPy instrumentation"""
28
28
 
29
29
  def instrumentation_dependencies(self) -> Collection[str]:
30
- return ["dspy >= 0.1.5"]
30
+ return ["dspy-ai >= 2.0.0"]
31
31
 
32
32
  def _instrument(self, **kwargs):
33
33
  tracer_provider = kwargs.get("tracer_provider")
34
34
  tracer = get_tracer(__name__, "", tracer_provider)
35
- version = v("dspy")
35
+ version = v("dspy-ai")
36
36
  _W(
37
37
  "dspy.teleprompt.bootstrap",
38
38
  "BootstrapFewShot.compile",
@@ -39,25 +39,25 @@ def patch_bootstrapfewshot_optimizer(operation_name, version, tracer):
39
39
  ),
40
40
  }
41
41
  span_attributes["dspy.optimizer.module.prog"] = json.dumps(prog)
42
- if "metric" in instance and instance.metric:
43
- span_attributes["dspy.optimizer.metric"] = instance.metric.__name__
42
+ if hasattr(instance, 'metric'):
43
+ span_attributes["dspy.optimizer.metric"] = getattr(instance, 'metric').__name__
44
44
  if kwargs.get("trainset") and len(kwargs.get("trainset")) > 0:
45
45
  span_attributes["dspy.optimizer.trainset"] = str(kwargs.get("trainset"))
46
46
  config = {}
47
- if "metric_threshold" in instance and instance.metric_threshold:
48
- config["metric_threshold"] = instance.metric_threshold
49
- if "teacher_settings" in instance and instance.teacher_settings:
50
- config["teacher_settings"] = instance.teacher_settings
51
- if "max_bootstrapped_demos" in instance and instance.max_bootstrapped_demos:
52
- config["max_bootstrapped_demos"] = instance.max_bootstrapped_demos
53
- if "max_labeled_demos" in instance and instance.max_labeled_demos:
54
- config["max_labeled_demos"] = instance.max_labeled_demos
55
- if "max_rounds" in instance and instance.max_rounds:
56
- config["max_rounds"] = instance.max_rounds
57
- if "max_errors" in instance and instance.max_errors:
58
- config["max_errors"] = instance.max_errors
59
- if "error_count" in instance and instance.error_count:
60
- config["error_count"] = instance.error_count
47
+ if hasattr(instance, 'metric_threshold'):
48
+ config["metric_threshold"] = getattr(instance, 'metric_threshold')
49
+ if hasattr(instance, 'teacher_settings'):
50
+ config["teacher_settings"] = getattr(instance, 'teacher_settings')
51
+ if hasattr(instance, 'max_bootstrapped_demos'):
52
+ config["max_bootstrapped_demos"] = getattr(instance, 'max_bootstrapped_demos')
53
+ if hasattr(instance, 'max_labeled_demos'):
54
+ config["max_labeled_demos"] = getattr(instance, 'max_labeled_demos')
55
+ if hasattr(instance, 'max_rounds'):
56
+ config["max_rounds"] = getattr(instance, 'max_rounds')
57
+ if hasattr(instance, 'max_steps'):
58
+ config["max_errors"] = getattr(instance, 'max_errors')
59
+ if hasattr(instance, 'error_count'):
60
+ config["error_count"] = getattr(instance, 'error_count')
61
61
  if config and len(config) > 0:
62
62
  span_attributes["dspy.optimizer.config"] = json.dumps(config)
63
63
 
@@ -147,30 +147,30 @@ def patch_evaluate(operation_name, version, tracer):
147
147
  **(extra_attributes if extra_attributes is not None else {}),
148
148
  }
149
149
 
150
- if "devset" in instance and instance.devset is not None:
151
- span_attributes["dspy.evaluate.devset"] = str(instance.devset)
152
- if "display" in instance and instance.display is not None:
153
- span_attributes["dspy.evaluate.display"] = str(instance.display)
154
- if "num_threads" in instance and instance.num_threads is not None:
155
- span_attributes["dspy.evaluate.num_threads"] = str(instance.num_threads)
156
- if "return_outputs" in instance and instance.return_outputs is not None:
150
+ if hasattr(instance, "devset"):
151
+ span_attributes["dspy.evaluate.devset"] = str(getattr(instance, "devset"))
152
+ if hasattr(instance, "trainset"):
153
+ span_attributes["dspy.evaluate.display"] = str(getattr(instance, "trainset"))
154
+ if hasattr(instance, "num_threads"):
155
+ span_attributes["dspy.evaluate.num_threads"] = str(getattr(instance, "num_threads"))
156
+ if hasattr(instance, "return_outputs"):
157
157
  span_attributes["dspy.evaluate.return_outputs"] = str(
158
- instance.return_outputs
158
+ getattr(instance, "return_outputs")
159
159
  )
160
- if "display_table" in instance and instance.display_table is not None:
161
- span_attributes["dspy.evaluate.display_table"] = str(instance.display_table)
162
- if "display_progress" in instance and instance.display_progress is not None:
160
+ if hasattr(instance, "display_table"):
161
+ span_attributes["dspy.evaluate.display_table"] = str(getattr(instance, "display_table"))
162
+ if hasattr(instance, "display_progress"):
163
163
  span_attributes["dspy.evaluate.display_progress"] = str(
164
- instance.display_progress
164
+ getattr(instance, "display_progress")
165
165
  )
166
- if "metric" in instance and instance.metric is not None:
167
- span_attributes["dspy.evaluate.metric"] = instance.metric.__name__
168
- if "error_count" in instance and instance.error_count is not None:
169
- span_attributes["dspy.evaluate.error_count"] = str(instance.error_count)
170
- if "error_lock" in instance and instance.error_lock is not None:
171
- span_attributes["dspy.evaluate.error_lock"] = str(instance.error_lock)
172
- if "max_errors" in instance and instance.max_errors is not None:
173
- span_attributes["dspy.evaluate.max_errors"] = str(instance.max_errors)
166
+ if hasattr(instance, "metric"):
167
+ span_attributes["dspy.evaluate.metric"] = getattr(instance, "metric").__name__
168
+ if hasattr(instance, "error_count"):
169
+ span_attributes["dspy.evaluate.error_count"] = str(getattr(instance, "error_count"))
170
+ if hasattr(instance, "error_lock"):
171
+ span_attributes["dspy.evaluate.error_lock"] = str(getattr(instance, "error_lock"))
172
+ if hasattr(instance, "max_errors"):
173
+ span_attributes["dspy.evaluate.max_errors"] = str(getattr(instance, "max_errors"))
174
174
  if args and len(args) > 0:
175
175
  span_attributes["dspy.evaluate.args"] = str(args)
176
176
 
@@ -1 +1 @@
1
- __version__ = "2.2.1"
1
+ __version__ = "2.2.2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: langtrace-python-sdk
3
- Version: 2.2.1
3
+ Version: 2.2.2
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>
@@ -11,6 +11,7 @@ examples/cohere_example/rerank.py,sha256=e7OU0A2FzfiQDuOmCy3Kg5LLNYGRmRIK5LqeLnT
11
11
  examples/cohere_example/tools.py,sha256=a5uvS058tcwU6PJbF9EDO6LPVmPj2LoW4Vn8Web3Iq8,1656
12
12
  examples/crewai_example/basic.py,sha256=PBu4f8yQfZO1L_22UDm_ReU9lnEcycjZcGuy5UpgDJM,1948
13
13
  examples/dspy_example/math_problems_cot.py,sha256=Z98nB6myt8WJse2dWS6Ap7CFUhC27lBNb37R1Gg80VQ,1282
14
+ examples/dspy_example/math_problems_cot_parallel.py,sha256=mrv6CrzgOZzplibAxZCYDKdtvbnj-suZKC24QR4RiBM,1891
14
15
  examples/dspy_example/program_of_thought_basic.py,sha256=oEbtJdeKENMUbex25-zyStWwurRWW6OdP0KDs-jUkko,984
15
16
  examples/dspy_example/quiz_gen.py,sha256=OyGhepeX8meKOtLdmlYUjMD2ECk-ZQuQXUZif1hFQY4,3371
16
17
  examples/dspy_example/react.py,sha256=APAnHqgy9w-qY5jnPD_WbBx6bwo9C-DhPnUuhL-t7sg,1376
@@ -56,7 +57,7 @@ examples/weaviate_example/__init__.py,sha256=8JMDBsRSEV10HfTd-YC7xb4txBjD3la56sn
56
57
  examples/weaviate_example/query_text.py,sha256=sG8O-bXQpflBAiYpgE_M2X7GcHUlZNgl_wJW8_h-W6Q,127024
57
58
  langtrace_python_sdk/__init__.py,sha256=VZM6i71NR7pBQK6XvJWRelknuTYUhqwqE7PlicKa5Wg,1166
58
59
  langtrace_python_sdk/langtrace.py,sha256=1L0IjME-pzEYht92QfwByPZr3H1MClTrqQdoN1KyKJY,7689
59
- langtrace_python_sdk/version.py,sha256=4dqvKTDgbqeyzbWj6hYiNdzxsI8j1YOKSLM8vF6a0j4,22
60
+ langtrace_python_sdk/version.py,sha256=toAYzE_ok1SiBE0AqAVdW0O8YCXCwcx0w4JATYQuJOg,22
60
61
  langtrace_python_sdk/constants/__init__.py,sha256=P8QvYwt5czUNDZsKS64vxm9Dc41ptGbuF1TFtAF6nv4,44
61
62
  langtrace_python_sdk/constants/exporter/langtrace_exporter.py,sha256=5MNjnAOg-4am78J3gVMH6FSwq5N8TOj72ugkhsw4vi0,46
62
63
  langtrace_python_sdk/constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -89,8 +90,8 @@ langtrace_python_sdk/instrumentation/crewai/__init__.py,sha256=_UBKfvQv7l0g2_wnm
89
90
  langtrace_python_sdk/instrumentation/crewai/instrumentation.py,sha256=W8PLTLzgEdrEx1DCo79wNs9xcuWK0YuxEICLavOESDw,1715
90
91
  langtrace_python_sdk/instrumentation/crewai/patch.py,sha256=Vnpip9Pbk4UFbTFHoUrHtAnDgsaihwSvZBgtUeOtLr8,6109
91
92
  langtrace_python_sdk/instrumentation/dspy/__init__.py,sha256=tM1srfi_QgyCzrde4izojMrRq2Wm7Dj5QUvVQXIJzkk,84
92
- langtrace_python_sdk/instrumentation/dspy/instrumentation.py,sha256=Y-_qcH5jCT4TbGvci6Iw0_OWUUlCmovMxnysj6NCnXI,2923
93
- langtrace_python_sdk/instrumentation/dspy/patch.py,sha256=EI1iTgKzwtCyQrzBSyPIjzhiQUVl5jfFDtodXXe5BjA,9258
93
+ langtrace_python_sdk/instrumentation/dspy/instrumentation.py,sha256=o8URiDvCbZ8LL0I-4xKHkn_Ms2sETBRpn-gOliv3xzQ,2929
94
+ langtrace_python_sdk/instrumentation/dspy/patch.py,sha256=86oTIUcM45INKnGs6Q5I-1NQ0jvgDQuwGlOg-sbCCYs,9017
94
95
  langtrace_python_sdk/instrumentation/gemini/__init__.py,sha256=ilWmKA4Li-g3DX6R10WQ4v-51VljxToEnJpOQoQB5uQ,88
95
96
  langtrace_python_sdk/instrumentation/gemini/instrumentation.py,sha256=rhGOt1YsTmTSzdFXkuTcFJFUQSgNBnqKvYURcS3yGHU,1308
96
97
  langtrace_python_sdk/instrumentation/gemini/patch.py,sha256=XyJT6Zl5NSlHOPxKvfZDtLiWV_G5aiOeZqAvlIQf0j0,6291
@@ -182,8 +183,8 @@ tests/pinecone/cassettes/test_query.yaml,sha256=b5v9G3ssUy00oG63PlFUR3JErF2Js-5A
182
183
  tests/pinecone/cassettes/test_upsert.yaml,sha256=neWmQ1v3d03V8WoLl8FoFeeCYImb8pxlJBWnFd_lITU,38607
183
184
  tests/qdrant/conftest.py,sha256=9n0uHxxIjWk9fbYc4bx-uP8lSAgLBVx-cV9UjnsyCHM,381
184
185
  tests/qdrant/test_qdrant.py,sha256=pzjAjVY2kmsmGfrI2Gs2xrolfuaNHz7l1fqGQCjp5_o,3353
185
- langtrace_python_sdk-2.2.1.dist-info/METADATA,sha256=7xKB3hhzIgl7c0XGqad1zKYBcV9-AUFFh5eIos8K_8c,14471
186
- langtrace_python_sdk-2.2.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
187
- langtrace_python_sdk-2.2.1.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
188
- langtrace_python_sdk-2.2.1.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
189
- langtrace_python_sdk-2.2.1.dist-info/RECORD,,
186
+ langtrace_python_sdk-2.2.2.dist-info/METADATA,sha256=4fYMOzc9y_HLZ-M9IxzgcEesxm8ylDZiTKlCnXsjQUw,14471
187
+ langtrace_python_sdk-2.2.2.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
188
+ langtrace_python_sdk-2.2.2.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
189
+ langtrace_python_sdk-2.2.2.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
190
+ langtrace_python_sdk-2.2.2.dist-info/RECORD,,