Skip to content

Commit

Permalink
update to handle error due to new content filtering method by api
Browse files Browse the repository at this point in the history
  • Loading branch information
wotey committed Aug 26, 2024
1 parent bd781c5 commit 1a2d520
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/backend/approaches/chatreadretrieveread.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import openai
from openai import AsyncAzureOpenAI
from openai import BadRequestError
from approaches.approach import Approach
from azure.search.documents import SearchClient
from azure.search.documents.models import RawVectorQuery
Expand Down Expand Up @@ -200,7 +201,10 @@ async def run(self, history: Sequence[dict[str, str]], overrides: dict[str, Any]
if filter_reasons:
error_message = "The generated content was filtered due to triggering Azure OpenAI's content filtering system. Reason(s): The response contains content flagged as " + ", ".join(filter_reasons)
raise ValueError(error_message)

except BadRequestError as e:
log.error(f"Error generating optimized keyword search: {str(e.body['message'])}")
yield json.dumps({"error": f"Error generating optimized keyword search: {str(e.body['message'])}"}) + "\n"
return
except Exception as e:
log.error(f"Error generating optimized keyword search: {str(e)}")
yield json.dumps({"error": f"Error generating optimized keyword search: {str(e)}"}) + "\n"
Expand Down
5 changes: 5 additions & 0 deletions app/backend/approaches/chatwebretrieveread.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from azure.core.credentials import AzureKeyCredential
import openai
from openai import AzureOpenAI
from openai import BadRequestError
from openai import AsyncAzureOpenAI
from approaches.approach import Approach
from core.messagebuilder import MessageBuilder
Expand Down Expand Up @@ -143,6 +144,10 @@ async def run(self, history: Sequence[dict[str, str]],overrides: dict[str, Any],

try:
query_resp = await self.make_chat_completion(messages)
except BadRequestError as e:
log.error(f"Error generating optimized keyword search: {str(e.body['message'])}")
yield json.dumps({"error": f"Error generating optimized keyword search: {str(e.body['message'])}"}) + "\n"
return
except Exception as e:
log.error(f"Error generating optimized keyword search: {str(e)}")
yield json.dumps({"error": f"Error generating optimized keyword search: {str(e)}"}) + "\n"
Expand Down

0 comments on commit 1a2d520

Please sign in to comment.