openai[patch]: Added annotations support to azure openai (#13704)

- **Description:** Added Azure OpenAI Annotations (content filtering
results) to ChatResult

  - **Issue:** 13090

  - **Twitter handle:** ElazarShay

Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
Shay Ben Elazar 2024-01-29 23:31:09 +02:00 committed by GitHub
parent 32c5be8b73
commit 84ebfb5b9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -217,9 +217,19 @@ class AzureChatOpenAI(ChatOpenAI):
if self.model_version:
model = f"{model}-{self.model_version}"
if chat_result.llm_output is not None and isinstance(
chat_result.llm_output, dict
):
chat_result.llm_output["model_name"] = model
chat_result.llm_output = chat_result.llm_output or {}
chat_result.llm_output["model_name"] = model
if "prompt_filter_results" in response:
chat_result.llm_output = chat_result.llm_output or {}
chat_result.llm_output["prompt_filter_results"] = response[
"prompt_filter_results"
]
for chat_gen, response_choice in zip(
chat_result.generations, response["choices"]
):
chat_gen.generation_info = chat_gen.generation_info or {}
chat_gen.generation_info["content_filter_results"] = response_choice.get(
"content_filter_results", {}
)
return chat_result