From 49e4aaf67326b3185405bdefb36efe79e4705a59 Mon Sep 17 00:00:00 2001 From: "Nguyen Trung Duc (john)" Date: Wed, 17 May 2023 08:35:19 +0700 Subject: [PATCH] Fix subclassing OpenAIEmbeddings (#4500) # Fix subclassing OpenAIEmbeddings Fixes #4498 ## Before submitting - Problem: Due to annotated type `Tuple[()]`. - Fix: Change the annotated type to "Iterable[str]". Even though tiktoken use [Collection[str]](https://github.com/openai/tiktoken/blob/095924e02c85617df6889698d94515f91666c7ea/tiktoken/core.py#L80) type annotation, but pydantic doesn't support Collection type, and [Iterable](https://docs.pydantic.dev/latest/usage/types/#typing-iterables) is the closest to Collection. --- langchain/embeddings/openai.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/langchain/embeddings/openai.py b/langchain/embeddings/openai.py index 9402f42a..9eb48852 100644 --- a/langchain/embeddings/openai.py +++ b/langchain/embeddings/openai.py @@ -9,6 +9,7 @@ from typing import ( List, Literal, Optional, + Sequence, Set, Tuple, Union, @@ -115,7 +116,7 @@ class OpenAIEmbeddings(BaseModel, Embeddings): openai_api_key: Optional[str] = None openai_organization: Optional[str] = None allowed_special: Union[Literal["all"], Set[str]] = set() - disallowed_special: Union[Literal["all"], Set[str], Tuple[()]] = "all" + disallowed_special: Union[Literal["all"], Set[str], Sequence[str]] = "all" chunk_size: int = 1000 """Maximum number of texts to embed in each batch""" max_retries: int = 6