file#

class besser.agent.core.file.File(file_name=None, file_type=None, file_base64=None, file_path=None, file_data=None)[source]#

Bases: object

A representation of files sent and received by an agent.

Files are used to encapsulate information about the files exchanged in an agent conversation. They include attributes such as the file’s name, type, and base64 representation. Note that at least one of path, data or base64 need to be set.

Parameters:
  • file_name (str) – The name of the file.

  • file_type (str) – The type of the file.

  • file_base64 (str, optional) – The base64 representation of the file.

  • file_path (str, optional) – Path to the file.

  • file_data (bytes, optional) – Raw file data.

_name#

The name of the file.

Type:

str

_type#

The type of the file.

Type:

str

_base64#

The base64 representation of the file.

Type:

str

property base64#

Getter for the base64 representation of the file.

static decode(file_str)[source]#

Decode a JSON payload string into a File object.

Parameters:

file_str (str) – A JSON-encoded file string.

Returns:

A File object if the decoding is successful, None otherwise.

Return type:

File or None

static from_dict(data)[source]#

Returns a File object generated based on the given dict object.

get_json_string()[source]#

Returns a stringified dictionary containing the attributes of the File object.

property name#

Getter for the name of the file.

to_dict()[source]#

Returns a dictionary containing the attributes of the File object.

property type#

Getter for the type of the file.