generation
¶
Generation
¶
Generation(
server: BaseServer,
args: GenArgs,
*,
max_relay_rounds: int = 0,
mock_response: Optional[
Union[CompletionResponse, str]
] = None,
llm_executor_type: ExecutorType = ExecutorType.LLM_THREAD_POOL,
lazy_eval: bool = False,
_ctx: Optional[PromptContext] = None,
**kwargs: Any
)
Bases: Generic[M]
Represents a generation call to the model.
Parameters:
-
server
(BaseServer
) –An LLM server where the generation request will be sent.
-
args
(GenArgs
) –The arguments of the generation call.
-
max_relay_rounds
(int
, default:0
) –the maximum number of relay rounds to continue the unfinished text generation.
-
mock_response
(Optional[Union[CompletionResponse, str]]
, default:None
) –A mock response for the generation call.
-
llm_executor_type
(ExecutorType
, default:LLM_THREAD_POOL
) –The type of the executor to run the LLM call.
-
lazy_eval
(bool
, default:False
) –If True, the generation call will be evaluated lazily.
-
_ctx
(Optional[PromptContext]
, default:None
) –The prompt context filled automatically by the APPL function.
-
**kwargs
(Any
, default:{}
) –Extra arguments for the generation call.
Source code in src/appl/core/generation.py
as_prompt
¶
as_prompt() -> Union[AIMessage, StringFuture]
Get the response of the generation as a promptable object.
Source code in src/appl/core/generation.py
run_tool_calls
¶
run_tool_calls(
filter_fn: Optional[
Callable[[List[ToolCall]], List[ToolCall]]
] = None,
parallel: bool = False,
executor_type: ExecutorType = ExecutorType.GENERAL_THREAD_POOL,
log_results: Optional[bool] = None,
) -> List[ToolMessage]
Run all tool calls in the generation and return the results.
Parameters:
-
filter_fn
(Optional[Callable[[List[ToolCall]], List[ToolCall]]]
, default:None
) –A function that takes a list of ToolCall objects and returns a filtered list of ToolCall objects. This function can be used to filter the tool calls that will be run.
-
parallel
(bool
, default:False
) –If True, run the tool calls in parallel. Default to False.
-
executor_type
(ExecutorType
, default:GENERAL_THREAD_POOL
) –The type of the executor to run the tool calls, can be "general_thread_pool", "general_process_pool", "new_thread" or "new_process".
-
log_results
(Optional[bool]
, default:None
) –If True, log the results of the tool calls. Note This will wait for the results to be ready. Default to use the setting in configs.
Returns:
-
List[ToolMessage]
–A list of ToolMessage objects.
Source code in src/appl/core/generation.py
get_gen_name_prefix
¶
Get the prefix for generation names in the current thread.