Skip to content

Commit f5237e0

Browse files
leoguillaumeleoguillaume
andauthored
hotfix: tei client (#287)
Co-authored-by: leoguillaume <leo.guillaume@modernisation.gouv.fr>
1 parent eec5076 commit f5237e0

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

app/clients/model/_teimodelclient.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import Any, Dict, Optional
33
from urllib.parse import urljoin
44

5-
from fastapi import Request
65
import httpx
76
from openai import AsyncOpenAI
87
import requests
@@ -63,25 +62,25 @@ def __init__(self, model: str, api_url: str, api_key: str, timeout: int, *args,
6362
else:
6463
self.vector_size = None
6564

66-
def _format_request(self, request: Request, json: Optional[dict] = None, files: Optional[dict] = None, data: Optional[dict] = None) -> dict:
65+
def _format_request(self, json: Optional[dict] = None, files: Optional[dict] = None, data: Optional[dict] = None) -> dict:
6766
"""
6867
Format a request to a client model. Overridden base class method to support TEI Reranking.
6968
7069
Args:
71-
endpoint(str): The endpoint to forward the request to.
7270
json(dict): The JSON body to use for the request.
7371
files(dict): The files to use for the request.
7472
data(dict): The data to use for the request.
7573
7674
Returns:
7775
tuple: The formatted request composed of the url, headers, json, files and data.
7876
"""
79-
url = urljoin(base=self.api_url, url=self.ENDPOINT_TABLE[request.url.path.removeprefix("/v1")])
77+
# self.endpoint is set by the ModelRouter
78+
url = urljoin(base=self.api_url, url=self.ENDPOINT_TABLE[self.endpoint])
8079
headers = {"Authorization": f"Bearer {self.api_key}"}
8180
if json and "model" in json:
8281
json["model"] = self.model
8382

84-
if request.url.path.endswith(ENDPOINT__RERANK):
83+
if self.endpoint.endswith(ENDPOINT__RERANK):
8584
json = {"query": json["prompt"], "texts": json["input"]}
8685

8786
return url, headers, json, files, data

0 commit comments

Comments
 (0)