From 80e133f16d02c1e644e498727c1ddf03f16d9d43 Mon Sep 17 00:00:00 2001 From: Camille Van Hoffelen Date: Tue, 30 May 2023 23:34:36 +0200 Subject: [PATCH] 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 --- langchain/llms/fake.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/langchain/llms/fake.py b/langchain/llms/fake.py index 15fbab5e..5700e82f 100644 --- a/langchain/llms/fake.py +++ b/langchain/llms/fake.py @@ -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