return_prompt_wrapper

def return_prompt_wrapper(cls: Any, func: Callable):

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

def wrap_prompt_functions(cls: T):

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

class TextPrompt(str):

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.

Attributes: key_words (set): A set of strings representing the keywords in the prompt.

key_words

def key_words(self):

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

format

def format(self, *args: Any, **kwargs: Any):

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

class CodePrompt(TextPrompt):

A class that represents a code prompt. It extends the :obj:TextPrompt class with a :obj:code_type property.

Attributes: code_type (str, optional): The type of code. Defaults to None.

new

def __new__(cls, *args: Any, **kwargs: Any):

Creates a new instance of the :obj:CodePrompt class.

Returns:

CodePrompt: The created :obj:CodePrompt instance.

code_type

def code_type(self):

Returns:

Optional[str]: The type of code.

set_code_type

def set_code_type(self, code_type: str):

Sets the type of code.

Parameters:

  • code_type (str): The type of code.

execute

def execute(
    self,
    interpreter: Optional[BaseInterpreter] = None,
    **kwargs: Any
):

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

class TextPromptDict:

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

init

def __init__(self, *args: Any, **kwargs: Any):