Skip to content

Commit

Permalink
fix validator in unit test util
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurme committed Sep 10, 2024
1 parent bf4ea0a commit f6093a0
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions libs/partners/mongodb/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
BaseMessage,
)
from langchain_core.outputs import ChatGeneration, ChatResult
from pydantic import validator
from pydantic import model_validator
from pymongo.collection import Collection
from pymongo.results import DeleteResult, InsertManyResult

Expand Down Expand Up @@ -134,15 +134,14 @@ class FakeLLM(LLM):
sequential_responses: Optional[bool] = False
response_index: int = 0

@validator("queries", always=True)
def check_queries_required(
cls, queries: Optional[Mapping], values: Mapping[str, Any]
) -> Optional[Mapping]:
if values.get("sequential_response") and not queries:
@model_validator(mode="before")
@classmethod
def check_queries_required(cls, values: dict) -> dict:
if values.get("sequential_response") and not values.get("queries"):
raise ValueError(
"queries is required when sequential_response is set to True"
)
return queries
return values

def get_num_tokens(self, text: str) -> int:
"""Return number of tokens."""
Expand Down

0 comments on commit f6093a0

Please sign in to comment.