File tree Expand file tree Collapse file tree 4 files changed +24
-2
lines changed Expand file tree Collapse file tree 4 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 1
1
name : Development
2
2
3
3
on :
4
- pull_request :
4
+ pull_request_target :
5
5
types : [opened, synchronize, reopened]
6
6
7
7
jobs :
Original file line number Diff line number Diff line change @@ -110,6 +110,14 @@ def info(self) -> dict[str, Any]:
110
110
"""
111
111
...
112
112
113
+ @abstractmethod
114
+ async def reset (self ) -> None :
115
+ """
116
+ Reset the connection object. This is useful for backends that
117
+ reuse connections or have state that needs to be cleared.
118
+ """
119
+ ...
120
+
113
121
async def validate (self ):
114
122
"""
115
123
Handle final setup and validate the backend is ready for use.
@@ -126,6 +134,8 @@ async def validate(self):
126
134
): # type: ignore[attr-defined]
127
135
pass
128
136
137
+ await self .reset ()
138
+
129
139
@abstractmethod
130
140
async def check_setup (self ):
131
141
"""
Original file line number Diff line number Diff line change @@ -157,6 +157,15 @@ def info(self) -> dict[str, Any]:
157
157
"chat_completions_path" : CHAT_COMPLETIONS_PATH ,
158
158
}
159
159
160
+ async def reset (self ) -> None :
161
+ """
162
+ Reset the connection object. This is useful for backends that
163
+ reuse connections or have state that needs to be cleared.
164
+ For this backend, it closes the async client if it exists.
165
+ """
166
+ if self ._async_client is not None :
167
+ await self ._async_client .aclose ()
168
+
160
169
async def check_setup (self ):
161
170
"""
162
171
Check if the backend is setup correctly and can be used for requests.
@@ -361,7 +370,7 @@ def _get_async_client(self) -> httpx.AsyncClient:
361
370
362
371
:return: The async HTTP client.
363
372
"""
364
- if self ._async_client is None :
373
+ if self ._async_client is None or self . _async_client . is_closed :
365
374
client = httpx .AsyncClient (
366
375
http2 = self .http2 ,
367
376
timeout = self .timeout ,
Original file line number Diff line number Diff line change @@ -41,6 +41,9 @@ def model(self) -> Optional[str]:
41
41
def info (self ) -> dict [str , Any ]:
42
42
return {}
43
43
44
+ async def reset (self ) -> None :
45
+ pass
46
+
44
47
async def prepare_multiprocessing (self ):
45
48
pass
46
49
You can’t perform that action at this time.
0 commit comments