|
|
|
@ -228,6 +228,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
callbacks=config.get("callbacks"),
|
|
|
|
|
tags=config.get("tags"),
|
|
|
|
|
metadata=config.get("metadata"),
|
|
|
|
|
run_name=config.get("run_name"),
|
|
|
|
|
**kwargs,
|
|
|
|
|
)
|
|
|
|
|
.generations[0][0]
|
|
|
|
@ -255,6 +256,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
callbacks=config.get("callbacks"),
|
|
|
|
|
tags=config.get("tags"),
|
|
|
|
|
metadata=config.get("metadata"),
|
|
|
|
|
run_name=config.get("run_name"),
|
|
|
|
|
**kwargs,
|
|
|
|
|
)
|
|
|
|
|
return llm_result.generations[0][0].text
|
|
|
|
@ -280,6 +282,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
callbacks=[c.get("callbacks") for c in config],
|
|
|
|
|
tags=[c.get("tags") for c in config],
|
|
|
|
|
metadata=[c.get("metadata") for c in config],
|
|
|
|
|
run_name=[c.get("run_name") for c in config],
|
|
|
|
|
**kwargs,
|
|
|
|
|
)
|
|
|
|
|
return [g[0].text for g in llm_result.generations]
|
|
|
|
@ -328,6 +331,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
callbacks=[c.get("callbacks") for c in config],
|
|
|
|
|
tags=[c.get("tags") for c in config],
|
|
|
|
|
metadata=[c.get("metadata") for c in config],
|
|
|
|
|
run_name=[c.get("run_name") for c in config],
|
|
|
|
|
**kwargs,
|
|
|
|
|
)
|
|
|
|
|
return [g[0].text for g in llm_result.generations]
|
|
|
|
@ -375,7 +379,11 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
self.metadata,
|
|
|
|
|
)
|
|
|
|
|
(run_manager,) = callback_manager.on_llm_start(
|
|
|
|
|
dumpd(self), [prompt], invocation_params=params, options=options
|
|
|
|
|
dumpd(self),
|
|
|
|
|
[prompt],
|
|
|
|
|
invocation_params=params,
|
|
|
|
|
options=options,
|
|
|
|
|
name=config.get("run_name"),
|
|
|
|
|
)
|
|
|
|
|
try:
|
|
|
|
|
generation: Optional[GenerationChunk] = None
|
|
|
|
@ -422,7 +430,11 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
self.metadata,
|
|
|
|
|
)
|
|
|
|
|
(run_manager,) = await callback_manager.on_llm_start(
|
|
|
|
|
dumpd(self), [prompt], invocation_params=params, options=options
|
|
|
|
|
dumpd(self),
|
|
|
|
|
[prompt],
|
|
|
|
|
invocation_params=params,
|
|
|
|
|
options=options,
|
|
|
|
|
name=config.get("run_name"),
|
|
|
|
|
)
|
|
|
|
|
try:
|
|
|
|
|
generation: Optional[GenerationChunk] = None
|
|
|
|
@ -544,6 +556,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
*,
|
|
|
|
|
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,
|
|
|
|
|
**kwargs: Any,
|
|
|
|
|
) -> LLMResult:
|
|
|
|
|
"""Run the LLM on the given prompt and input."""
|
|
|
|
@ -569,11 +582,17 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
assert metadata is None or (
|
|
|
|
|
isinstance(metadata, list) and len(metadata) == len(prompts)
|
|
|
|
|
)
|
|
|
|
|
assert run_name is None or (
|
|
|
|
|
isinstance(run_name, list) and len(run_name) == len(prompts)
|
|
|
|
|
)
|
|
|
|
|
callbacks = cast(List[Callbacks], callbacks)
|
|
|
|
|
tags_list = cast(List[Optional[List[str]]], tags or ([None] * len(prompts)))
|
|
|
|
|
metadata_list = cast(
|
|
|
|
|
List[Optional[Dict[str, Any]]], metadata or ([{}] * len(prompts))
|
|
|
|
|
)
|
|
|
|
|
run_name_list = run_name or cast(
|
|
|
|
|
List[Optional[str]], ([None] * len(prompts))
|
|
|
|
|
)
|
|
|
|
|
callback_managers = [
|
|
|
|
|
CallbackManager.configure(
|
|
|
|
|
callback,
|
|
|
|
@ -599,6 +618,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
self.metadata,
|
|
|
|
|
)
|
|
|
|
|
] * len(prompts)
|
|
|
|
|
run_name_list = [cast(Optional[str], run_name)] * len(prompts)
|
|
|
|
|
|
|
|
|
|
params = self.dict()
|
|
|
|
|
params["stop"] = stop
|
|
|
|
@ -620,9 +640,15 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
)
|
|
|
|
|
run_managers = [
|
|
|
|
|
callback_manager.on_llm_start(
|
|
|
|
|
dumpd(self), [prompt], invocation_params=params, options=options
|
|
|
|
|
dumpd(self),
|
|
|
|
|
[prompt],
|
|
|
|
|
invocation_params=params,
|
|
|
|
|
options=options,
|
|
|
|
|
name=run_name,
|
|
|
|
|
)[0]
|
|
|
|
|
for callback_manager, prompt in zip(callback_managers, prompts)
|
|
|
|
|
for callback_manager, prompt, run_name in zip(
|
|
|
|
|
callback_managers, prompts, run_name_list
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
output = self._generate_helper(
|
|
|
|
|
prompts, stop, run_managers, bool(new_arg_supported), **kwargs
|
|
|
|
@ -635,6 +661,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
[prompts[idx]],
|
|
|
|
|
invocation_params=params,
|
|
|
|
|
options=options,
|
|
|
|
|
name=run_name_list[idx],
|
|
|
|
|
)[0]
|
|
|
|
|
for idx in missing_prompt_idxs
|
|
|
|
|
]
|
|
|
|
@ -702,6 +729,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
*,
|
|
|
|
|
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,
|
|
|
|
|
**kwargs: Any,
|
|
|
|
|
) -> LLMResult:
|
|
|
|
|
"""Run the LLM on the given prompt and input."""
|
|
|
|
@ -718,11 +746,17 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
assert metadata is None or (
|
|
|
|
|
isinstance(metadata, list) and len(metadata) == len(prompts)
|
|
|
|
|
)
|
|
|
|
|
assert run_name is None or (
|
|
|
|
|
isinstance(run_name, list) and len(run_name) == len(prompts)
|
|
|
|
|
)
|
|
|
|
|
callbacks = cast(List[Callbacks], callbacks)
|
|
|
|
|
tags_list = cast(List[Optional[List[str]]], tags or ([None] * len(prompts)))
|
|
|
|
|
metadata_list = cast(
|
|
|
|
|
List[Optional[Dict[str, Any]]], metadata or ([{}] * len(prompts))
|
|
|
|
|
)
|
|
|
|
|
run_name_list = run_name or cast(
|
|
|
|
|
List[Optional[str]], ([None] * len(prompts))
|
|
|
|
|
)
|
|
|
|
|
callback_managers = [
|
|
|
|
|
AsyncCallbackManager.configure(
|
|
|
|
|
callback,
|
|
|
|
@ -748,6 +782,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
self.metadata,
|
|
|
|
|
)
|
|
|
|
|
] * len(prompts)
|
|
|
|
|
run_name_list = [cast(Optional[str], run_name)] * len(prompts)
|
|
|
|
|
|
|
|
|
|
params = self.dict()
|
|
|
|
|
params["stop"] = stop
|
|
|
|
@ -770,9 +805,15 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
run_managers = await asyncio.gather(
|
|
|
|
|
*[
|
|
|
|
|
callback_manager.on_llm_start(
|
|
|
|
|
dumpd(self), [prompt], invocation_params=params, options=options
|
|
|
|
|
dumpd(self),
|
|
|
|
|
[prompt],
|
|
|
|
|
invocation_params=params,
|
|
|
|
|
options=options,
|
|
|
|
|
name=run_name,
|
|
|
|
|
)
|
|
|
|
|
for callback_manager, prompt, run_name in zip(
|
|
|
|
|
callback_managers, prompts, run_name_list
|
|
|
|
|
)
|
|
|
|
|
for callback_manager, prompt in zip(callback_managers, prompts)
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
run_managers = [r[0] for r in run_managers]
|
|
|
|
@ -788,6 +829,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
|
|
|
|
[prompts[idx]],
|
|
|
|
|
invocation_params=params,
|
|
|
|
|
options=options,
|
|
|
|
|
name=run_name_list[idx],
|
|
|
|
|
)
|
|
|
|
|
for idx in missing_prompt_idxs
|
|
|
|
|
]
|
|
|
|
|