Skip to content

Commit a2bcbee

Browse files
committed
Merge branch 'main' into feat/oai1.78.0
2 parents c529bb1 + 49ca6fa commit a2bcbee

17 files changed

+1769
-22
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Portkey.ai
3+
Copyright (c) 2025 Portkey.ai
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

portkey_ai/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@
9999
InputItems,
100100
AsyncResponses,
101101
AsyncInputItems,
102+
Labels,
103+
AsyncLabels,
104+
Collections,
105+
AsyncCollections,
102106
FineTuningCheckpoints,
103107
AsyncFineTuningCheckpoints,
104108
Permissions,
@@ -231,6 +235,10 @@
231235
"InputItems",
232236
"AsyncResponses",
233237
"AsyncInputItems",
238+
"Labels",
239+
"AsyncLabels",
240+
"Collections",
241+
"AsyncCollections",
234242
"FineTuningCheckpoints",
235243
"AsyncFineTuningCheckpoints",
236244
"Permissions",

portkey_ai/api_resources/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
InputItems,
8888
AsyncResponses,
8989
AsyncInputItems,
90+
Labels,
91+
AsyncLabels,
92+
Collections,
93+
AsyncCollections,
9094
FineTuningCheckpoints,
9195
AsyncFineTuningCheckpoints,
9296
Permissions,
@@ -223,6 +227,10 @@
223227
"InputItems",
224228
"AsyncResponses",
225229
"AsyncInputItems",
230+
"Labels",
231+
"AsyncLabels",
232+
"Collections",
233+
"AsyncCollections",
226234
"FineTuningCheckpoints",
227235
"AsyncFineTuningCheckpoints",
228236
"Permissions",

portkey_ai/api_resources/apis/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@
123123
from .virtual_keys import VirtualKeys, AsyncVirtualKeys
124124
from .logs import Logs, AsyncLogs
125125

126+
from .labels import Labels, AsyncLabels
127+
128+
from .collections import Collections, AsyncCollections
129+
126130
sys.modules["openai"] = vendored_openai # For pydantic v1 and v2 compatibility
127131

128132
__all__ = [
@@ -217,6 +221,10 @@
217221
"InputItems",
218222
"AsyncResponses",
219223
"AsyncInputItems",
224+
"Labels",
225+
"AsyncLabels",
226+
"Collections",
227+
"AsyncCollections",
220228
"FineTuningCheckpoints",
221229
"AsyncFineTuningCheckpoints",
222230
"Permissions",

portkey_ai/api_resources/apis/api_keys.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def create(
2828
usage_limits: Optional[Dict[str, Any]] = None,
2929
scopes: List[str],
3030
defaults: Optional[Dict[str, Any]] = None,
31+
expires_at: Optional[Any] = None,
32+
**kwargs: Any,
3133
) -> ApiKeyAddResponse:
3234
body = {
3335
"type": type,
@@ -40,6 +42,8 @@ def create(
4042
"usage_limits": usage_limits,
4143
"scopes": scopes,
4244
"defaults": defaults,
45+
"expires_at": expires_at,
46+
**kwargs,
4347
}
4448
return self._post(
4549
f"{PortkeyApiPaths.API_KEYS_API}/{type}/{sub_type}",
@@ -96,6 +100,8 @@ def update(
96100
usage_limits: Optional[Dict[str, Any]] = None,
97101
scopes: Optional[List[str]] = None,
98102
defaults: Optional[Dict[str, Any]] = None,
103+
expires_at: Optional[Any] = None,
104+
**kwargs: Any,
99105
) -> Any:
100106
body = {
101107
"id": id,
@@ -105,6 +111,8 @@ def update(
105111
"usage_limits": usage_limits,
106112
"scopes": scopes,
107113
"defaults": defaults,
114+
"expires_at": expires_at,
115+
**kwargs,
108116
}
109117
return self._put(
110118
f"{PortkeyApiPaths.API_KEYS_API}/{id}",
@@ -149,6 +157,8 @@ async def create(
149157
usage_limits: Optional[Dict[str, Any]] = None,
150158
scopes: List[str],
151159
defaults: Optional[Dict[str, Any]] = None,
160+
expires_at: Optional[Any] = None,
161+
**kwargs: Any,
152162
) -> ApiKeyAddResponse:
153163
body = {
154164
"type": type,
@@ -161,6 +171,8 @@ async def create(
161171
"usage_limits": usage_limits,
162172
"scopes": scopes,
163173
"defaults": defaults,
174+
"expires_at": expires_at,
175+
**kwargs,
164176
}
165177
return await self._post(
166178
f"{PortkeyApiPaths.API_KEYS_API}/{type}/{sub_type}",
@@ -217,6 +229,8 @@ async def update(
217229
usage_limits: Optional[Dict[str, Any]] = None,
218230
scopes: Optional[List[str]] = None,
219231
defaults: Optional[Dict[str, Any]] = None,
232+
expires_at: Optional[Any] = None,
233+
**kwargs: Any,
220234
) -> Any:
221235
body = {
222236
"id": id,
@@ -226,6 +240,8 @@ async def update(
226240
"usage_limits": usage_limits,
227241
"scopes": scopes,
228242
"defaults": defaults,
243+
"expires_at": expires_at,
244+
**kwargs,
229245
}
230246
return await self._put(
231247
f"{PortkeyApiPaths.API_KEYS_API}/{id}",

portkey_ai/api_resources/apis/audio.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
from typing import Any, List, Union
33
from portkey_ai.api_resources.apis.api_resource import APIResource, AsyncAPIResource
4+
from portkey_ai.api_resources.global_constants import AUDIO_FILE_DURATION_HEADER
5+
from portkey_ai.api_resources.get_audio_duration import get_audio_file_duration
46
from ..._vendor.openai._types import NotGiven, NOT_GIVEN, FileTypes
57
from portkey_ai.api_resources.client import AsyncPortkey, Portkey
68
import typing
@@ -39,9 +41,13 @@ def create(
3941
temperature: Union[float, NotGiven] = NOT_GIVEN,
4042
timestamp_granularities: Union[List[str], NotGiven] = NOT_GIVEN,
4143
stream: Union[bool, NotGiven] = NOT_GIVEN,
42-
**kwargs
44+
**kwargs,
4345
) -> Union[Transcription, TranscriptionVerbose, str]:
4446
extra_headers = kwargs.pop("extra_headers", {})
47+
if file.name and self._client.calculate_audio_duration:
48+
duration = get_audio_file_duration(file.name)
49+
if duration is not None:
50+
extra_headers[AUDIO_FILE_DURATION_HEADER] = duration
4551
if stream:
4652
return self.openai_client.audio.transcriptions.create(
4753
file=file,
@@ -93,9 +99,13 @@ def create(
9399
model: str,
94100
prompt: Union[str, NotGiven] = NOT_GIVEN,
95101
temperature: Union[float, NotGiven] = NOT_GIVEN,
96-
**kwargs
102+
**kwargs,
97103
) -> Union[Translation, TranslationVerbose, str]:
98104
extra_headers = kwargs.pop("extra_headers", {})
105+
if file.name and self._client.calculate_audio_duration: # type: ignore[union-attr]
106+
duration = get_audio_file_duration(file.name) # type: ignore[union-attr]
107+
if duration is not None:
108+
extra_headers[AUDIO_FILE_DURATION_HEADER] = duration
99109
response = self.openai_client.with_raw_response.audio.translations.create(
100110
file=file,
101111
model=model,
@@ -125,7 +135,7 @@ def create(
125135
response_format: Union[str, NotGiven] = NOT_GIVEN,
126136
speed: Union[float, NotGiven] = NOT_GIVEN,
127137
stream: Union[bool, NotGiven] = NOT_GIVEN,
128-
**kwargs
138+
**kwargs,
129139
) -> Any:
130140
if stream is True:
131141
self.openai_client = self.openai_client.with_streaming_response
@@ -169,9 +179,13 @@ async def create(
169179
temperature: Union[float, NotGiven] = NOT_GIVEN,
170180
timestamp_granularities: Union[List[str], NotGiven] = NOT_GIVEN,
171181
stream: Union[bool, NotGiven] = NOT_GIVEN,
172-
**kwargs
182+
**kwargs,
173183
) -> Union[Transcription, TranscriptionVerbose, str]:
174184
extra_headers = kwargs.pop("extra_headers", {})
185+
if file.name and self._client.calculate_audio_duration:
186+
duration = get_audio_file_duration(file.name)
187+
if duration is not None:
188+
extra_headers[AUDIO_FILE_DURATION_HEADER] = duration
175189
if stream:
176190
return await self.openai_client.audio.transcriptions.create(
177191
file=file,
@@ -225,9 +239,13 @@ async def create(
225239
model: str,
226240
prompt: Union[str, NotGiven] = NOT_GIVEN,
227241
temperature: Union[float, NotGiven] = NOT_GIVEN,
228-
**kwargs
242+
**kwargs,
229243
) -> Union[Translation, TranslationVerbose, str]:
230244
extra_headers = kwargs.pop("extra_headers", {})
245+
if file.name and self._client.calculate_audio_duration: # type: ignore[union-attr]
246+
duration = get_audio_file_duration(file.name) # type: ignore[union-attr]
247+
if duration is not None:
248+
extra_headers[AUDIO_FILE_DURATION_HEADER] = duration
231249
response = await self.openai_client.with_raw_response.audio.translations.create(
232250
file=file,
233251
model=model,
@@ -257,7 +275,7 @@ async def create(
257275
response_format: Union[str, NotGiven] = NOT_GIVEN,
258276
speed: Union[float, NotGiven] = NOT_GIVEN,
259277
stream: Union[bool, NotGiven] = NOT_GIVEN,
260-
**kwargs
278+
**kwargs,
261279
) -> Any:
262280
if stream is True:
263281
self.openai_client = await self.openai_client.with_streaming_response

0 commit comments

Comments
 (0)