promptlayer 1.0.22__tar.gz → 1.0.23__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.
- {promptlayer-1.0.22 → promptlayer-1.0.23}/PKG-INFO +1 -1
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/__init__.py +1 -1
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/promptlayer.py +13 -1
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/utils.py +45 -1
- {promptlayer-1.0.22 → promptlayer-1.0.23}/pyproject.toml +1 -1
- {promptlayer-1.0.22 → promptlayer-1.0.23}/LICENSE +0 -0
- {promptlayer-1.0.22 → promptlayer-1.0.23}/README.md +0 -0
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/groups/__init__.py +0 -0
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/groups/groups.py +0 -0
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/promptlayer_base.py +0 -0
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/span_exporter.py +0 -0
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/templates.py +0 -0
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/track/__init__.py +0 -0
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/track/track.py +0 -0
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/types/__init__.py +0 -0
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/types/prompt_template.py +0 -0
- {promptlayer-1.0.22 → promptlayer-1.0.23}/promptlayer/types/request_log.py +0 -0
|
@@ -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
|
|
185
|
+
if stream and provider in ["openai", "openai.azure"]:
|
|
174
186
|
kwargs["stream_options"] = {"include_usage": True}
|
|
175
187
|
|
|
176
188
|
return {
|
|
@@ -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
|
-
|
|
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
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|