langchain/tests/unit_tests/llms/fake_llm.py

31 lines
791 B
Python
Raw Normal View History

2022-10-24 21:51:15 +00:00
"""Fake LLM wrapper for testing purposes."""
2022-11-09 06:17:10 +00:00
from typing import Any, List, Mapping, Optional
2022-10-24 21:51:15 +00:00
from pydantic import BaseModel
2022-10-24 21:51:15 +00:00
from langchain.llms.base import LLM
class FakeLLM(LLM, BaseModel):
2022-10-24 21:51:15 +00:00
"""Fake LLM wrapper for testing purposes."""
queries: Optional[Mapping] = None
@property
def _llm_type(self) -> str:
"""Return type of llm."""
return "fake"
2022-10-24 21:51:15 +00:00
2022-12-15 15:53:32 +00:00
def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
2022-10-25 02:56:26 +00:00
"""First try to lookup in queries, else return 'foo' or 'bar'."""
if self.queries is not None:
return self.queries[prompt]
2022-10-24 21:51:15 +00:00
if stop is None:
return "foo"
else:
return "bar"
2022-11-09 06:17:10 +00:00
@property
def _identifying_params(self) -> Mapping[str, Any]:
return {}