Skip to content

Commit

Permalink
Added async _acall to FakeListLLM (langchain-ai#5439)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
camille-vanhoffelen authored and Undertone0809 committed Jun 19, 2023
1 parent c793a64 commit f702d0a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions langchain/llms/fake.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -22,7 +25,18 @@ def _call(
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
Expand Down

0 comments on commit f702d0a

Please sign in to comment.