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 langchain.llms.base import LLM
|
|
|
|
|
|
|
|
|
|
|
|
class FakeLLM(LLM):
|
|
|
|
"""Fake LLM wrapper for testing purposes."""
|
|
|
|
|
|
|
|
def __init__(self, queries: Optional[Mapping] = None):
|
|
|
|
"""Initialize with optional lookup of queries."""
|
|
|
|
self._queries = queries
|
|
|
|
|
|
|
|
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-10-24 21:51:15 +00:00
|
|
|
if self._queries is not None:
|
|
|
|
return self._queries[prompt]
|
|
|
|
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 {}
|