77# @Email : sepinetam@gmail.com
88# @File : client_polling.py
99
10+ from __future__ import annotations
11+
12+ from os import PathLike
13+ from pathlib import Path
1014from typing import List
1115
1216import anthropic
1721
1822
1923class ClientPolling :
24+ api_file = Path .home () / ".api" # Default api file path
25+
2026 def __init__ (self ,
21- api_keys : APIPolling | List [str ],
27+ api_keys : APIPolling | List [str ] = None ,
2228 * args , ** kwargs ):
23- self .api_polling = APIPolling (api_keys )
29+ if api_keys is None :
30+ self .api_polling = APIPolling .load_api ()
31+ else :
32+ if isinstance (api_keys , APIPolling ):
33+ self .api_polling = api_keys
34+ elif isinstance (api_keys , list ):
35+ self .api_polling = APIPolling (api_keys )
36+ else :
37+ raise TypeError (f"api_keys must be APIPolling or list or None, but got { type (api_keys )} " )
2438 self .client_kwargs = kwargs .copy ()
2539
2640 def __len__ (self ):
2741 return self .api_polling .polling_length
2842
43+ @classmethod
44+ def load_from_api (cls ,
45+ api_file : str | PathLike = None ,
46+ * args , ** kwargs ) -> ClientPolling :
47+ api_polling = APIPolling .load_api (api_file or cls .api_file )
48+ return cls (api_polling , * args , ** kwargs )
49+
2950 @property
3051 def client (self ) -> OpenAI :
3152 client = OpenAI (
@@ -44,6 +65,8 @@ def async_client(self) -> AsyncOpenAI:
4465
4566
4667class GeminiClientPolling (ClientPolling ):
68+ api_file = Path .home () / ".gemini.api"
69+
4770 @property
4871 def client (self ) -> genai .Client :
4972 client = genai .Client (
@@ -61,6 +84,8 @@ def async_client(self) -> genai.Client:
6184
6285
6386class ClaudeClientPolling (ClientPolling ):
87+ api_file = Path .home () / ".claude.api"
88+
6489 @property
6590 def client (self ) -> anthropic .Anthropic :
6691 client = anthropic .Anthropic (
0 commit comments