Skip to main content

return_prompt_wrapper

Wrapper that converts the return value of a function to an input class instance if it’s a string. Parameters:
  • cls (Any): The class to convert to.
  • func (Callable): The function to decorate.
Returns: Callable[…, Union[Any, str]]: Decorated function that returns the decorated class instance if the return value is a string.

wrap_prompt_functions

Decorator that wraps functions of a class inherited from :obj:str with the :obj:return_text_prompt decorator. Parameters:
  • cls (type): The class to decorate.
Returns: type: Decorated class with wrapped functions.

TextPrompt

A class that represents a text prompt. The :obj:TextPrompt class extends the built-in :obj:str class to provide a property for retrieving the set of keywords in the prompt. Parameters:
  • key_words (set): A set of strings representing the keywords in the prompt.

key_words

Returns a set of strings representing the keywords in the prompt.

format

Overrides the built-in :obj:str.format method to allow for default values in the format string. This is used to allow formatting the partial string. Returns: TextPrompt: A new :obj:TextPrompt object with the format string replaced with the formatted string.

CodePrompt

A class that represents a code prompt. It extends the :obj:TextPrompt class with a :obj:code_type property. Parameters:
  • code_type (str, optional): The type of code. Defaults to None.

new

Creates a new instance of the :obj:CodePrompt class. Returns: CodePrompt: The created :obj:CodePrompt instance.

code_type

Returns: Optional[str]: The type of code.

set_code_type

Sets the type of code. Parameters:
  • code_type (str): The type of code.

execute

Executes the code string using the provided interpreter. This method runs a code string through either a specified interpreter or a default one. It supports additional keyword arguments for flexibility. Parameters:
  • interpreter (Optional[BaseInterpreter]): The interpreter instance to use for execution. If None, a default interpreter is used. (default: :obj:None) **kwargs: Additional keyword arguments passed to the interpreter to run the code.
Returns: str: The result of the code execution. If the execution fails, this should include sufficient information to diagnose and correct the issue.

TextPromptDict

A dictionary class that maps from key to :obj:TextPrompt object.

init