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
|
|
|
|
2022-12-13 14:46:01 +00:00
|
|
|
from pydantic import BaseModel
|
|
|
|
|
2022-10-24 21:51:15 +00:00
|
|
|
from langchain.llms.base import LLM
|
|
|
|
|
|
|
|
|
2022-12-13 14:46:01 +00:00
|
|
|
class FakeLLM(LLM, BaseModel):
|
2022-10-24 21:51:15 +00:00
|
|
|
"""Fake LLM wrapper for testing purposes."""
|
|
|
|
|
2022-12-13 14:46:01 +00:00
|
|
|
queries: Optional[Mapping] = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _llm_type(self) -> str:
|
|
|
|
"""Return type of llm."""
|
|
|
|
return "fake"
|
2022-10-24 21:51:15 +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'."""
|
2022-12-13 14:46:01 +00:00
|
|
|
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 {}
|