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>
pull/16747/head
Shay Ben Elazar 8 months ago committed by GitHub
parent 32c5be8b73
commit 84ebfb5b9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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

Loading…
Cancel
Save