mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-28 06:48:50 +00:00
This PR upgrades langchain-community to pydantic 2.
* Most of this PR was auto-generated using code mods with gritql
(https://github.com/eyurtsev/migrate-pydantic/tree/main)
* Subsequently, some code was fixed manually due to accommodate
differences between pydantic 1 and 2
Breaking Changes:
- Use TEXTEMBED_API_KEY and TEXTEMBEB_API_URL for env variables for text
embed integrations:
cbea780492
Other changes:
- Added pydantic_settings as a required dependency for community. This
may be removed if we have enough time to convert the dependency into an
optional one.
---------
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
19 lines
507 B
Python
19 lines
507 B
Python
from difflib import SequenceMatcher
|
|
from typing import List, Tuple
|
|
|
|
from pydantic 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
|