Harrison/azure content filter (#4645)

Co-authored-by: Rob Kopel <R0bk@users.noreply.github.com>
This commit is contained in:
Harrison Chase 2023-05-13 21:46:51 -07:00 committed by GitHub
parent f5e2f70115
commit 5020094e3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@ from typing import Any, Dict, Mapping
from pydantic import root_validator
from langchain.chat_models.openai import ChatOpenAI
from langchain.schema import ChatResult
from langchain.utils import get_from_dict_or_env
logger = logging.getLogger(__name__)
@ -119,3 +120,12 @@ class AzureChatOpenAI(ChatOpenAI):
@property
def _llm_type(self) -> str:
return "azure-openai-chat"
def _create_chat_result(self, response: Mapping[str, Any]) -> ChatResult:
for res in response["choices"]:
if res.get("finish_reason", None) == "content_filter":
raise ValueError(
"Azure has not provided the response due to a content"
" filter being triggered"
)
return super()._create_chat_result(response)