ui_elements package

Submodules

ui_elements.base_element module

This module contains the base class for all the streamlit UI elements

class ui_elements.base_element.StreamLitPydanticModel[source]

Bases: BaseModel

This class is used to automatically generate the streamlit UI for a pydantic model

additional_custom_fields_to_edit() list[str | FormatOption][source]

This method is used to get the additional fields to show

Returns:

The additional fields to show

additional_custom_fields_to_show() list[str | FormatOption][source]

This method is used to get the additional fields to be shown by the model

Returns:

The additional fields to show

classmethod create_model(model_dict: dict[str, FormatOption]) StreamLitPydanticModel | None[source]

This function creates the model

Parameters:

model_dict – The model meta information

Returns:

The model object

classmethod delete_object(key: str, model_meta_dict: dict[str, FormatOption]) None[source]

This function is called when user clicks on the delete button

Parameters:
  • key – The key of the object to delete

  • model_meta_dict – The model meta information

classmethod delete_operation(key: str | int, object_to_search: Any, *args) None[source]

This function deletes the key from the object

Parameters:
  • key – The key to delete

  • object_to_search – The object to search

classmethod fields_to_edit() list[str | FormatOption][source]

This method is used to get the fields to edit

Returns:

The fields to edit

classmethod fields_to_show() list[str | FormatOption][source]

This method is used to get the fields to show

Returns:

The fields to show

classmethod find_target_to_modify(keys: list[str], object_to_search: Any, operation: Callable[[str | int, Any], None], *args) None[source]

This function finds the target to modify this function is called in case of update, delete operations

Parameters:
  • keys – The list of keys to search

  • object_to_search – The object to search

  • operation – The operation to perform

get_additional_custom_field_value(field_name: str) Any[source]

This method is used to get the value for custom fields

Parameters:

field_name – The field name

Returns:

The field value

Raises:

NotImplementedError – This method is not implemented and needs to be

classmethod get_data_from_meta(meta_info: dict[str, FormatOption], key_prefix: str = '') dict[str, Any][source]

This function gets the data from the streamlit session state based on the meta information

Parameters:
  • meta_info – The meta information

  • key_prefix – The prefix to the key in session state

Returns:

The data in the same structure as the meta information from session state

classmethod get_default_value(value: Any | None = None, field_type: Literal['STRING', 'INT', 'FLOAT', 'BOOL', 'LIST', 'DICT', 'SECRET_STRING', 'LONG_STRING', 'IMAGE_PATH'] | None = None) Any[source]

This function returns the default value of the object

Parameters:
  • value – The value of the object

  • field_type – The field type

Returns:

The default value of the object

classmethod get_field_key(key_prefix: str, field_name) str[source]

This function returns the field key

Parameters:
  • key_prefix – The prefix to the key

  • field_name – The field name

Returns:

The field key

get_field_value(field_name: str) Any[source]

This method is used to get the value for a field

Parameters:

field_name – The field name

Returns:

The field value

get_serialised_model_data(view_mode: bool = False, create_mode=False) dict[str, FormatOption][source]

This function returns the serialised model meta information

Parameters:
  • view_mode – Whether the model is in view mode

  • create_mode – Whether the model is in create mode

Returns:

The serialised model meta information

classmethod get_value(value: Any | FormatOption) Any[source]

This function returns the value of the format option

Parameters:

value – The value of the format option

Returns:

The value of the format option

Return type:

Any

classmethod insert_operation(key: str | int, object_to_search: Any, insert_field_name: Any, insert_type: str) None[source]

This function inserts the key into the object

Parameters:
  • key – The key to insert

  • object_to_search – The object to search

  • insert_value – The value to insert

  • insert_type – The type of the value to insert

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

model_post_init(__context: Any) None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • __context – The context.

classmethod render_bool_object(field_name: str, header: str, value: bool, edit_mode: bool = False, key_prefix: str = '') None[source]

This function renders the bool object

Parameters:
  • field_name – The field name of the object

  • header – The header of the object

  • value – The value of the object

  • edit_mode – Whether the object is in edit mode

  • key_prefix – The prefix to the key

classmethod render_dict_object(field_name: str, header: str, value: dict[str, Any], edit_mode: bool = False, key_prefix: str = '') None[source]

This function renders the dict object

Parameters:
  • field_name – The field name of the object

  • header – The header of the object

  • value – The value of the object

  • edit_mode – Whether the object is in edit mode

  • key_prefix – The prefix to the key

classmethod render_image_path_object(field_name: str, header: str, image_path: str, edit_mode: bool = False, key_prefix: str = '') None[source]

This function renders the image path object

Parameters:
  • field_name – The field name of the object

  • header – The header of the object

  • value – The value of the object

  • edit_mode – Whether the object is in edit mode

  • key_prefix – The prefix to the key

classmethod render_list_object(field_name: str, header: str, value: list[Any], edit_mode: bool = False, key_prefix: str = '') None[source]

This function renders the list object

Parameters:
  • field_name – The field name of the object

  • header – The header of the object

  • value – The value of the object

  • edit_mode – Whether the object is in edit mode

  • key_prefix – The prefix to the key

classmethod render_long_string_object(field_name: str, header: str, value: str, edit_mode: bool = False, key_prefix: str = '') None[source]

This function renders the long string object

Parameters:
  • field_name – The field name of the object

  • header – The header of the object

  • value – The value of the object

  • edit_mode – Whether the object is in edit mode

  • key_prefix – The prefix to the key

classmethod render_model_in_create_mode(model_meta_info: dict[str, FormatOption]) None[source]

This function renders the model in create mode

Parameters:

model_meta_info – The model meta information

render_model_in_edit_mode(model_dict: dict[str, FormatOption]) None[source]

This function renders the model create view

Parameters:

model_dict – The model meta information

render_model_in_view_mode(model_meta_info: dict[str, FormatOption]) None[source]

This function renders the model to view

Parameters:

model_meta_info – The model meta information

classmethod render_number_object(field_name: str, header: str, value: float, edit_mode: bool = False, key_prefix: str = '') None[source]

This function renders the number object

Parameters:
  • field_name – The field name of the object

  • header – The header of the object

  • value – The value of the object

  • edit_mode – Whether the object is in edit mode

  • key_prefix – The prefix to the key

classmethod render_object(field_name: str, header: str, value: Any, field_type: Literal['STRING', 'INT', 'FLOAT', 'BOOL', 'LIST', 'DICT', 'SECRET_STRING', 'LONG_STRING', 'IMAGE_PATH'] | None = None, key_prefix: str = '', edit_mode: bool = False, delete: bool = False) None[source]

This function renders the object

Parameters:
  • header – The header of the object

  • value – The value of the object

  • field_type – Tells the type of the field (optional)

  • key_prefix – The prefix to the key

  • edit_mode – Whether the object is in edit mode

  • delete – Whether the object can be deleted

classmethod render_object_internal(field_name: str, header: str, value: Any, field_type: Literal['STRING', 'INT', 'FLOAT', 'BOOL', 'LIST', 'DICT', 'SECRET_STRING', 'LONG_STRING', 'IMAGE_PATH'] | None = None, key_prefix: str = '', edit_mode: bool = False) None[source]

This function renders the object

Parameters:
  • field_name – The field name of the object

  • header – The header of the object

  • value – The value of the object

  • edit_mode – Whether the object is in edit mode

  • key_prefix – The prefix to the key

classmethod render_secret_string_object(field_name: str, header: str, value: str, edit_mode: bool = False, key_prefix: str = '') None[source]

This function renders the secret string object

Parameters:
  • field_name – The field name of the object

  • header – The header of the object

  • value – The value of the object

  • edit_mode – Whether the object is in edit mode

  • key_prefix – The prefix to the key

render_sidebar() None[source]

This function renders the sidebar

classmethod render_string_object(field_name: str, header: str, value: str, edit_mode: bool = False, key_prefix: str = '') None[source]

This function renders the string object

Parameters:
  • field_name – The field name of the object

  • header – The header of the object

  • value – The value of the object

  • edit_mode – Whether the object is in edit mode

  • key_prefix – The prefix to the key

set_additional_custom_field_value(field_name: str, field_value: Any)[source]

This method is used to set the value for custom fields

Parameters:
  • field_name – The field name

  • field_value – The field value

set_field_value(field_name: str, field_value: Any) None[source]

This method is used to set the value for a field

Parameters:
  • field_name – The field name

  • field_value – The field value

set_value_for_custom_fields(field_name: str, field_value: Any) None[source]

This method is used to set the value for custom fields

Parameters:
  • field_name – The field name

  • field_value – The field value

set_value_from_sidebar()[source]

This function sets the value from the sidebar The value is set from the session state

classmethod update_array(type_key: str) None[source]

This function is called when user clicks on the add new item button

Parameters:

type_key – The key of the type of the item to add

classmethod update_dict(value_key: str, type_key: str) None[source]

This function is called when user clicks on the add new key button

Parameters:
  • value_key – The key of the value of the item to add

  • type_key – The key of the type of the item to add

validate_edit_and_save_state(model_dict: dict[str, FormatOption]) bool[source]

This function validates the edit

Parameters:

model_dict – The model meta information

Returns:

Whether the edit is valid

ui_elements.components module

This file contains the functions to render the user and system messages

ui_elements.components.render_group_ai_message(message: GroupMessage, container=None, placeholder=None, show_time=False) None[source]

This function renders the group system message

Parameters:
  • message – The message object containing system message

  • container – The container of the system message.

  • placeholder – The placeholder to write the message

  • show_time – Whether to show the time

ui_elements.components.render_group_user_message(message: GroupMessage) None[source]

This function renders the group user message

Parameters:

message – The message object containing user message

ui_elements.components.render_system_message(message: Message, previous_user_message: Message, message_placeholder=None, container=None, calculate_time=True, icon_path=None) tuple[container, empty][source]

This function renders the system message

Parameters:
  • message – The message object containing system message

  • previous_user_message – The previous user message

  • message_placeholder – The placeholder to write the message

  • container – The container of the system message.

  • calculate_time – Whether to calculate the time taken for the system to respond

  • icon_path – The path to Model chat Icon

Returns:

The container and the message placeholder of the system message

ui_elements.components.render_user_message(message: Message) None[source]

This function renders the user message

Parameters:

message – The message object containing user message

ui_elements.format_option module

This file contains the FormatOption class

class ui_elements.format_option.FormatOption(*, format_type: Literal['STRING', 'INT', 'FLOAT', 'BOOL', 'LIST', 'DICT', 'SECRET_STRING', 'LONG_STRING', 'STRING_CHOICE', 'IMAGE_PATH'], create_value: Any | None = None, title: str = None, value: Any = None, field_name: str, choices: list[str] | None = None)[source]

Bases: BaseModel

This class is used to store the format fields

choices: list[str] | None
create_value: Any | None
field_name: str
format_type: Literal['STRING', 'INT', 'FLOAT', 'BOOL', 'LIST', 'DICT', 'SECRET_STRING', 'LONG_STRING', 'STRING_CHOICE', 'IMAGE_PATH']
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'choices': FieldInfo(annotation=Union[list[str], NoneType], required=False, description='The choices'), 'create_value': FieldInfo(annotation=Union[Any, NoneType], required=False, description='The create value'), 'field_name': FieldInfo(annotation=str, required=True, description='The field name'), 'format_type': FieldInfo(annotation=Literal[str, str, str, str, str, str, str, str, str, str], required=True, description='The format type'), 'title': FieldInfo(annotation=str, required=False, description='The title'), 'value': FieldInfo(annotation=Any, required=False, description='The value of the data')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

title: str
validate_option() FormatOption[source]

This method is used to validate the option

Returns:

The validated option

value: Any

ui_elements.group_setting module

This module is used to store the meta GPT setting for the startup

class ui_elements.group_setting.MetaGPTSetting(*, investment: float = 3, implement: bool = True, code_review: bool = True, openai_api_key: str = '', run_tests: bool = False)[source]

Bases: StreamLitPydanticModel

This class is used to store the meta GPT setting for the startup

code_review: bool
classmethod fields_to_edit() list[str | FormatOption][source]

This method is used to get the fields to edit

Returns:

The fields to edit

get_field_value(field_name: str) Any[source]

This method is used to get the value for a field

Parameters:

field_name – The field name

Returns:

The field value

implement: bool
investment: float
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'code_review': FieldInfo(annotation=bool, required=False, default=True, description='Enable Code Review'), 'implement': FieldInfo(annotation=bool, required=False, default=True, description='Generate Application Code'), 'investment': FieldInfo(annotation=float, required=False, default=3, description='Upper Limit in OpenAI API usage in USD'), 'openai_api_key': FieldInfo(annotation=str, required=False, default='', description='The OpenAI API key'), 'run_tests': FieldInfo(annotation=bool, required=False, default=False, description='Generate Test Cases for the application')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

openai_api_key: str
run_tests: bool
set_field_value(field_name: str, field_value: Any) None[source]

This method is used to set the value for a field

Parameters:
  • field_name – The field name

  • field_value – The field value

Module contents