Skip to content

Commit 0a55867

Browse files
committed
feat: support Gemini Client and Anthropic Client
1 parent 3cfd60a commit 0a55867

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ authors = [
88
]
99
requires-python = ">=3.11"
1010
dependencies = [
11+
"anthropic>=0.75.0",
12+
"google-genai>=1.55.0",
1113
"openai>=2.0.0",
1214
"tiktoken>=0.10.0",
1315
]

src/openai_api_polling/polling/client_polling.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from typing import List
1111

12+
import anthropic
13+
from google import genai
1214
from openai import AsyncOpenAI, OpenAI
1315

1416
from .api_polling import APIPolling
@@ -19,7 +21,7 @@ def __init__(self,
1921
api_keys: APIPolling | List[str],
2022
*args, **kwargs):
2123
self.api_polling = APIPolling(api_keys)
22-
self.openai_kwargs = kwargs.copy()
24+
self.client_kwargs = kwargs.copy()
2325

2426
def __len__(self):
2527
return self.api_polling.polling_length
@@ -28,14 +30,49 @@ def __len__(self):
2830
def client(self) -> OpenAI:
2931
client = OpenAI(
3032
api_key=self.api_polling.api_key,
31-
**self.openai_kwargs
33+
**self.client_kwargs
3234
)
3335
return client
3436

3537
@property
3638
def async_client(self) -> AsyncOpenAI:
3739
client = AsyncOpenAI(
3840
api_key=self.api_polling.api_key,
39-
**self.openai_kwargs
41+
**self.client_kwargs
42+
)
43+
return client
44+
45+
46+
class GeminiClientPolling(ClientPolling):
47+
@property
48+
def client(self) -> genai.Client:
49+
client = genai.Client(
50+
api_key=self.api_polling.api_key,
51+
**self.client_kwargs
52+
)
53+
return client
54+
55+
@property
56+
def async_client(self) -> genai.Client:
57+
"""
58+
Google GenAI SDK not support async client. (At least I have not found that)
59+
"""
60+
return self.client
61+
62+
63+
class ClaudeClientPolling(ClientPolling):
64+
@property
65+
def client(self) -> anthropic.Anthropic:
66+
client = anthropic.Anthropic(
67+
api_key=self.api_polling.api_key,
68+
**self.client_kwargs
69+
)
70+
return client
71+
72+
@property
73+
def async_client(self) -> anthropic.AsyncAnthropic:
74+
client = anthropic.AsyncAnthropic(
75+
api_key=self.api_polling.api_key,
76+
**self.client_kwargs
4077
)
4178
return client

0 commit comments

Comments
 (0)