File size: 525 Bytes
ed4d993
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from difflib import SequenceMatcher
from typing import List, Tuple

from langchain_core.pydantic_v1 import BaseModel

from langchain_community.cross_encoders.base import BaseCrossEncoder


class FakeCrossEncoder(BaseCrossEncoder, BaseModel):
    """Fake cross encoder model."""

    def score(self, text_pairs: List[Tuple[str, str]]) -> List[float]:
        scores = list(
            map(
                lambda pair: SequenceMatcher(None, pair[0], pair[1]).ratio(), text_pairs
            )
        )
        return scores