From 05515947224c7aa100559c8fc351bdaeed9125e7 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Mon, 15 May 2023 08:57:30 -0700 Subject: [PATCH] add async default (#4701) a spin on https://github.com/hwchase17/langchain/pull/4300/files#diff-4f16071d58cd34fb3ec5cd5089e9dbd6fb06574c25c76b4d573827f8a2f48e96 --- langchain/chat_models/base.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/langchain/chat_models/base.py b/langchain/chat_models/base.py index bc62535a..806c1574 100644 --- a/langchain/chat_models/base.py +++ b/langchain/chat_models/base.py @@ -2,6 +2,7 @@ import asyncio import inspect import warnings from abc import ABC, abstractmethod +from functools import partial from typing import Any, Dict, List, Mapping, Optional, Sequence from pydantic import Extra, Field, root_validator @@ -239,3 +240,12 @@ class SimpleChatModel(BaseChatModel): run_manager: Optional[CallbackManagerForLLMRun] = None, ) -> str: """Simpler interface.""" + + async def _agenerate( + self, + messages: List[BaseMessage], + stop: Optional[List[str]] = None, + run_manager: Optional[AsyncCallbackManagerForLLMRun] = None, + ) -> ChatResult: + func = partial(self._generate, messages, stop=stop, run_manager=run_manager) + return await asyncio.get_event_loop().run_in_executor(None, func)