Skip to main content
Version: 1.0

aixplain.modules.model.response

ModelResponse Objects

class ModelResponse()

[view_source]

ModelResponse class to store the response of the model run.

This class provides a structured way to store and manage the response from model runs. It includes fields for status, data, details, completion status, error messages, usage information, and additional metadata.

__init__

def __init__(status: ResponseStatus,
data: Text = "",
details: Optional[Union[Dict, List]] = {},
completed: bool = False,
error_message: Text = "",
used_credits: float = 0.0,
run_time: float = 0.0,
usage: Optional[Dict] = None,
url: Optional[Text] = None,
error_code: Optional[ErrorCode] = None,
**kwargs)

[view_source]

Initialize a new ModelResponse instance.

Arguments:

  • status ResponseStatus - The status of the response.
  • data Text - The data returned by the model.
  • details Optional[Union[Dict, List]] - Additional details about the response.
  • completed bool - Whether the response is complete.
  • error_message Text - The error message if the response is not successful.
  • used_credits float - The amount of credits used for the response.
  • run_time float - The time taken to generate the response.
  • usage Optional[Dict] - Usage information about the response.
  • url Optional[Text] - The URL of the response.
  • error_code Optional[ErrorCode] - The error code if the response is not successful.
  • data0 - Additional keyword arguments.

__getitem__

def __getitem__(key: Text) -> Any

[view_source]

Get an item from the ModelResponse.

Arguments:

  • key Text - The key to get the value for.

Returns:

  • Any - The value associated with the key.

Raises:

  • KeyError - If the key is not found in the ModelResponse.

get

def get(key: Text, default: Optional[Any] = None) -> Any

[view_source]

Get an item from the ModelResponse with a default value.

Arguments:

  • key Text - The key to get the value for.
  • default Optional[Any] - The default value to return if the key is not found.

Returns:

  • Any - The value associated with the key or the default value if the key is not found.

__setitem__

def __setitem__(key: Text, value: Any) -> None

[view_source]

Set an item in the ModelResponse.

Arguments:

  • key Text - The key to set the value for.
  • value Any - The value to set.

Raises:

  • KeyError - If the key is not found in the ModelResponse.

__repr__

def __repr__() -> str

[view_source]

Return a string representation of the ModelResponse.

Returns:

  • str - A string representation of the ModelResponse.

__contains__

def __contains__(key: Text) -> bool

[view_source]

Check if a key is in the ModelResponse.

Arguments:

  • key Text - The key to check for.

Returns:

  • bool - True if the key is in the ModelResponse, False otherwise.

to_dict

def to_dict() -> Dict[Text, Any]

[view_source]

Convert the ModelResponse to a dictionary.

Returns:

Dict[Text, Any]: A dictionary representation of the ModelResponse.