promptlayer 1.0.22__py3-none-any.whl → 1.0.24__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.

Potentially problematic release.


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

promptlayer/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  from .promptlayer import PromptLayer
2
2
 
3
- __version__ = "1.0.22"
3
+ __version__ = "1.0.24"
4
4
  __all__ = ["PromptLayer", "__version__"]
@@ -20,6 +20,7 @@ from promptlayer.utils import (
20
20
  anthropic_request,
21
21
  anthropic_stream_completion,
22
22
  anthropic_stream_message,
23
+ azure_openai_request,
23
24
  openai_request,
24
25
  openai_stream_chat,
25
26
  openai_stream_completion,
@@ -50,11 +51,22 @@ MAP_PROVIDER_TO_FUNCTION_NAME = {
50
51
  "stream_function": anthropic_stream_completion,
51
52
  },
52
53
  },
54
+ "openai.azure": {
55
+ "chat": {
56
+ "function_name": "openai.AzureOpenAI.chat.completions.create",
57
+ "stream_function": openai_stream_chat,
58
+ },
59
+ "completion": {
60
+ "function_name": "openai.AzureOpenAI.completions.create",
61
+ "stream_function": openai_stream_completion,
62
+ },
63
+ },
53
64
  }
54
65
 
55
66
  MAP_PROVIDER_TO_FUNCTION = {
56
67
  "openai": openai_request,
57
68
  "anthropic": anthropic_request,
69
+ "openai.azure": azure_openai_request,
58
70
  }
59
71
 
60
72
 
@@ -170,7 +182,7 @@ class PromptLayer:
170
182
  kwargs["base_url"] = provider_base_url["url"]
171
183
 
172
184
  kwargs["stream"] = stream
173
- if stream and provider == "openai":
185
+ if stream and provider in ["openai", "openai.azure"]:
174
186
  kwargs["stream_options"] = {"include_usage": True}
175
187
 
176
188
  return {
@@ -365,7 +377,9 @@ class PromptLayer:
365
377
  input_variables: Optional[Dict[str, Any]] = None,
366
378
  metadata: Optional[Dict[str, str]] = None,
367
379
  workflow_label_name: Optional[str] = None,
368
- workflow_version_number: Optional[int] = None,
380
+ workflow_version: Optional[
381
+ int
382
+ ] = None, # This is the version number, not the version ID
369
383
  ) -> Dict[str, Any]:
370
384
  try:
371
385
  result = run_workflow_request(
@@ -373,7 +387,7 @@ class PromptLayer:
373
387
  input_variables=input_variables or {},
374
388
  metadata=metadata,
375
389
  workflow_label_name=workflow_label_name,
376
- workflow_version_number=workflow_version_number,
390
+ workflow_version_number=workflow_version,
377
391
  api_key=self.api_key,
378
392
  )
379
393
  return result
promptlayer/utils.py CHANGED
@@ -772,8 +772,10 @@ def openai_stream_chat(results: list):
772
772
  ChatCompletion,
773
773
  ChatCompletionChunk,
774
774
  ChatCompletionMessage,
775
+ ChatCompletionMessageToolCall,
775
776
  )
776
777
  from openai.types.chat.chat_completion import Choice
778
+ from openai.types.chat.chat_completion_message_tool_call import Function
777
779
 
778
780
  chat_completion_chunks: List[ChatCompletionChunk] = results
779
781
  response: ChatCompletion = ChatCompletion(
@@ -796,10 +798,42 @@ def openai_stream_chat(results: list):
796
798
  response.system_fingerprint = last_result.system_fingerprint
797
799
  response.usage = last_result.usage
798
800
  content = ""
801
+ tool_calls: Union[List[ChatCompletionMessageToolCall], None] = None
799
802
  for result in chat_completion_chunks:
800
- if len(result.choices) > 0 and result.choices[0].delta.content:
803
+ choices = result.choices
804
+ if len(choices) == 0:
805
+ continue
806
+ if choices[0].delta.content:
801
807
  content = f"{content}{result.choices[0].delta.content}"
808
+
809
+ delta = choices[0].delta
810
+ if delta.tool_calls:
811
+ tool_calls = tool_calls or []
812
+ last_tool_call = None
813
+ if len(tool_calls) > 0:
814
+ last_tool_call = tool_calls[-1]
815
+ tool_call = delta.tool_calls[0]
816
+ if not tool_call.function:
817
+ continue
818
+ if not last_tool_call or tool_call.id:
819
+ tool_calls.append(
820
+ ChatCompletionMessageToolCall(
821
+ id=tool_call.id or "",
822
+ function=Function(
823
+ name=tool_call.function.name or "",
824
+ arguments=tool_call.function.arguments or "",
825
+ ),
826
+ type=tool_call.type or "function",
827
+ )
828
+ )
829
+ continue
830
+ last_tool_call.function.name = (
831
+ f"{last_tool_call.function.name}{tool_call.function.name or ''}"
832
+ )
833
+ last_tool_call.function.arguments = f"{last_tool_call.function.arguments}{tool_call.function.arguments or ''}"
834
+
802
835
  response.choices[0].message.content = content
836
+ response.choices[0].message.tool_calls = tool_calls
803
837
  return response
804
838
 
805
839
 
@@ -923,6 +957,16 @@ def openai_request(prompt_blueprint: GetPromptTemplateResponse, **kwargs):
923
957
  return request_to_make(client, **kwargs)
924
958
 
925
959
 
960
+ def azure_openai_request(prompt_blueprint: GetPromptTemplateResponse, **kwargs):
961
+ from openai import AzureOpenAI
962
+
963
+ client = AzureOpenAI(base_url=kwargs.pop("base_url", None))
964
+ request_to_make = MAP_TYPE_TO_OPENAI_FUNCTION[
965
+ prompt_blueprint["prompt_template"]["type"]
966
+ ]
967
+ return request_to_make(client, **kwargs)
968
+
969
+
926
970
  def anthropic_chat_request(client, **kwargs):
927
971
  return client.messages.create(**kwargs)
928
972
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: promptlayer
3
- Version: 1.0.22
3
+ Version: 1.0.24
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,7 +1,7 @@
1
- promptlayer/__init__.py,sha256=aF6sRMIn2_Y9xori_4spKkreZWQiBat3aauSIgiBKo4,102
1
+ promptlayer/__init__.py,sha256=JTVK-6FTroG1GYTAY06uIChUCDWGll51745efZYKqlw,102
2
2
  promptlayer/groups/__init__.py,sha256=-xs-2cn0nc0D_5YxZr3nC86iTdRVZmBhEpOKDJXE-sQ,224
3
3
  promptlayer/groups/groups.py,sha256=yeO6T0TM3qB0ondZRiHhcH8G06YygrpFoM8b9RmoIao,165
4
- promptlayer/promptlayer.py,sha256=oyoH-toEteTAqt2rCBFqo4cWRIo1le-4eiwakNikOB8,16229
4
+ promptlayer/promptlayer.py,sha256=Qyju-mDJcf0NiGjV6SQHsyf1syXHekvKhzRzExOn31k,16719
5
5
  promptlayer/promptlayer_base.py,sha256=sev-EZehRXJSZSmJtMkqmAUK1345pqbDY_lNjPP5MYA,7158
6
6
  promptlayer/span_exporter.py,sha256=zIJNsb3Fe6yb5wKLDmkoPF2wqFjk1p39E0jWHD2plzI,2658
7
7
  promptlayer/templates.py,sha256=aY_-BCrL0AgIdYEUE28pi0AP_avTVAgwv5hgzrh75vo,717
@@ -10,8 +10,8 @@ promptlayer/track/track.py,sha256=XNEZT9yNiRBPp9vaDZo_f0dP_ldOu8q1qafpVfS5Ze8,16
10
10
  promptlayer/types/__init__.py,sha256=xJcvQuOk91ZBBePb40-1FDNDKYrZoH5lPE2q6_UhprM,111
11
11
  promptlayer/types/prompt_template.py,sha256=TUXLXvuvew0EBLfTMBa2LhFeQoF7R-tcFKg7_UUtHMQ,4433
12
12
  promptlayer/types/request_log.py,sha256=xU6bcxQar6GaBOJlgZTavXUV3FjE8sF_nSjPu4Ya_00,174
13
- promptlayer/utils.py,sha256=Q1IHSK98e-VCcbpU7bdmpA2iQ7YY5wlQ4K8lMV16vaM,31921
14
- promptlayer-1.0.22.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
15
- promptlayer-1.0.22.dist-info/METADATA,sha256=_cafx2H-l4TmvMTXNoi7BblkXMtucp8HklieARIvnCI,4660
16
- promptlayer-1.0.22.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
17
- promptlayer-1.0.22.dist-info/RECORD,,
13
+ promptlayer/utils.py,sha256=Oyk_n0hIbYaCFK98QaUzHQeEdGxfQL3HRfXY-AlbPm0,33662
14
+ promptlayer-1.0.24.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
15
+ promptlayer-1.0.24.dist-info/METADATA,sha256=iGmVrzJEanaYQsBLYY7t2hF4ly4jCAHQnJJD01QHXdc,4660
16
+ promptlayer-1.0.24.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
17
+ promptlayer-1.0.24.dist-info/RECORD,,