aixplain.modules.model.response
ModelResponse Objects
class ModelResponse()
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)
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.data
0 - Additional keyword arguments.
__getitem__
def __getitem__(key: Text) -> Any
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
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
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
Return a string representation of the ModelResponse.
Returns:
str
- A string representation of the ModelResponse.
__contains__
def __contains__(key: Text) -> bool
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]
Convert the ModelResponse to a dictionary.
Returns:
Dict[Text, Any]: A dictionary representation of the ModelResponse.