raise error for content_filter (#849)

* raise error for content_filter

* use the code field

* simplify
This commit is contained in:
Chi Wang
2023-12-06 08:12:09 -08:00
committed by GitHub
parent fa11c4fa42
commit 31c166435e

View File

@@ -248,12 +248,16 @@ class OpenAIWrapper:
continue # filter is not passed; try the next config
try:
response = self._completions_create(client, params)
except APIError:
except APIError as err:
error_code = getattr(err, "code", None)
if error_code == "content_filter":
# raise the error for content_filter
raise
logger.debug(f"config {i} failed", exc_info=1)
if i == last:
raise
else:
# add cost calculation before caching not matter filter is passed or not
# add cost calculation before caching no matter filter is passed or not
response.cost = self.cost(response)
self._update_usage_summary(response, use_cache=False)
if cache_seed is not None: