mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-07-19 21:33:31 -04:00
49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
"""Fake LLM wrapper for testing purposes."""
|
|
from typing import Any, List, Mapping, Optional
|
|
|
|
from langchain.callbacks.manager import (
|
|
AsyncCallbackManagerForLLMRun,
|
|
CallbackManagerForLLMRun,
|
|
)
|
|
from langchain.llms.base import LLM
|
|
|
|
|
|
class FakeListLLM(LLM):
|
|
"""Fake LLM wrapper for testing purposes."""
|
|
|
|
responses: List
|
|
i: int = 0
|
|
|
|
@property
|
|
def _llm_type(self) -> str:
|
|
"""Return type of llm."""
|
|
return "fake-list"
|
|
|
|
def _call(
|
|
self,
|
|
prompt: str,
|
|
stop: Optional[List[str]] = None,
|
|
run_manager: Optional[CallbackManagerForLLMRun] = None,
|
|
**kwargs: Any,
|
|
) -> str:
|
|
"""Return next response"""
|
|
response = self.responses[self.i]
|
|
self.i += 1
|
|
return response
|
|
|
|
async def _acall(
|
|
self,
|
|
prompt: str,
|
|
stop: Optional[List[str]] = None,
|
|
run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
|
|
**kwargs: Any,
|
|
) -> str:
|
|
"""Return next response"""
|
|
response = self.responses[self.i]
|
|
self.i += 1
|
|
return response
|
|
|
|
@property
|
|
def _identifying_params(self) -> Mapping[str, Any]:
|
|
return {"responses": self.responses}
|