fabricatio_question.capabilities.questioning

Questioning capabilities module for interactive user prompts.

This module provides the Questioning class which extends the Propose capability to create interactive selection prompts for users.

Classes

Questioning

A capability class for creating interactive user selection prompts.

Module Contents

class fabricatio_question.capabilities.questioning.Questioning(/, **data: Any)

Bases: fabricatio_core.capabilities.propose.Propose

A capability class for creating interactive user selection prompts.

This class extends the Propose capability to generate and present selection questions to users, allowing for single or multiple choice interactions.

async selection(q: str, k: int = 1, **kwargs: Unpack[fabricatio_core.models.kwargs_types.LLMKwargs]) str | List[str]

Create an interactive selection prompt for the user.

This method first uses the LLM to generate a well-structured selection question based on the provided prompt, then presents it interactively to the user. The question can be configured for single or multiple selections.

Parameters:
  • q (str) – The question or prompt text that will be used to generate the interactive selection question.

  • k (int, optional) – The number of selections allowed. Defaults to 1. If k=1, returns a single string. If k>1, returns a list of strings.

  • **kwargs – Additional keyword arguments passed to the LLM generation process, such as model parameters, temperature, etc.

Returns:

If k=1, returns a single selected string.

If k>1, returns a list of selected strings up to k items.

Return type:

str | List[str]

Raises:

Exception – If the LLM generation fails or user interaction encounters an error.

async selection_string(q: str, k: int = 1, **kwargs: Unpack[fabricatio_core.models.kwargs_types.LLMKwargs]) str

Generates a selection question and returns the formatted response with selected indices.

This method creates a selection question using the internal propose method to generate options and then gathers user input for either a single or multiple selections. The result is rendered using a template that includes the question topic, options, and selections.

Parameters:
  • q (str) – The prompt text used to generate the selection question.

  • k (int, optional) – The number of selections allowed. Defaults to 1. If k=1, a single selection is made. If k>1, multiple selections are made up to k.

  • **kwargs – Additional keyword arguments passed to the LLM generation process.

Returns:

A formatted string representing the rendered selection question along with

the indices of the selected options.

Return type:

str

Raises:

Exception – If question generation or user interaction encounters an error.