From cebf63d41f92338775407973d14dcfc5bee68fef Mon Sep 17 00:00:00 2001 From: Dev Sharma <12devsharma10c@gmail.com> Date: Sun, 3 Aug 2025 00:05:51 +0530 Subject: [PATCH] fix: allow base64 string in Embedding model to prevent Pydantic warnings for Azure embeddings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR fixes #1039 by updating the Embedding response model used for Azure async embedding calls. Currently, when using the Azure Embeddings API in async mode, the SDK emits Pydantic warnings at every call because the embedding field is strictly typed as List[float]. However, Azure sometimes returns base64‑encoded strings instead of float arrays, which Pydantic tries to validate, resulting in noisy warnings and minor performance overhead. This change modifies the model to accept both List[float] and str for the embedding field and disables unnecessary validation, preventing Pydantic from trying to coerce base64 strings into float arrays. --- src/openai/types/embedding_create_params.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/openai/types/embedding_create_params.py b/src/openai/types/embedding_create_params.py index 94edce10a4..dadc8f9595 100644 --- a/src/openai/types/embedding_create_params.py +++ b/src/openai/types/embedding_create_params.py @@ -1,4 +1,20 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +import openai +from embedding_patch import PatchedEmbedding + +openai.types.Embeddings.Embedding = PatchedEmbedding + +from typing import List, Union +from pydantic import BaseModel + +class PatchedEmbedding(BaseModel): + embedding: Union[List[float], str] + index: int + + class Config: + arbitrary_types_allowed = True + validate_assignment = False + from __future__ import annotations