mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-25 13:00:24 +08:00
Session Close when called HuggingFace Client (#411)
* [FIX] Session Close * [NEW] Async Context Managers of Response * [NEW] Linting
This commit is contained in:
@@ -35,15 +35,17 @@ class HuggingFaceAPI:
|
||||
inference: the inference we obtain from the model in HF
|
||||
"""
|
||||
|
||||
session = aiohttp.ClientSession()
|
||||
payload: Dict[str, str] = {"inputs": input}
|
||||
response = await session.post(self.api_url, headers=self.headers, json=payload)
|
||||
async with aiohttp.ClientSession() as session:
|
||||
payload: Dict[str, str] = {"inputs": input}
|
||||
|
||||
# If we get a bad response
|
||||
if response.status != 200:
|
||||
raise OasstError("Response Error Detoxify HuggingFace", error_code=OasstErrorCode.HUGGINGFACE_API_ERROR)
|
||||
async with session.post(self.api_url, headers=self.headers, json=payload) as response:
|
||||
# If we get a bad response
|
||||
if response.status != 200:
|
||||
raise OasstError(
|
||||
"Response Error Detoxify HuggingFace", error_code=OasstErrorCode.HUGGINGFACE_API_ERROR
|
||||
)
|
||||
|
||||
# Get the response from the API call
|
||||
inference = await response.json()
|
||||
# Get the response from the API call
|
||||
inference = await response.json()
|
||||
|
||||
return inference
|
||||
|
||||
Reference in New Issue
Block a user