Added async _acall to FakeListLLM (#5439)

# Added Async _acall to FakeListLLM

FakeListLLM is handy when unit testing apps built with langchain. This
allows the use of FakeListLLM inside concurrent code with
[asyncio](https://docs.python.org/3/library/asyncio.html).

I also changed the pydocstring which was out of date.

## Who can review?

@hwchase17 - project lead
@agola11 - async
This commit is contained in:
Camille Van Hoffelen 2023-05-30 23:34:36 +02:00 committed by GitHub
parent 1f11f80641
commit 80e133f16d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,10 @@
"""Fake LLM wrapper for testing purposes."""
from typing import Any, List, Mapping, Optional
from langchain.callbacks.manager import CallbackManagerForLLMRun
from langchain.callbacks.manager import (
AsyncCallbackManagerForLLMRun,
CallbackManagerForLLMRun,
)
from langchain.llms.base import LLM
@ -22,7 +25,18 @@ class FakeListLLM(LLM):
stop: Optional[List[str]] = None,
run_manager: Optional[CallbackManagerForLLMRun] = None,
) -> str:
"""First try to lookup in queries, else return 'foo' or 'bar'."""
"""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,
) -> str:
"""Return next response"""
response = self.responses[self.i]
self.i += 1
return response