community: Fix OVHcloud 401 Unauthorized on embedding. (#23260)

They are now rejecting with code 401 calls from users with expired or
invalid tokens (while before they were being considered anonymous).
Thus, the authorization header has to be removed when there is no token.

Related to: #23178

---------

Signed-off-by: Joffref <mariusjoffre@gmail.com>
This commit is contained in:
Mathis Joffre
2024-06-24 18:58:32 +02:00
committed by GitHub
parent 4964ba74db
commit 60103fc4a5
4 changed files with 39 additions and 28 deletions

View File

@@ -4,22 +4,28 @@ from langchain_community.embeddings.ovhcloud import OVHCloudEmbeddings
def test_ovhcloud_correct_instantiation() -> None:
llm = OVHCloudEmbeddings(model_name="multilingual-e5-base")
llm = OVHCloudEmbeddings(model_name="multilingual-e5-base", access_token="token")
assert isinstance(llm, OVHCloudEmbeddings)
llm = OVHCloudEmbeddings(
model_name="multilingual-e5-base", region="kepler", access_token="token"
)
assert isinstance(llm, OVHCloudEmbeddings)
def test_ovhcloud_empty_model_name_should_raise_error() -> None:
with pytest.raises(ValueError):
OVHCloudEmbeddings(model_name="")
OVHCloudEmbeddings(model_name="", region="kepler", access_token="token")
def test_ovhcloud_empty_region_should_raise_error() -> None:
with pytest.raises(ValueError):
OVHCloudEmbeddings(model_name="multilingual-e5-base", region="")
OVHCloudEmbeddings(
model_name="multilingual-e5-base", region="", access_token="token"
)
def test_ovhcloud_empty_access_token_should_not_raise_error() -> None:
llm = OVHCloudEmbeddings(
model_name="multilingual-e5-base", region="kepler", access_token=""
)
assert isinstance(llm, OVHCloudEmbeddings)
def test_ovhcloud_empty_access_token_should_raise_error() -> None:
with pytest.raises(ValueError):
OVHCloudEmbeddings(
model_name="multilingual-e5-base", region="kepler", access_token=""
)