Harrison/better async (#2112)

Co-authored-by: Ammar Husain <ammo700@gmail.com>
searx
Harrison Chase 1 year ago committed by GitHub
parent 6e85cbcce3
commit c58932e8fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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…
Cancel
Save