From 1e7157a9aca411205a1bfbece55142ab7e22fb78 Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Sun, 2 Jun 2024 11:40:23 +0300 Subject: [PATCH 01/21] Adjust LocalAI embeds for OpenAI 1.30 --- .../langchain_community/embeddings/localai.py | 66 ++++--- .../cassettes/test_localai_embed.yaml | 163 ++++++++++++++++++ .../embeddings/test_localai.py | 14 ++ 3 files changed, 218 insertions(+), 25 deletions(-) create mode 100644 libs/community/tests/integration_tests/embeddings/cassettes/test_localai_embed.yaml create mode 100644 libs/community/tests/integration_tests/embeddings/test_localai.py diff --git a/libs/community/langchain_community/embeddings/localai.py b/libs/community/langchain_community/embeddings/localai.py index 924f162128ec2..499e370c89e0e 100644 --- a/libs/community/langchain_community/embeddings/localai.py +++ b/libs/community/langchain_community/embeddings/localai.py @@ -46,11 +46,11 @@ def _create_retry_decorator(embeddings: LocalAIEmbeddings) -> Callable[[Any], An stop=stop_after_attempt(embeddings.max_retries), wait=wait_exponential(multiplier=1, min=min_seconds, max=max_seconds), retry=( - retry_if_exception_type(openai.error.Timeout) - | retry_if_exception_type(openai.error.APIError) - | retry_if_exception_type(openai.error.APIConnectionError) - | retry_if_exception_type(openai.error.RateLimitError) - | retry_if_exception_type(openai.error.ServiceUnavailableError) + retry_if_exception_type(openai.APITimeoutError) + | retry_if_exception_type(openai.APIError) + | retry_if_exception_type(openai.APIConnectionError) + | retry_if_exception_type(openai.RateLimitError) + | retry_if_exception_type(openai.InternalServerError) ), before_sleep=before_sleep_log(logger, logging.WARNING), ) @@ -68,11 +68,11 @@ def _async_retry_decorator(embeddings: LocalAIEmbeddings) -> Any: stop=stop_after_attempt(embeddings.max_retries), wait=wait_exponential(multiplier=1, min=min_seconds, max=max_seconds), retry=( - retry_if_exception_type(openai.error.Timeout) - | retry_if_exception_type(openai.error.APIError) - | retry_if_exception_type(openai.error.APIConnectionError) - | retry_if_exception_type(openai.error.RateLimitError) - | retry_if_exception_type(openai.error.ServiceUnavailableError) + retry_if_exception_type(openai.APITimeoutError) + | retry_if_exception_type(openai.APIError) + | retry_if_exception_type(openai.APIConnectionError) + | retry_if_exception_type(openai.RateLimitError) + | retry_if_exception_type(openai.InternalServerError) ), before_sleep=before_sleep_log(logger, logging.WARNING), ) @@ -90,10 +90,10 @@ async def wrapped_f(*args: Any, **kwargs: Any) -> Callable: # https://stackoverflow.com/questions/76469415/getting-embeddings-of-length-1-from-langchain-openaiembeddings def _check_response(response: dict) -> dict: - if any(len(d["embedding"]) == 1 for d in response["data"]): + if any(len(d.embedding) == 1 for d in response.data): import openai - raise openai.error.APIError("LocalAI API returned an empty embedding") + raise openai.APIError("LocalAI API returned an empty embedding") return response @@ -229,8 +229,20 @@ def validate_environment(cls, values: Dict) -> Dict: ) try: import openai - - values["client"] = openai.Embedding + client_params = { + "api_key": values["openai_api_key"], + "organization": values["openai_organization"], + "base_url": values["openai_api_base"], + "timeout": values["request_timeout"], + "max_retries": values["max_retries"], + #"default_headers": values["default_headers"], + #"default_query": values["default_query"], + #"http_client": values["http_client"], + } + #if not values.get("client"): + values["client"] = openai.OpenAI(**client_params).embeddings + + #values["client"] = openai.Embedding except ImportError: raise ImportError( "Could not import openai python package. " @@ -242,21 +254,25 @@ def validate_environment(cls, values: Dict) -> Dict: def _invocation_params(self) -> Dict: openai_args = { "model": self.model, - "request_timeout": self.request_timeout, - "headers": self.headers, - "api_key": self.openai_api_key, - "organization": self.openai_organization, - "api_base": self.openai_api_base, - "api_version": self.openai_api_version, + #"request_timeout": self.request_timeout, + #"headers": self.headers, + #"api_key": self.openai_api_key, + #"organization": self.openai_organization, + #"api_base": self.openai_api_base, + #"api_version": self.openai_api_version, **self.model_kwargs, } if self.openai_proxy: import openai - openai.proxy = { - "http": self.openai_proxy, - "https": self.openai_proxy, - } # type: ignore[assignment] + # TODO: The 'openai.proxy' option isn't read in the client API. You will need to pass it when you instantiate the client, e.g. 'OpenAI(proxy={ + # "http": self.openai_proxy, + # "https": self.openai_proxy, + # })' + # openai.proxy = { + # "http": self.openai_proxy, + # "https": self.openai_proxy, + # } # type: ignore[assignment] return openai_args def _embedding_func(self, text: str, *, engine: str) -> List[float]: @@ -270,7 +286,7 @@ def _embedding_func(self, text: str, *, engine: str) -> List[float]: self, input=[text], **self._invocation_params, - )["data"][0]["embedding"] + ).data[0].embedding async def _aembedding_func(self, text: str, *, engine: str) -> List[float]: """Call out to LocalAI's embedding endpoint.""" diff --git a/libs/community/tests/integration_tests/embeddings/cassettes/test_localai_embed.yaml b/libs/community/tests/integration_tests/embeddings/cassettes/test_localai_embed.yaml new file mode 100644 index 0000000000000..8cc24eb22d438 --- /dev/null +++ b/libs/community/tests/integration_tests/embeddings/cassettes/test_localai_embed.yaml @@ -0,0 +1,163 @@ +interactions: +- request: + body: '{"input": ["foo bar"], "model": "bge-m3", "encoding_format": "base64"}' + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + authorization: + - Bearer foo + connection: + - keep-alive + content-length: + - '70' + content-type: + - application/json + host: + - foo.bar + openai-organization: + - '' + user-agent: + - OpenAI/Python 1.30.1 + x-stainless-arch: + - x64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - Linux + x-stainless-package-version: + - 1.30.1 + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.19 + method: POST + uri: https://foo.bar/v1/embeddings + response: + body: + string: !!binary | + H4sIAAAAAAAEAzyXTZIdNw6E7/LW6gkCBElQV5lVS93hkMOyI2a08+X94afcvXlVxSLAzEQC9ffr + +/8+3399fry+ypEzZW9dX15/ffv98/uv19fXHz/+/+v15fWD56/v62wb099E73qzOT7e3v1T3o7r + p6vL/C7vrP3518fnHyz/9tvn28/JjY/3X++vr//9+/X589vnx8ePP3/javxniJ0rer688XuYLXOp + i21Lfa4vuWaq+K01Y83pZ9yVl2rTyFZj2Zhyrm/JCz0+B6fIfZdwJbs2G9vsHssncseVM05GUTM5 + Z3YYUz/bZyUjum3K3bFO1/YxZ60T9SXDVm499lHfZ9bea+8hN3c+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c1stnW9dYSKt5SRcl8sPT7zVbgO + 1DWDkNCwbIfV4VM0dsVpa2aMcqUwd9BFQaDM6FIgeIkxtb1LQhm5CvHhx43E8EFif3x48orJ6XX6 + 2e3vbl4+ub4vsprwfTm8Tbv97+78NX+el+dl/phOl3rixcBxWt7n0+3oMi+H43VgXf8AAAD//wMA + O2LeFe0yAAA= + headers: + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json + Date: + - Sun, 02 Jun 2024 08:23:45 GMT + Transfer-Encoding: + - chunked + Vary: + - Accept-Encoding + status: + code: 200 + message: OK +version: 1 diff --git a/libs/community/tests/integration_tests/embeddings/test_localai.py b/libs/community/tests/integration_tests/embeddings/test_localai.py new file mode 100644 index 0000000000000..eb60784db7b25 --- /dev/null +++ b/libs/community/tests/integration_tests/embeddings/test_localai.py @@ -0,0 +1,14 @@ +import pytest + +from langchain_community.embeddings import LocalAIEmbeddings + +@pytest.mark.requires("openai") +@pytest.mark.vcr +def test_localai_embed() -> None: + llm=LocalAIEmbeddings( + openai_api_key="foo", model="bge-m3", + openai_api_base="https://foo.bar/v1") + eqq=llm.embed_query("foo bar") + //print(eqq) + assert len(eqq) > 100 + assert eqq[0] != eqq[1] From b200394e03c0292498f8b66740aff22945fea598 Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Sun, 2 Jun 2024 11:41:12 +0300 Subject: [PATCH 02/21] Adjust LocalAI embeds for OpenAI 1.30 --- .../community/tests/integration_tests/embeddings/test_localai.py | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/community/tests/integration_tests/embeddings/test_localai.py b/libs/community/tests/integration_tests/embeddings/test_localai.py index eb60784db7b25..8b79b3ed24493 100644 --- a/libs/community/tests/integration_tests/embeddings/test_localai.py +++ b/libs/community/tests/integration_tests/embeddings/test_localai.py @@ -9,6 +9,5 @@ def test_localai_embed() -> None: openai_api_key="foo", model="bge-m3", openai_api_base="https://foo.bar/v1") eqq=llm.embed_query("foo bar") - //print(eqq) assert len(eqq) > 100 assert eqq[0] != eqq[1] From c5c500fdce7781eef7da9deef9eea8890c7027b0 Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Sun, 2 Jun 2024 11:51:22 +0300 Subject: [PATCH 03/21] format --- .../langchain_community/embeddings/localai.py | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/libs/community/langchain_community/embeddings/localai.py b/libs/community/langchain_community/embeddings/localai.py index 499e370c89e0e..8335b45b5d686 100644 --- a/libs/community/langchain_community/embeddings/localai.py +++ b/libs/community/langchain_community/embeddings/localai.py @@ -229,20 +229,21 @@ def validate_environment(cls, values: Dict) -> Dict: ) try: import openai + client_params = { "api_key": values["openai_api_key"], "organization": values["openai_organization"], "base_url": values["openai_api_base"], "timeout": values["request_timeout"], "max_retries": values["max_retries"], - #"default_headers": values["default_headers"], - #"default_query": values["default_query"], - #"http_client": values["http_client"], + # "default_headers": values["default_headers"], + # "default_query": values["default_query"], + # "http_client": values["http_client"], } - #if not values.get("client"): + # if not values.get("client"): values["client"] = openai.OpenAI(**client_params).embeddings - #values["client"] = openai.Embedding + # values["client"] = openai.Embedding except ImportError: raise ImportError( "Could not import openai python package. " @@ -254,12 +255,12 @@ def validate_environment(cls, values: Dict) -> Dict: def _invocation_params(self) -> Dict: openai_args = { "model": self.model, - #"request_timeout": self.request_timeout, - #"headers": self.headers, - #"api_key": self.openai_api_key, - #"organization": self.openai_organization, - #"api_base": self.openai_api_base, - #"api_version": self.openai_api_version, + # "request_timeout": self.request_timeout, + # "headers": self.headers, + # "api_key": self.openai_api_key, + # "organization": self.openai_organization, + # "api_base": self.openai_api_base, + # "api_version": self.openai_api_version, **self.model_kwargs, } if self.openai_proxy: @@ -282,11 +283,15 @@ def _embedding_func(self, text: str, *, engine: str) -> List[float]: # See: https://github.com/openai/openai-python/issues/418#issuecomment-1525939500 # replace newlines, which can negatively affect performance. text = text.replace("\n", " ") - return embed_with_retry( - self, - input=[text], - **self._invocation_params, - ).data[0].embedding + return ( + embed_with_retry( + self, + input=[text], + **self._invocation_params, + ) + .data[0] + .embedding + ) async def _aembedding_func(self, text: str, *, engine: str) -> List[float]: """Call out to LocalAI's embedding endpoint.""" From 461b201ea51d715185613c1cad366cce8580d2a5 Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Sun, 2 Jun 2024 17:13:41 +0300 Subject: [PATCH 04/21] removing proxy, providing advise. --- .../langchain_community/embeddings/localai.py | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/libs/community/langchain_community/embeddings/localai.py b/libs/community/langchain_community/embeddings/localai.py index 8335b45b5d686..b117ee2f17ed1 100644 --- a/libs/community/langchain_community/embeddings/localai.py +++ b/libs/community/langchain_community/embeddings/localai.py @@ -139,6 +139,22 @@ class LocalAIEmbeddings(BaseModel, Embeddings): openai_api_base="http://localhost:8080" ) + Specifying proxy: + .. code-block:: python + + from langchain_community.embeddings import LocalAIEmbeddings + import openai + import httpx + openai = LocalAIEmbeddings( + openai_api_key="random-string", + client=openai.OpenAI( + base_url="http://localhost:8080", + http_client=openai.DefaultHttpxClient( + proxies="http://localhost:8899", + transport=httpx.HTTPTransport(local_address="0.0.0.0"), + ), + api_key="random-string").embeddings + ) """ client: Any = None #: :meta private: @@ -146,8 +162,6 @@ class LocalAIEmbeddings(BaseModel, Embeddings): deployment: str = model openai_api_version: Optional[str] = None openai_api_base: Optional[str] = None - # to support explicit proxy for LocalAI - openai_proxy: Optional[str] = None embedding_ctx_length: int = 8191 """The maximum number of tokens to embed at once.""" openai_api_key: Optional[str] = None @@ -207,12 +221,6 @@ def validate_environment(cls, values: Dict) -> Dict: "OPENAI_API_BASE", default="", ) - values["openai_proxy"] = get_from_dict_or_env( - values, - "openai_proxy", - "OPENAI_PROXY", - default="", - ) default_api_version = "" values["openai_api_version"] = get_from_dict_or_env( @@ -240,8 +248,8 @@ def validate_environment(cls, values: Dict) -> Dict: # "default_query": values["default_query"], # "http_client": values["http_client"], } - # if not values.get("client"): - values["client"] = openai.OpenAI(**client_params).embeddings + if not values.get("client"): + values["client"] = openai.OpenAI(**client_params).embeddings # values["client"] = openai.Embedding except ImportError: @@ -263,17 +271,6 @@ def _invocation_params(self) -> Dict: # "api_version": self.openai_api_version, **self.model_kwargs, } - if self.openai_proxy: - import openai - - # TODO: The 'openai.proxy' option isn't read in the client API. You will need to pass it when you instantiate the client, e.g. 'OpenAI(proxy={ - # "http": self.openai_proxy, - # "https": self.openai_proxy, - # })' - # openai.proxy = { - # "http": self.openai_proxy, - # "https": self.openai_proxy, - # } # type: ignore[assignment] return openai_args def _embedding_func(self, text: str, *, engine: str) -> List[float]: @@ -306,7 +303,7 @@ async def _aembedding_func(self, text: str, *, engine: str) -> List[float]: input=[text], **self._invocation_params, ) - )["data"][0]["embedding"] + ).data[0].embedding def embed_documents( self, texts: List[str], chunk_size: Optional[int] = 0 From 063adf67b85bc642144d2c601b69dcbb034a8fa1 Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Sun, 2 Jun 2024 21:14:14 +0300 Subject: [PATCH 05/21] migrate async embeds as well, covering by test. --- .../langchain_community/embeddings/localai.py | 9 +- .../cassettes/test_localai_aembed.yaml | 163 ++++++++++++++++++ .../embeddings/test_localai.py | 13 ++ 3 files changed, 181 insertions(+), 4 deletions(-) create mode 100644 libs/community/tests/integration_tests/embeddings/cassettes/test_localai_aembed.yaml diff --git a/libs/community/langchain_community/embeddings/localai.py b/libs/community/langchain_community/embeddings/localai.py index b117ee2f17ed1..32a8320127370 100644 --- a/libs/community/langchain_community/embeddings/localai.py +++ b/libs/community/langchain_community/embeddings/localai.py @@ -114,7 +114,7 @@ async def async_embed_with_retry(embeddings: LocalAIEmbeddings, **kwargs: Any) - @_async_retry_decorator(embeddings) async def _async_embed_with_retry(**kwargs: Any) -> Any: - response = await embeddings.client.acreate(**kwargs) + response = await embeddings.async_client.create(**kwargs) return _check_response(response) return await _async_embed_with_retry(**kwargs) @@ -157,7 +157,8 @@ class LocalAIEmbeddings(BaseModel, Embeddings): ) """ - client: Any = None #: :meta private: + client: Any = None #: :meta private: + async_client: Any = None #: :meta private: model: str = "text-embedding-ada-002" deployment: str = model openai_api_version: Optional[str] = None @@ -250,8 +251,8 @@ def validate_environment(cls, values: Dict) -> Dict: } if not values.get("client"): values["client"] = openai.OpenAI(**client_params).embeddings - - # values["client"] = openai.Embedding + if not values.get("async_client"): + values["async_client"] = openai.AsyncOpenAI(**client_params).embeddings except ImportError: raise ImportError( "Could not import openai python package. " diff --git a/libs/community/tests/integration_tests/embeddings/cassettes/test_localai_aembed.yaml b/libs/community/tests/integration_tests/embeddings/cassettes/test_localai_aembed.yaml new file mode 100644 index 0000000000000..7d102eb137cf9 --- /dev/null +++ b/libs/community/tests/integration_tests/embeddings/cassettes/test_localai_aembed.yaml @@ -0,0 +1,163 @@ +interactions: +- request: + body: '{"input": ["foo bar"], "model": "bge-m3", "encoding_format": "base64"}' + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + authorization: + - Bearer foo + connection: + - keep-alive + content-length: + - '70' + content-type: + - application/json + host: + - foo.bar + openai-organization: + - '' + user-agent: + - AsyncOpenAI/Python 1.30.1 + x-stainless-arch: + - x64 + x-stainless-async: + - async:asyncio + x-stainless-lang: + - python + x-stainless-os: + - Linux + x-stainless-package-version: + - 1.30.1 + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.19 + method: POST + uri: https://foo.bar/v1/embeddings + response: + body: + string: !!binary | + H4sIAAAAAAAEAzyXS3IkNwxE79JryUGCIAnqKrPSpzUhx8gTYWs3l/fDpyRtuqrIApiZSKD+3F7/ + vT9/3d9uT333PWbXqQ+33y9/31+/bk+3Xx//fd0ebh88v215v7/en98fbb7vR10vL49n3PVx2+76 + Ks9t2itrP3+/3X+x/OXn/fFzcOPt+ev59vTjz+3++XJ/e/v45ydX7a/WdZ8u++GR302Jaz0vlk6x + MR9izZBuJ9e0OYbtdmZcig5dS8SXtdH3sdXjQraNJrmozc5VX/mytlTP1tjeTzt9tx1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XOOINcn+CtL3RIEKfOyDRuyNWCOclGlTvyK+dNkydLlJy5yc1stnW9dYSKt5SRcl8sPT7z + VbgO1DWDkNCwbIfV4VM0dsVpa2aMcqUwd9BFQaDM6FIgeIkxtb1LQhm5CvHhx43E8EFif3x48orJ + 6XX62e3vbl4+ub4vsprwfTm8Tbv97+78NX+el+dl/phOl3rixcBxWt7n0+3oMi+H43VgXf8AAAD/ + /wMAT2Qek+0yAAA= + headers: + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json + Date: + - Sun, 02 Jun 2024 18:04:14 GMT + Transfer-Encoding: + - chunked + Vary: + - Accept-Encoding + status: + code: 200 + message: OK +version: 1 diff --git a/libs/community/tests/integration_tests/embeddings/test_localai.py b/libs/community/tests/integration_tests/embeddings/test_localai.py index 8b79b3ed24493..3b8880eb4fb54 100644 --- a/libs/community/tests/integration_tests/embeddings/test_localai.py +++ b/libs/community/tests/integration_tests/embeddings/test_localai.py @@ -1,3 +1,5 @@ +import asyncio + import pytest from langchain_community.embeddings import LocalAIEmbeddings @@ -11,3 +13,14 @@ def test_localai_embed() -> None: eqq=llm.embed_query("foo bar") assert len(eqq) > 100 assert eqq[0] != eqq[1] + + +@pytest.mark.requires("openai") +@pytest.mark.vcr +async def test_localai_aembed() -> None: + llm=LocalAIEmbeddings( + openai_api_key="foo", model="bge-m3", + openai_api_base="https://foo.bar/v1") + eqq=await llm.aembed_query("foo bar") + assert len(eqq) > 100 + assert eqq[0] != eqq[1] \ No newline at end of file From 87ab824283f781f6604b247f0ef3040759d46245 Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Mon, 3 Jun 2024 16:03:21 +0300 Subject: [PATCH 06/21] ruff --- .../tests/integration_tests/embeddings/test_localai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/tests/integration_tests/embeddings/test_localai.py b/libs/community/tests/integration_tests/embeddings/test_localai.py index 3b8880eb4fb54..2d2bed81a8c3e 100644 --- a/libs/community/tests/integration_tests/embeddings/test_localai.py +++ b/libs/community/tests/integration_tests/embeddings/test_localai.py @@ -1,9 +1,9 @@ -import asyncio import pytest from langchain_community.embeddings import LocalAIEmbeddings + @pytest.mark.requires("openai") @pytest.mark.vcr def test_localai_embed() -> None: From 3ac510abb41e8d2fae9399ebf7816f2d4d06ebfe Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Fri, 7 Jun 2024 13:17:42 +0300 Subject: [PATCH 07/21] ruff --- .../langchain_community/embeddings/localai.py | 14 +++++++---- .../embeddings/test_localai.py | 25 +++++++++---------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/libs/community/langchain_community/embeddings/localai.py b/libs/community/langchain_community/embeddings/localai.py index 32a8320127370..bfe3bbb794bf0 100644 --- a/libs/community/langchain_community/embeddings/localai.py +++ b/libs/community/langchain_community/embeddings/localai.py @@ -299,12 +299,16 @@ async def _aembedding_func(self, text: str, *, engine: str) -> List[float]: # replace newlines, which can negatively affect performance. text = text.replace("\n", " ") return ( - await async_embed_with_retry( - self, - input=[text], - **self._invocation_params, + ( + await async_embed_with_retry( + self, + input=[text], + **self._invocation_params, + ) ) - ).data[0].embedding + .data[0] + .embedding + ) def embed_documents( self, texts: List[str], chunk_size: Optional[int] = 0 diff --git a/libs/community/tests/integration_tests/embeddings/test_localai.py b/libs/community/tests/integration_tests/embeddings/test_localai.py index 2d2bed81a8c3e..9d97ebd1b34ca 100644 --- a/libs/community/tests/integration_tests/embeddings/test_localai.py +++ b/libs/community/tests/integration_tests/embeddings/test_localai.py @@ -1,4 +1,3 @@ - import pytest from langchain_community.embeddings import LocalAIEmbeddings @@ -7,20 +6,20 @@ @pytest.mark.requires("openai") @pytest.mark.vcr def test_localai_embed() -> None: - llm=LocalAIEmbeddings( - openai_api_key="foo", model="bge-m3", - openai_api_base="https://foo.bar/v1") - eqq=llm.embed_query("foo bar") - assert len(eqq) > 100 - assert eqq[0] != eqq[1] + llm = LocalAIEmbeddings( + openai_api_key="foo", model="bge-m3", openai_api_base="https://foo.bar/v1" + ) + eqq = llm.embed_query("foo bar") + assert len(eqq) > 100 + assert eqq[0] != eqq[1] @pytest.mark.requires("openai") @pytest.mark.vcr async def test_localai_aembed() -> None: - llm=LocalAIEmbeddings( - openai_api_key="foo", model="bge-m3", - openai_api_base="https://foo.bar/v1") - eqq=await llm.aembed_query("foo bar") - assert len(eqq) > 100 - assert eqq[0] != eqq[1] \ No newline at end of file + llm = LocalAIEmbeddings( + openai_api_key="foo", model="bge-m3", openai_api_base="https://foo.bar/v1" + ) + eqq = await llm.aembed_query("foo bar") + assert len(eqq) > 100 + assert eqq[0] != eqq[1] From 5f1c46baa96e7e1b73de544d190eacf6d883d9ca Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Fri, 7 Jun 2024 15:45:37 +0300 Subject: [PATCH 08/21] don't know how to pass type validation --- libs/community/langchain_community/embeddings/localai.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/community/langchain_community/embeddings/localai.py b/libs/community/langchain_community/embeddings/localai.py index bfe3bbb794bf0..dd432655ab78c 100644 --- a/libs/community/langchain_community/embeddings/localai.py +++ b/libs/community/langchain_community/embeddings/localai.py @@ -89,11 +89,13 @@ async def wrapped_f(*args: Any, **kwargs: Any) -> Callable: # https://stackoverflow.com/questions/76469415/getting-embeddings-of-length-1-from-langchain-openaiembeddings -def _check_response(response: dict) -> dict: +def _check_response(response: Any) -> Any: if any(len(d.embedding) == 1 for d in response.data): import openai - raise openai.APIError("LocalAI API returned an empty embedding") + raise openai.APIError( + "LocalAI API returned an empty embedding", None, body=None + ) return response From 087a149f875f85a3e410a27a923ad79ba347aa2c Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Sun, 15 Sep 2024 23:58:55 +0300 Subject: [PATCH 09/21] bring back openai_proxy to LocalAIEmbeddings --- .../langchain_community/embeddings/localai.py | 73 ++++++++++++------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/libs/community/langchain_community/embeddings/localai.py b/libs/community/langchain_community/embeddings/localai.py index dd432655ab78c..27de8c53db0f8 100644 --- a/libs/community/langchain_community/embeddings/localai.py +++ b/libs/community/langchain_community/embeddings/localai.py @@ -140,31 +140,16 @@ class LocalAIEmbeddings(BaseModel, Embeddings): openai_api_key="random-string", openai_api_base="http://localhost:8080" ) - - Specifying proxy: - .. code-block:: python - - from langchain_community.embeddings import LocalAIEmbeddings - import openai - import httpx - openai = LocalAIEmbeddings( - openai_api_key="random-string", - client=openai.OpenAI( - base_url="http://localhost:8080", - http_client=openai.DefaultHttpxClient( - proxies="http://localhost:8899", - transport=httpx.HTTPTransport(local_address="0.0.0.0"), - ), - api_key="random-string").embeddings - ) """ - client: Any = None #: :meta private: - async_client: Any = None #: :meta private: + client: Any = None #: :meta private: + async_client: Any = None #: :meta private: model: str = "text-embedding-ada-002" deployment: str = model openai_api_version: Optional[str] = None openai_api_base: Optional[str] = None + # to support explicit proxy for LocalAI + openai_proxy: Optional[str] = None embedding_ctx_length: int = 8191 """The maximum number of tokens to embed at once.""" openai_api_key: Optional[str] = None @@ -224,7 +209,12 @@ def validate_environment(cls, values: Dict) -> Dict: "OPENAI_API_BASE", default="", ) - + values["openai_proxy"] = get_from_dict_or_env( + values, + "openai_proxy", + "OPENAI_PROXY", + default="", + ) default_api_version = "" values["openai_api_version"] = get_from_dict_or_env( values, @@ -238,6 +228,14 @@ def validate_environment(cls, values: Dict) -> Dict: "OPENAI_ORGANIZATION", default="", ) + if values.get("openai_proxy") and ( + values.get("client") or values.get("async_client") + ): + raise ValueError( + "Cannot specify 'openai_proxy' if one of " + "'client'/'async_client' is already specified. Received:\n" + f"{values.get('openai_proxy')=}" + ) try: import openai @@ -247,14 +245,39 @@ def validate_environment(cls, values: Dict) -> Dict: "base_url": values["openai_api_base"], "timeout": values["request_timeout"], "max_retries": values["max_retries"], - # "default_headers": values["default_headers"], - # "default_query": values["default_query"], - # "http_client": values["http_client"], } if not values.get("client"): - values["client"] = openai.OpenAI(**client_params).embeddings + sync_specific = {} + if values.get("openai_proxy"): + try: + import httpx + except ImportError as e: + raise ImportError( + "Could not import httpx python package. " + "Please install it with `pip install httpx`." + ) from e + sync_specific["http_client"] = httpx.Client( + proxy=values.get("openai_proxy") + ) + values["client"] = openai.OpenAI( + **client_params, **sync_specific + ).embeddings if not values.get("async_client"): - values["async_client"] = openai.AsyncOpenAI(**client_params).embeddings + async_specific = {} + if values.get("openai_proxy"): + try: + import httpx + except ImportError as e: + raise ImportError( + "Could not import httpx python package. " + "Please install it with `pip install httpx`." + ) from e + async_specific["http_client"] = httpx.AsyncClient( + proxy=values.get("openai_proxy") + ) + values["async_client"] = openai.AsyncOpenAI( + **client_params, **async_specific, **sync_specific + ).embeddings except ImportError: raise ImportError( "Could not import openai python package. " From cfe05fca2d22bf7762d021a88d9f9003eda2de1b Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Mon, 16 Sep 2024 00:00:10 +0300 Subject: [PATCH 10/21] damn --- libs/community/langchain_community/embeddings/localai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/langchain_community/embeddings/localai.py b/libs/community/langchain_community/embeddings/localai.py index 27de8c53db0f8..b54023bb09328 100644 --- a/libs/community/langchain_community/embeddings/localai.py +++ b/libs/community/langchain_community/embeddings/localai.py @@ -276,7 +276,7 @@ def validate_environment(cls, values: Dict) -> Dict: proxy=values.get("openai_proxy") ) values["async_client"] = openai.AsyncOpenAI( - **client_params, **async_specific, **sync_specific + **client_params, **async_specific ).embeddings except ImportError: raise ImportError( From be81f2ae5c4bad41d12ec956cc0d4a1b2d6a4537 Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Mon, 16 Sep 2024 00:01:23 +0300 Subject: [PATCH 11/21] wipe --- libs/community/langchain_community/embeddings/localai.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libs/community/langchain_community/embeddings/localai.py b/libs/community/langchain_community/embeddings/localai.py index b54023bb09328..c8eb9bd3e87bc 100644 --- a/libs/community/langchain_community/embeddings/localai.py +++ b/libs/community/langchain_community/embeddings/localai.py @@ -289,12 +289,6 @@ def validate_environment(cls, values: Dict) -> Dict: def _invocation_params(self) -> Dict: openai_args = { "model": self.model, - # "request_timeout": self.request_timeout, - # "headers": self.headers, - # "api_key": self.openai_api_key, - # "organization": self.openai_organization, - # "api_base": self.openai_api_base, - # "api_version": self.openai_api_version, **self.model_kwargs, } return openai_args From 7a65f52d340403efd7a520fd90390c7b998474a5 Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Fri, 20 Sep 2024 18:37:58 +0300 Subject: [PATCH 12/21] unit test for LocalAI client&proxy setup --- .../unit_tests/embeddings/test_localai.py | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 libs/community/tests/unit_tests/embeddings/test_localai.py diff --git a/libs/community/tests/unit_tests/embeddings/test_localai.py b/libs/community/tests/unit_tests/embeddings/test_localai.py new file mode 100644 index 0000000000000..94cfba95df3cc --- /dev/null +++ b/libs/community/tests/unit_tests/embeddings/test_localai.py @@ -0,0 +1,54 @@ +import pytest + +from langchain_community.embeddings import LocalAIEmbeddings + + +@pytest.mark.requires("openai") +def test_localai_invalid_model_kwargs() -> None: + with pytest.raises(ValueError): + LocalAIEmbeddings(model_kwargs={"model": "foo"}) + + +@pytest.mark.requires("openai") +def test_localai_incorrect_field() -> None: + with pytest.warns(match="not default parameter"): + llm = LocalAIEmbeddings(foo="bar", openai_api_key="foo") # type: ignore[call-arg] + assert llm.model_kwargs == {"foo": "bar"} + +@pytest.mark.requires("openai") +def test_localai_base_url() -> None: + llm = LocalAIEmbeddings(openai_api_key="random-string", + openai_api_base="http://localhost:8080") + assert llm.openai_api_base == "http://localhost:8080" + +@pytest.mark.requires("openai") +def test_localai_client() -> None: + import openai + llm = LocalAIEmbeddings(openai_api_key="random-string", + openai_api_base="http://localhost:8080", + client= (myclient:=openai.OpenAI(api_key="foo")), + async_client= (myasync:=openai.AsyncClient(api_key="foo")) ) + assert llm.openai_api_base == "http://localhost:8080" + assert llm.client == myclient + assert llm.async_client == myasync + +def test_localai_proxy() -> None: + import openai + llm = LocalAIEmbeddings(openai_api_key="random-string", + openai_api_base="http://localhost:8080", + openai_proxy = "http://localhost:6666") + assert llm.openai_api_base == "http://localhost:8080" + assert llm.openai_proxy == "http://localhost:6666" + with pytest.raises(ValueError): + LocalAIEmbeddings(openai_api_key="random-string", + openai_api_base="http://localhost:8080", + client=openai.OpenAI(api_key="foo"), + openai_proxy="http://localhost:6666") + with pytest.raises(ValueError): + LocalAIEmbeddings(openai_api_key="random-string", + openai_api_base="http://localhost:8080", + async_client=openai.AsyncClient(api_key="foo"), + openai_proxy="http://localhost:6666") + + + From 08ec3340c4671935805a3b47950ce1a67ccb05d0 Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Fri, 20 Sep 2024 18:45:44 +0300 Subject: [PATCH 13/21] lint --- .../unit_tests/embeddings/test_localai.py | 51 +++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/libs/community/tests/unit_tests/embeddings/test_localai.py b/libs/community/tests/unit_tests/embeddings/test_localai.py index 94cfba95df3cc..ba1c87216b6e1 100644 --- a/libs/community/tests/unit_tests/embeddings/test_localai.py +++ b/libs/community/tests/unit_tests/embeddings/test_localai.py @@ -15,40 +15,51 @@ def test_localai_incorrect_field() -> None: llm = LocalAIEmbeddings(foo="bar", openai_api_key="foo") # type: ignore[call-arg] assert llm.model_kwargs == {"foo": "bar"} + @pytest.mark.requires("openai") def test_localai_base_url() -> None: - llm = LocalAIEmbeddings(openai_api_key="random-string", - openai_api_base="http://localhost:8080") + llm = LocalAIEmbeddings( + openai_api_key="random-string", openai_api_base="http://localhost:8080" + ) assert llm.openai_api_base == "http://localhost:8080" + @pytest.mark.requires("openai") def test_localai_client() -> None: import openai - llm = LocalAIEmbeddings(openai_api_key="random-string", - openai_api_base="http://localhost:8080", - client= (myclient:=openai.OpenAI(api_key="foo")), - async_client= (myasync:=openai.AsyncClient(api_key="foo")) ) + + llm = LocalAIEmbeddings( + openai_api_key="random-string", + openai_api_base="http://localhost:8080", + client=(myclient := openai.OpenAI(api_key="foo")), + async_client=(myasync := openai.AsyncClient(api_key="foo")), + ) assert llm.openai_api_base == "http://localhost:8080" assert llm.client == myclient assert llm.async_client == myasync + def test_localai_proxy() -> None: import openai - llm = LocalAIEmbeddings(openai_api_key="random-string", - openai_api_base="http://localhost:8080", - openai_proxy = "http://localhost:6666") + + llm = LocalAIEmbeddings( + openai_api_key="random-string", + openai_api_base="http://localhost:8080", + openai_proxy="http://localhost:6666", + ) assert llm.openai_api_base == "http://localhost:8080" assert llm.openai_proxy == "http://localhost:6666" with pytest.raises(ValueError): - LocalAIEmbeddings(openai_api_key="random-string", - openai_api_base="http://localhost:8080", - client=openai.OpenAI(api_key="foo"), - openai_proxy="http://localhost:6666") + LocalAIEmbeddings( + openai_api_key="random-string", + openai_api_base="http://localhost:8080", + client=openai.OpenAI(api_key="foo"), + openai_proxy="http://localhost:6666", + ) with pytest.raises(ValueError): - LocalAIEmbeddings(openai_api_key="random-string", - openai_api_base="http://localhost:8080", - async_client=openai.AsyncClient(api_key="foo"), - openai_proxy="http://localhost:6666") - - - + LocalAIEmbeddings( + openai_api_key="random-string", + openai_api_base="http://localhost:8080", + async_client=openai.AsyncClient(api_key="foo"), + openai_proxy="http://localhost:6666", + ) From 18536797439d43bbbdc8daee2a0178db8fd581cb Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Fri, 20 Sep 2024 23:34:56 +0300 Subject: [PATCH 14/21] adding proxy integration tests with vcr cassettes --- .../cassettes/test_localai_proxy_aembed.yaml | 53 +++++++++++++++++++ .../cassettes/test_localai_proxy_embed.yaml | 53 +++++++++++++++++++ .../embeddings/test_localai.py | 28 ++++++++++ 3 files changed, 134 insertions(+) create mode 100644 libs/community/tests/integration_tests/embeddings/cassettes/test_localai_proxy_aembed.yaml create mode 100644 libs/community/tests/integration_tests/embeddings/cassettes/test_localai_proxy_embed.yaml diff --git a/libs/community/tests/integration_tests/embeddings/cassettes/test_localai_proxy_aembed.yaml b/libs/community/tests/integration_tests/embeddings/cassettes/test_localai_proxy_aembed.yaml new file mode 100644 index 0000000000000..28e9bff214bec --- /dev/null +++ b/libs/community/tests/integration_tests/embeddings/cassettes/test_localai_proxy_aembed.yaml @@ -0,0 +1,53 @@ +interactions: +- request: + body: '{"input": ["foo bar"], "model": "bert-cpp-minilm-v6", "encoding_format": + "base64"}' + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + authorization: + - Bearer foo + connection: + - keep-alive + content-length: + - '82' + content-type: + - application/json + host: + - host.docker.internal:9090 + openai-organization: + - '' + user-agent: + - AsyncOpenAI/Python 1.45.0 + x-stainless-arch: + - x64 + x-stainless-async: + - async:asyncio + x-stainless-lang: + - python + x-stainless-os: + - Linux + x-stainless-package-version: + - 1.45.0 + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.12.3 + method: POST + uri: http://host.docker.internal:9090/v1/embeddings + response: + body: + string: '{"created":1726864341,"object":"list","id":"deda476d-3bfc-45fb-a19b-1f20bc9ad30b","model":"bert-cpp-minilm-v6","data":[{"embedding":[-0.010992386,-0.03549562,0.018737776,-0.019781824,-0.09459962,0.0098638255,0.1106663,-0.0017531032,0.028909575,-0.0626337,0.01696725,-0.015336791,-0.0129836695,-0.06703008,0.013242183,0.04178338,0.01814328,-0.039132655,-0.03918885,-0.028863922,-0.04933069,0.07945776,-0.052886207,0.008833937,-0.0767572,0.051378693,-0.05252732,-0.0045520235,0.02301586,-0.07795919,0.07836584,0.106179416,0.037719745,-0.01060789,-0.042230617,-0.05108326,0.061738104,0.049142104,0.09697526,0.048138138,-0.049587876,-0.026666822,-0.008235938,-0.004523452,-0.016184658,0.052324392,-0.03460722,0.008953229,0.042250782,0.0016407531,0.01860321,-0.04320511,0.014449185,0.053518053,0.06468848,0.04338993,0.018743465,0.017313244,0.04562465,0.016839467,-0.008387781,0.037793268,-0.01710513,-0.042774048,0.09855642,-0.020444328,-0.047672477,0.093603656,0.004692008,0.027804578,0.038890544,-0.0066055832,0.0074837157,0.08626364,0.068263195,-0.06440563,0.017618092,-0.034942295,0.11782754,-0.00078116776,-0.09244731,-0.009669715,-0.072590634,-0.082383096,0.020041237,0.013121715,-0.0018002193,-0.010319777,0.010160952,0.061030913,-0.12667504,-0.052647457,0.00206918,0.0081874505,0.04179256,0.013751449,0.019433828,-0.024446478,-0.037253175,0.21245079,0.06694145,0.15932757,0.044739258,-0.036858078,0.023283307,-0.04305377,0.035766043,0.075765565,0.049929354,-0.03899172,-0.0014016735,-0.021113595,-0.017426746,-0.0675897,-0.022710923,0.03498959,0.07375316,0.001532535,-0.027202422,-0.09463035,-0.053807955,0.103622265,-0.008812674,0.086671524,-0.108532526,-0.03655349,-0.010438359,-3.4067292e-33,-0.020161318,-0.09071882,-0.033199534,0.0012113027,0.062799856,-0.09009555,-0.053208504,0.028269041,-0.03233055,0.052911658,-0.004343782,-0.05519837,-0.06613678,-0.07078895,0.1430808,-0.009443969,-0.04124667,0.04434897,-0.057148404,-0.024886468,-0.020205468,-0.020207124,0.03288797,0.017990129,0.03338311,-0.044424217,0.013198827,-0.014092881,0.05266774,0.035726495,-0.01012384,0.0027516189,0.06656579,0.00039096797,-0.034294724,-0.0180108,-0.019445987,-0.00020122722,-0.03503971,0.002529173,-0.021500085,-0.019401014,-0.04415041,0.020503446,-0.008118465,0.01654083,-0.028257431,-0.0046991482,-0.058289014,0.04461023,0.011568976,0.029990848,-0.062414378,0.05308095,0.002457138,-0.034827027,-0.013951771,0.042915013,0.05264154,-0.048492815,0.040068176,0.08165961,-0.022619909,0.09063727,-0.050600637,-0.0005098602,0.076447666,-0.008752696,0.06748363,-0.03471805,-0.062175352,0.011858924,-0.031483777,0.009002488,-0.030024864,0.0017439668,-0.008490022,-0.013870139,-0.03592444,-0.023589272,0.04241159,0.010421106,-0.015617996,0.061739683,-0.025365287,-0.037294053,0.10580097,-0.114110954,-0.07608144,-0.082127444,-0.16973266,-0.009299494,0.01404157,-0.049723916,0.0338938,2.9320429e-33,0.0871552,-0.045085877,0.0108446255,-0.018055182,-0.016635794,-0.040556904,-0.030527832,-0.0019158109,-0.08639412,-0.03539183,-0.05564409,-0.045331225,0.039546337,-0.012525965,0.057619806,0.03662369,0.053309884,-0.013806599,-0.07069193,0.01598836,0.010245769,-0.101355135,0.04796546,-0.013990657,-0.06963044,0.041853867,0.10655551,0.002725985,-0.04538322,-0.047761228,0.016181143,-0.022188326,0.01978193,-0.024148062,-0.011306033,0.036089756,0.011296482,0.0016116656,-0.028187606,-0.099616684,0.09923823,0.082863405,-0.016481059,0.07000222,-0.015265777,0.037124503,-0.01609281,-0.032083355,0.054494247,-0.002363291,0.02848842,-0.010819923,0.00013777956,-0.0045429682,-0.029510072,-0.05110118,-0.042344216,0.03287905,-0.06811587,-0.029157013,-0.07444023,0.0077999933,-0.029623162,0.012028628,-0.040302727,-0.045357127,-0.043638855,0.052165817,-0.043859657,0.008499412,0.023691256,0.0030422518,0.011715966,0.06540763,-0.094976895,-0.016297512,0.05058357,-0.0014306409,-0.025144305,0.05034372,0.033044204,-0.082392745,0.05965251,0.028674077,0.005637143,-0.024449574,0.00854059,0.087944634,-0.016800692,0.048313204,0.027357321,0.053084243,-0.050009932,-0.037500665,-0.03884432,-1.4420178e-8,-0.02305306,0.002053573,-0.017934084,0.06456365,0.014417454,0.08451174,-0.021397848,-0.060855243,-0.01854651,-0.013851016,-0.027564973,-0.017328622,-0.06398853,0.044354245,0.012049138,-0.06558295,-0.049685594,-0.0052492027,0.012335376,-0.032616712,-0.10193803,0.061984632,0.037276693,-0.02438224,-0.07514694,-0.012535868,-0.021958109,0.030562205,0.030931996,-0.015919918,0.08160673,0.21002313,-0.033921503,-0.048431955,0.00013464018,-0.014892002,-0.01463541,-0.009037973,-0.025499407,0.1094333,-0.009823529,-0.038237467,-0.026453257,-0.07398165,0.012102728,0.043241173,0.058243975,0.04208147,-0.009952821,0.014732737,0.015060534,0.048055876,0.047981013,0.04733172,0.04427347,0.09314033,-0.06828399,0.030224344,-0.008520464,-0.010505093,0.09225868,0.027643135,0.051353388,0.070093356],"index":0,"object":"embedding"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}' + headers: + Content-Length: + - '4953' + Content-Type: + - application/json + Date: + - Fri, 20 Sep 2024 20:32:20 GMT + status: + code: 200 + message: OK +version: 1 diff --git a/libs/community/tests/integration_tests/embeddings/cassettes/test_localai_proxy_embed.yaml b/libs/community/tests/integration_tests/embeddings/cassettes/test_localai_proxy_embed.yaml new file mode 100644 index 0000000000000..1a9796d148a5b --- /dev/null +++ b/libs/community/tests/integration_tests/embeddings/cassettes/test_localai_proxy_embed.yaml @@ -0,0 +1,53 @@ +interactions: +- request: + body: '{"input": ["foo bar"], "model": "bert-cpp-minilm-v6", "encoding_format": + "base64"}' + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + authorization: + - Bearer foo + connection: + - keep-alive + content-length: + - '82' + content-type: + - application/json + host: + - host.docker.internal:9090 + openai-organization: + - '' + user-agent: + - OpenAI/Python 1.45.0 + x-stainless-arch: + - x64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - Linux + x-stainless-package-version: + - 1.45.0 + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.12.3 + method: POST + uri: http://host.docker.internal:9090/v1/embeddings + response: + body: + string: '{"created":1726864199,"object":"list","id":"186fed3b-cdc8-4629-be83-8d286a0869e6","model":"bert-cpp-minilm-v6","data":[{"embedding":[-0.010992386,-0.03549562,0.018737776,-0.019781824,-0.09459962,0.0098638255,0.1106663,-0.0017531032,0.028909575,-0.0626337,0.01696725,-0.015336791,-0.0129836695,-0.06703008,0.013242183,0.04178338,0.01814328,-0.039132655,-0.03918885,-0.028863922,-0.04933069,0.07945776,-0.052886207,0.008833937,-0.0767572,0.051378693,-0.05252732,-0.0045520235,0.02301586,-0.07795919,0.07836584,0.106179416,0.037719745,-0.01060789,-0.042230617,-0.05108326,0.061738104,0.049142104,0.09697526,0.048138138,-0.049587876,-0.026666822,-0.008235938,-0.004523452,-0.016184658,0.052324392,-0.03460722,0.008953229,0.042250782,0.0016407531,0.01860321,-0.04320511,0.014449185,0.053518053,0.06468848,0.04338993,0.018743465,0.017313244,0.04562465,0.016839467,-0.008387781,0.037793268,-0.01710513,-0.042774048,0.09855642,-0.020444328,-0.047672477,0.093603656,0.004692008,0.027804578,0.038890544,-0.0066055832,0.0074837157,0.08626364,0.068263195,-0.06440563,0.017618092,-0.034942295,0.11782754,-0.00078116776,-0.09244731,-0.009669715,-0.072590634,-0.082383096,0.020041237,0.013121715,-0.0018002193,-0.010319777,0.010160952,0.061030913,-0.12667504,-0.052647457,0.00206918,0.0081874505,0.04179256,0.013751449,0.019433828,-0.024446478,-0.037253175,0.21245079,0.06694145,0.15932757,0.044739258,-0.036858078,0.023283307,-0.04305377,0.035766043,0.075765565,0.049929354,-0.03899172,-0.0014016735,-0.021113595,-0.017426746,-0.0675897,-0.022710923,0.03498959,0.07375316,0.001532535,-0.027202422,-0.09463035,-0.053807955,0.103622265,-0.008812674,0.086671524,-0.108532526,-0.03655349,-0.010438359,-3.4067292e-33,-0.020161318,-0.09071882,-0.033199534,0.0012113027,0.062799856,-0.09009555,-0.053208504,0.028269041,-0.03233055,0.052911658,-0.004343782,-0.05519837,-0.06613678,-0.07078895,0.1430808,-0.009443969,-0.04124667,0.04434897,-0.057148404,-0.024886468,-0.020205468,-0.020207124,0.03288797,0.017990129,0.03338311,-0.044424217,0.013198827,-0.014092881,0.05266774,0.035726495,-0.01012384,0.0027516189,0.06656579,0.00039096797,-0.034294724,-0.0180108,-0.019445987,-0.00020122722,-0.03503971,0.002529173,-0.021500085,-0.019401014,-0.04415041,0.020503446,-0.008118465,0.01654083,-0.028257431,-0.0046991482,-0.058289014,0.04461023,0.011568976,0.029990848,-0.062414378,0.05308095,0.002457138,-0.034827027,-0.013951771,0.042915013,0.05264154,-0.048492815,0.040068176,0.08165961,-0.022619909,0.09063727,-0.050600637,-0.0005098602,0.076447666,-0.008752696,0.06748363,-0.03471805,-0.062175352,0.011858924,-0.031483777,0.009002488,-0.030024864,0.0017439668,-0.008490022,-0.013870139,-0.03592444,-0.023589272,0.04241159,0.010421106,-0.015617996,0.061739683,-0.025365287,-0.037294053,0.10580097,-0.114110954,-0.07608144,-0.082127444,-0.16973266,-0.009299494,0.01404157,-0.049723916,0.0338938,2.9320429e-33,0.0871552,-0.045085877,0.0108446255,-0.018055182,-0.016635794,-0.040556904,-0.030527832,-0.0019158109,-0.08639412,-0.03539183,-0.05564409,-0.045331225,0.039546337,-0.012525965,0.057619806,0.03662369,0.053309884,-0.013806599,-0.07069193,0.01598836,0.010245769,-0.101355135,0.04796546,-0.013990657,-0.06963044,0.041853867,0.10655551,0.002725985,-0.04538322,-0.047761228,0.016181143,-0.022188326,0.01978193,-0.024148062,-0.011306033,0.036089756,0.011296482,0.0016116656,-0.028187606,-0.099616684,0.09923823,0.082863405,-0.016481059,0.07000222,-0.015265777,0.037124503,-0.01609281,-0.032083355,0.054494247,-0.002363291,0.02848842,-0.010819923,0.00013777956,-0.0045429682,-0.029510072,-0.05110118,-0.042344216,0.03287905,-0.06811587,-0.029157013,-0.07444023,0.0077999933,-0.029623162,0.012028628,-0.040302727,-0.045357127,-0.043638855,0.052165817,-0.043859657,0.008499412,0.023691256,0.0030422518,0.011715966,0.06540763,-0.094976895,-0.016297512,0.05058357,-0.0014306409,-0.025144305,0.05034372,0.033044204,-0.082392745,0.05965251,0.028674077,0.005637143,-0.024449574,0.00854059,0.087944634,-0.016800692,0.048313204,0.027357321,0.053084243,-0.050009932,-0.037500665,-0.03884432,-1.4420178e-8,-0.02305306,0.002053573,-0.017934084,0.06456365,0.014417454,0.08451174,-0.021397848,-0.060855243,-0.01854651,-0.013851016,-0.027564973,-0.017328622,-0.06398853,0.044354245,0.012049138,-0.06558295,-0.049685594,-0.0052492027,0.012335376,-0.032616712,-0.10193803,0.061984632,0.037276693,-0.02438224,-0.07514694,-0.012535868,-0.021958109,0.030562205,0.030931996,-0.015919918,0.08160673,0.21002313,-0.033921503,-0.048431955,0.00013464018,-0.014892002,-0.01463541,-0.009037973,-0.025499407,0.1094333,-0.009823529,-0.038237467,-0.026453257,-0.07398165,0.012102728,0.043241173,0.058243975,0.04208147,-0.009952821,0.014732737,0.015060534,0.048055876,0.047981013,0.04733172,0.04427347,0.09314033,-0.06828399,0.030224344,-0.008520464,-0.010505093,0.09225868,0.027643135,0.051353388,0.070093356],"index":0,"object":"embedding"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}' + headers: + Content-Length: + - '4953' + Content-Type: + - application/json + Date: + - Fri, 20 Sep 2024 20:29:58 GMT + status: + code: 200 + message: OK +version: 1 diff --git a/libs/community/tests/integration_tests/embeddings/test_localai.py b/libs/community/tests/integration_tests/embeddings/test_localai.py index 9d97ebd1b34ca..02af7c7520e5b 100644 --- a/libs/community/tests/integration_tests/embeddings/test_localai.py +++ b/libs/community/tests/integration_tests/embeddings/test_localai.py @@ -23,3 +23,31 @@ async def test_localai_aembed() -> None: eqq = await llm.aembed_query("foo bar") assert len(eqq) > 100 assert eqq[0] != eqq[1] + + +@pytest.mark.requires("openai") +@pytest.mark.vcr +def test_localai_proxy_embed() -> None: + llm = LocalAIEmbeddings( + openai_api_key="foo", + model="bert-cpp-minilm-v6", + openai_api_base="http://host.docker.internal:9090/v1", + openai_proxy="http://127.0.0.1:8080", + ) + eqq = llm.embed_query("foo bar") + assert len(eqq) > 100 + assert eqq[0] != eqq[1] + + +@pytest.mark.requires("openai") +@pytest.mark.vcr +async def test_localai_proxy_aembed() -> None: + llm = LocalAIEmbeddings( + openai_api_key="foo", + model="bert-cpp-minilm-v6", + openai_api_base="http://host.docker.internal:9090/v1", + openai_proxy="http://127.0.0.1:8080", + ) + eqq = await llm.aembed_query("foo bar") + assert len(eqq) > 100 + assert eqq[0] != eqq[1] From b87f6592343ad5a506e0e6949a785a0117fb7d2a Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Fri, 20 Sep 2024 23:45:38 +0300 Subject: [PATCH 15/21] unit_tests/embeddings/test_localai.py::test_localai_proxy - ModuleNotFoundError: No module named 'openai' --- libs/community/tests/unit_tests/embeddings/test_localai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/tests/unit_tests/embeddings/test_localai.py b/libs/community/tests/unit_tests/embeddings/test_localai.py index ba1c87216b6e1..e644417f2e779 100644 --- a/libs/community/tests/unit_tests/embeddings/test_localai.py +++ b/libs/community/tests/unit_tests/embeddings/test_localai.py @@ -38,7 +38,7 @@ def test_localai_client() -> None: assert llm.client == myclient assert llm.async_client == myasync - +@pytest.mark.requires("openai") def test_localai_proxy() -> None: import openai From f2d5ccf2e0f807d95795c3cc1c99308ddc607222 Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Fri, 20 Sep 2024 23:48:04 +0300 Subject: [PATCH 16/21] format --- libs/community/tests/unit_tests/embeddings/test_localai.py | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/community/tests/unit_tests/embeddings/test_localai.py b/libs/community/tests/unit_tests/embeddings/test_localai.py index e644417f2e779..d142d33e1ea25 100644 --- a/libs/community/tests/unit_tests/embeddings/test_localai.py +++ b/libs/community/tests/unit_tests/embeddings/test_localai.py @@ -38,6 +38,7 @@ def test_localai_client() -> None: assert llm.client == myclient assert llm.async_client == myasync + @pytest.mark.requires("openai") def test_localai_proxy() -> None: import openai From 124ccdf2cdda87dbe9cda290596682361d4a874a Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Sat, 21 Sep 2024 00:04:33 +0300 Subject: [PATCH 17/21] Bump openai for test. Here's the key question: 0.x or 1.x? --- libs/community/extended_testing_deps.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/extended_testing_deps.txt b/libs/community/extended_testing_deps.txt index d9879fd6aa07c..2ad68a3f427bd 100644 --- a/libs/community/extended_testing_deps.txt +++ b/libs/community/extended_testing_deps.txt @@ -49,7 +49,7 @@ newspaper3k>=0.2.8,<0.3 numexpr>=2.8.6,<3 nvidia-riva-client>=2.14.0,<3 oci>=2.128.0,<3 -openai<2 +openai>=1.30.0,<2 openapi-pydantic>=0.3.2,<0.4 oracle-ads>=2.9.1,<3 oracledb>=2.2.0,<3 From 50db4736c959cc33a277eea7291586ffabfd6a58 Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Sat, 21 Sep 2024 00:14:26 +0300 Subject: [PATCH 18/21] Bump "httpx=^0.27.0" for test as in langchain_openai --- libs/community/extended_testing_deps.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/extended_testing_deps.txt b/libs/community/extended_testing_deps.txt index 2ad68a3f427bd..ac7d31fc7ae58 100644 --- a/libs/community/extended_testing_deps.txt +++ b/libs/community/extended_testing_deps.txt @@ -32,7 +32,7 @@ gradientai>=1.4.0,<2 hdbcli>=2.19.21,<3 hologres-vector==0.0.6 html2text>=2020.1.16 -httpx>=0.24.1,<0.25 +httpx=^0.27.0 httpx-sse>=0.4.0,<0.5 jinja2>=3,<4 jq>=1.4.1,<2 From d0911fffbbccb86a587bfb3dcc2cbd490bbb6ddd Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Sat, 21 Sep 2024 00:28:03 +0300 Subject: [PATCH 19/21] Bump "httpx>=0.27.0" for test as in langchain_openai --- libs/community/extended_testing_deps.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/extended_testing_deps.txt b/libs/community/extended_testing_deps.txt index ac7d31fc7ae58..3c33e39903bc0 100644 --- a/libs/community/extended_testing_deps.txt +++ b/libs/community/extended_testing_deps.txt @@ -32,7 +32,7 @@ gradientai>=1.4.0,<2 hdbcli>=2.19.21,<3 hologres-vector==0.0.6 html2text>=2020.1.16 -httpx=^0.27.0 +httpx>=0.27.0 httpx-sse>=0.4.0,<0.5 jinja2>=3,<4 jq>=1.4.1,<2 From aaa05f9f24ab942621710966bf4d5cee0e2a30e4 Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Sat, 21 Sep 2024 01:07:07 +0300 Subject: [PATCH 20/21] keep up with old httpx --- libs/community/extended_testing_deps.txt | 4 ++-- .../langchain_community/embeddings/localai.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/community/extended_testing_deps.txt b/libs/community/extended_testing_deps.txt index 3c33e39903bc0..3af2416245b18 100644 --- a/libs/community/extended_testing_deps.txt +++ b/libs/community/extended_testing_deps.txt @@ -22,7 +22,7 @@ esprima>=4.0.1,<5 faiss-cpu>=1,<2 feedparser>=6.0.10,<7 fireworks-ai>=0.9.0,<0.10 -friendli-client>=1.2.4,<2 +friendli-client>=1.2.4 geopandas>=0.13.1 gitpython>=3.1.32,<4 gliner>=0.2.7 @@ -32,7 +32,7 @@ gradientai>=1.4.0,<2 hdbcli>=2.19.21,<3 hologres-vector==0.0.6 html2text>=2020.1.16 -httpx>=0.27.0 +httpx>=0.24.1,<0.25 httpx-sse>=0.4.0,<0.5 jinja2>=3,<4 jq>=1.4.1,<2 diff --git a/libs/community/langchain_community/embeddings/localai.py b/libs/community/langchain_community/embeddings/localai.py index c8eb9bd3e87bc..31e9cb30d15ab 100644 --- a/libs/community/langchain_community/embeddings/localai.py +++ b/libs/community/langchain_community/embeddings/localai.py @@ -257,7 +257,10 @@ def validate_environment(cls, values: Dict) -> Dict: "Please install it with `pip install httpx`." ) from e sync_specific["http_client"] = httpx.Client( - proxy=values.get("openai_proxy") + # httpx>=0.26 like in langchain-openai + # proxy=values.get("openai_proxy") + # perhaps it might be more restrictive + proxies={"all://*": values.get("openai_proxy")} ) values["client"] = openai.OpenAI( **client_params, **sync_specific @@ -273,7 +276,10 @@ def validate_environment(cls, values: Dict) -> Dict: "Please install it with `pip install httpx`." ) from e async_specific["http_client"] = httpx.AsyncClient( - proxy=values.get("openai_proxy") + # httpx>=0.26 like in langchain-openai + # proxy=values.get("openai_proxy") + # perhaps it might be more restrictive + proxies={"all://*": values.get("openai_proxy")} ) values["async_client"] = openai.AsyncOpenAI( **client_params, **async_specific From ef384192af724215a96981e4826d551e795bd91b Mon Sep 17 00:00:00 2001 From: mikhail-khludnev Date: Sat, 21 Sep 2024 01:08:14 +0300 Subject: [PATCH 21/21] friendlyback --- libs/community/extended_testing_deps.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/extended_testing_deps.txt b/libs/community/extended_testing_deps.txt index 3af2416245b18..2ad68a3f427bd 100644 --- a/libs/community/extended_testing_deps.txt +++ b/libs/community/extended_testing_deps.txt @@ -22,7 +22,7 @@ esprima>=4.0.1,<5 faiss-cpu>=1,<2 feedparser>=6.0.10,<7 fireworks-ai>=0.9.0,<0.10 -friendli-client>=1.2.4 +friendli-client>=1.2.4,<2 geopandas>=0.13.1 gitpython>=3.1.32,<4 gliner>=0.2.7