forked from Archives/langchain
Harrison/better async (#2112)
Co-authored-by: Ammar Husain <ammo700@gmail.com>
This commit is contained in:
parent
6e85cbcce3
commit
c58932e8fd
@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import List, Optional
|
||||
|
||||
@ -59,7 +60,9 @@ class BaseChatModel(BaseLanguageModel, BaseModel, ABC):
|
||||
self, messages: List[List[BaseMessage]], stop: Optional[List[str]] = None
|
||||
) -> LLMResult:
|
||||
"""Top Level call"""
|
||||
results = [await self._agenerate(m, stop=stop) for m in messages]
|
||||
results = await asyncio.gather(
|
||||
*[self._agenerate(m, stop=stop) for m in messages]
|
||||
)
|
||||
llm_output = self._combine_llm_outputs([res.llm_output for res in results])
|
||||
generations = [res.generations for res in results]
|
||||
return LLMResult(generations=generations, llm_output=llm_output)
|
||||
|
Loading…
Reference in New Issue
Block a user