MCPcopy
hub / github.com/langchain-ai/langchain / agenerate

Method agenerate

libs/core/langchain_core/language_models/llms.py:898–1065  ·  view source on GitHub ↗

Asynchronously pass a sequence of prompts to a model and return generations. This method should make use of batched calls for models that expose a batched API. Use this method when you want to: 1. take advantage of batched calls, 2. need more output

(
        self,
        prompts: List[str],
        stop: Optional[List[str]] = None,
        callbacks: Optional[Union[Callbacks, List[Callbacks]]] = None,
        *,
        tags: Optional[Union[List[str], List[List[str]]]] = None,
        metadata: Optional[Union[Dict[str, Any], List[Dict[str, Any]]]] = None,
        run_name: Optional[Union[str, List[str]]] = None,
        run_id: Optional[Union[uuid.UUID, List[Optional[uuid.UUID]]]] = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

896 return output
897
898 async def agenerate(
899 self,
900 prompts: List[str],
901 stop: Optional[List[str]] = None,
902 callbacks: Optional[Union[Callbacks, List[Callbacks]]] = None,
903 *,
904 tags: Optional[Union[List[str], List[List[str]]]] = None,
905 metadata: Optional[Union[Dict[str, Any], List[Dict[str, Any]]]] = None,
906 run_name: Optional[Union[str, List[str]]] = None,
907 run_id: Optional[Union[uuid.UUID, List[Optional[uuid.UUID]]]] = None,
908 **kwargs: Any,
909 ) -> LLMResult:
910 """Asynchronously pass a sequence of prompts to a model and return generations.
911
912 This method should make use of batched calls for models that expose a batched
913 API.
914
915 Use this method when you want to:
916 1. take advantage of batched calls,
917 2. need more output from the model than just the top generated value,
918 3. are building chains that are agnostic to the underlying language model
919 type (e.g., pure text completion models vs chat models).
920
921 Args:
922 prompts: List of string prompts.
923 stop: Stop words to use when generating. Model output is cut off at the
924 first occurrence of any of these substrings.
925 callbacks: Callbacks to pass through. Used for executing additional
926 functionality, such as logging or streaming, throughout generation.
927 **kwargs: Arbitrary additional keyword arguments. These are usually passed
928 to the model provider API call.
929
930 Returns:
931 An LLMResult, which contains a list of candidate Generations for each input
932 prompt and additional model provider-specific output.
933 """
934 # Create callback managers
935 if isinstance(callbacks, list) and (
936 isinstance(callbacks[0], (list, BaseCallbackManager))
937 or callbacks[0] is None
938 ):
939 # We've received a list of callbacks args to apply to each input
940 assert len(callbacks) == len(prompts)
941 assert tags is None or (
942 isinstance(tags, list) and len(tags) == len(prompts)
943 )
944 assert metadata is None or (
945 isinstance(metadata, list) and len(metadata) == len(prompts)
946 )
947 assert run_name is None or (
948 isinstance(run_name, list) and len(run_name) == len(prompts)
949 )
950 callbacks = cast(List[Callbacks], callbacks)
951 tags_list = cast(List[Optional[List[str]]], tags or ([None] * len(prompts)))
952 metadata_list = cast(
953 List[Optional[Dict[str, Any]]], metadata or ([{}] * len(prompts))
954 )
955 run_name_list = run_name or cast(

Callers 15

agenerate_promptMethod · 0.95
_call_asyncMethod · 0.95
_completion_with_retryFunction · 0.45
test_async_redis_cacheFunction · 0.45
ado_cache_testMethod · 0.45

Calls 12

_get_run_ids_listMethod · 0.95
dictMethod · 0.95
_agenerate_helperMethod · 0.95
get_llm_cacheFunction · 0.90
dumpdFunction · 0.90
RunInfoClass · 0.90
LLMResultClass · 0.90
aget_promptsFunction · 0.85
aupdate_cacheFunction · 0.85
configureMethod · 0.45
getMethod · 0.45
on_llm_startMethod · 0.45