promptlayer 1.0.12__tar.gz → 1.0.13__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.

Potentially problematic release.


This version of promptlayer might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: promptlayer
3
- Version: 1.0.12
3
+ Version: 1.0.13
4
4
  Summary: PromptLayer is a platform for prompt engineering and tracks your LLM requests.
5
5
  License: Apache-2.0
6
6
  Author: Magniv
@@ -1,4 +1,4 @@
1
1
  from .promptlayer import PromptLayer
2
2
 
3
- __version__ = "1.0.12"
3
+ __version__ = "1.0.13"
4
4
  __all__ = ["PromptLayer", "__version__"]
@@ -57,18 +57,30 @@ MAP_PROVIDER_TO_FUNCTION = {
57
57
 
58
58
 
59
59
  class PromptLayer:
60
- def __init__(self, api_key: str = None, enable_tracing: bool = False):
60
+ def __init__(
61
+ self,
62
+ api_key: str = None,
63
+ enable_tracing: bool = False,
64
+ workspace_id: int = None,
65
+ ):
61
66
  if api_key is None:
62
67
  api_key = os.environ.get("PROMPTLAYER_API_KEY")
68
+
63
69
  if api_key is None:
64
70
  raise ValueError(
65
- "PromptLayer API key not provided. Please set the PROMPTLAYER_API_KEY environment variable or pass the api_key parameter."
71
+ "PromptLayer API key not provided. "
72
+ "Please set the PROMPTLAYER_API_KEY environment variable or pass the api_key parameter."
66
73
  )
74
+
75
+ if enable_tracing and not workspace_id:
76
+ raise ValueError("Please set a workspace_id to enable tracing.")
77
+
67
78
  self.api_key = api_key
68
79
  self.templates = TemplateManager(api_key)
69
80
  self.group = GroupManager(api_key)
81
+ self.tracer = self._initialize_tracer(api_key, enable_tracing, workspace_id)
70
82
  self.track = TrackManager(api_key)
71
- self.tracer = self._initialize_tracer(enable_tracing)
83
+ self.workspace_id = workspace_id
72
84
 
73
85
  def __getattr__(
74
86
  self,
@@ -127,13 +139,18 @@ class PromptLayer:
127
139
  return result
128
140
  return self.templates.get(prompt_name, template_params)
129
141
 
130
- def _initialize_tracer(self, enable_tracing: bool):
142
+ @staticmethod
143
+ def _initialize_tracer(
144
+ api_key: str = None, enable_tracing: bool = False, workspace_id: int = None
145
+ ):
131
146
  if enable_tracing:
132
147
  resource = Resource(
133
148
  attributes={ResourceAttributes.SERVICE_NAME: "prompt-layer-library"}
134
149
  )
135
150
  tracer_provider = TracerProvider(resource=resource)
136
- promptlayer_exporter = PromptLayerSpanExporter(api_key=self.api_key)
151
+ promptlayer_exporter = PromptLayerSpanExporter(
152
+ api_key=api_key, workspace_id=workspace_id
153
+ )
137
154
  span_processor = BatchSpanProcessor(promptlayer_exporter)
138
155
  tracer_provider.add_span_processor(span_processor)
139
156
  trace.set_tracer_provider(tracer_provider)
@@ -8,9 +8,10 @@ from promptlayer.utils import URL_API_PROMPTLAYER
8
8
 
9
9
 
10
10
  class PromptLayerSpanExporter(SpanExporter):
11
- def __init__(self, api_key=None):
12
- self.url = f"{URL_API_PROMPTLAYER}/spans-bulk"
11
+ def __init__(self, api_key: str = None, workspace_id: int = None):
13
12
  self.api_key = api_key
13
+ self.url = f"{URL_API_PROMPTLAYER}/spans-bulk"
14
+ self.workspace_id = workspace_id
14
15
 
15
16
  def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
16
17
  request_data = []
@@ -64,7 +65,7 @@ class PromptLayerSpanExporter(SpanExporter):
64
65
  },
65
66
  json={
66
67
  "spans": request_data,
67
- "workspace_id": 1,
68
+ "workspace_id": self.workspace_id,
68
69
  },
69
70
  )
70
71
  response.raise_for_status()
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "promptlayer"
3
- version = "1.0.12"
3
+ version = "1.0.13"
4
4
  description = "PromptLayer is a platform for prompt engineering and tracks your LLM requests."
5
5
  authors = ["Magniv <hello@magniv.io>"]
6
6
  license = "Apache-2.0"
File without changes
File without changes