feat(model): Support deploy rerank model (#1522)

This commit is contained in:
Fangyin Cheng
2024-05-16 14:50:16 +08:00
committed by GitHub
parent 559affe87d
commit 593e974405
29 changed files with 814 additions and 75 deletions

View File

@@ -1,9 +1,24 @@
"""Interface for embedding models."""
import asyncio
from abc import ABC, abstractmethod
from typing import List
class RerankEmbeddings(ABC):
"""Interface for rerank models."""
@abstractmethod
def predict(self, query: str, candidates: List[str]) -> List[float]:
"""Predict the scores of the candidates."""
async def apredict(self, query: str, candidates: List[str]) -> List[float]:
"""Asynchronously predict the scores of the candidates."""
return await asyncio.get_running_loop().run_in_executor(
None, self.predict, query, candidates
)
class Embeddings(ABC):
"""Interface for embedding models.