Skip to content

Commit d9ea3bc

Browse files
committed
update: improve polling module with type hints and copy constructor
- Add type hints using from __future__ import annotations - Add copy constructor support for APIPolling class - Rename api_key_polling to api_polling for consistency - Fix AsyncOpenAI return type annotation
1 parent 89b2dba commit d9ea3bc

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

src/openai_api_polling/polling/api_polling.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
# @Email : sepinetam@gmail.com
88
# @File : api_polling.py
99

10+
from __future__ import annotations
11+
1012
from typing import List
1113

1214

1315
class APIPolling:
1416
def __init__(self,
15-
api_keys: List[str]):
16-
self.api_polling = api_keys
17+
api_keys: APIPolling | List[str]):
18+
if isinstance(api_keys, APIPolling):
19+
self.api_polling = list(api_keys.api_polling).copy()
20+
else:
21+
self.api_polling = api_keys
1722
self._index = 0
1823

1924
def __str__(self):

src/openai_api_polling/polling/client_polling.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,26 @@
1616

1717
class ClientPolling:
1818
def __init__(self,
19-
api_keys: List[str],
19+
api_keys: APIPolling | List[str],
2020
*args, **kwargs):
21-
self.api_key_polling = APIPolling(api_keys)
21+
self.api_polling = APIPolling(api_keys)
2222
self.openai_kwargs = kwargs.copy()
2323

2424
def __len__(self):
25-
return self.api_key_polling.polling_length
25+
return self.api_polling.polling_length
2626

2727
@property
2828
def client(self) -> OpenAI:
2929
client = OpenAI(
30-
api_key=self.api_key_polling.api_key,
30+
api_key=self.api_polling.api_key,
3131
**self.openai_kwargs
3232
)
3333
return client
3434

3535
@property
36-
def async_client(self) -> OpenAI:
36+
def async_client(self) -> AsyncOpenAI:
3737
client = AsyncOpenAI(
38-
api_key=self.api_key_polling.api_key,
38+
api_key=self.api_polling.api_key,
3939
**self.openai_kwargs
4040
)
4141
return client
42-

0 commit comments

Comments
 (0)