models package
Submodules
models.base_langchain_model module
This module implements the base class for all LangChain models
- class models.base_langchain_model.BaseLangChainModel(llm: LLM | SimpleChatModel = None, system_message: str | None = None, memory_kvargs: Dict[Any, Any] = None, **kvargs)[source]
Bases:
BaseLLMModelThis is the base class for all LangChain models
- get_prompt_response(message: str, stream_handler: BaseCallbackHandler | None = None) str[source]
This method is used to get a response to a prompt
- Parameters:
message – The message to give to the LLM
stream_handler – if passed response is streamed via handler
- Returns:
The response from the LLM
- get_prompt_response_without_memory(message: str, stream_handler: BaseCallbackHandler | None = None) str[source]
This method is used to get a response to a prompt The message is given to the LLM without any memory
- Parameters:
message – The message to give to the LLM
stream_handler – if passed response is streamed via handler
- Returns:
The response from the LLM
- class models.base_langchain_model.StreamlitDisplayHandler(container: container, initial_text: str = '', display_method: str = 'markdown')[source]
Bases:
BaseCallbackHandlerThis class is used to display the output of the LLM in streamlit
models.base_model module
This file contains the base model class that all models should inherit from
- class models.base_model.BaseLLMModel(system_message: str | None = None, **kvargs)[source]
Bases:
objectThis is the base model class that all models should inherit from
- add_ai_message(message: str)[source]
This method is used to add an AI message to the conversation
- Parameters:
message – The message to add to the conversation
- add_user_message(message: str)[source]
This method is used to add a user message to the conversation
- Parameters:
message – The message to add to the conversation
- get_messages() List[Message][source]
This method is used to get the messages in the conversation
- Returns:
The messages in the conversation
- get_prompt_response(message: str, stream_handler: BaseCallbackHandler | None = None) str[source]
This method is used to get a response to a prompt
- Parameters:
message – The message to give to the LLM
stream_handler – if passed response is streamed via handler
- Returns:
The response from the LLM
- get_prompt_response_without_memory(message: str, stream_handler: BaseCallbackHandler | None = None) str[source]
This method is used to get a response to a prompt The message is given to the LLM without any memory
- Parameters:
message – The message to give to the LLM
stream_handler – if passed response is streamed via handler
- Returns:
The response from the LLM
models.chat_gpt module
ChatGPT is a class that inherits from BaseLangChainModel and uses the ChatOpenAI class to generate text.
- class models.chat_gpt.ChatGPT(system_message: str | None = None, memory_kvargs: Dict[Any, Any] = None, **kvargs)[source]
Bases:
BaseLangChainModelThis is the class for the ChatGPT model
models.llama2 module
LLAMA2 model
- class models.llama2.LLAMA2(system_message: str | None = None, memory_kvargs: Dict[Any, Any] = None, **kvargs)[source]
Bases:
BaseLangChainModelThis is the class for the LLAMA2 model
models.message module
This is the module for the message data class
- class models.message.Message(*, message: str, message_type: Literal['SYSTEM', 'USER', 'AI'], timestamp: datetime = None)[source]
Bases:
BaseModelThis is the class for a message
- message: str
- message_type: Literal['SYSTEM', 'USER', 'AI']
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'message': FieldInfo(annotation=str, required=True, description='The message'), 'message_type': FieldInfo(annotation=Literal[str, str, str], required=True, description='The type of message'), 'timestamp': FieldInfo(annotation=datetime, required=False, default_factory=builtin_function_or_method, description='The timestamp of the message')}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- timestamp: datetime
models.meta_info module
This module contains the meta information for a model
- class models.meta_info.ModelMetaInfo(*, base_dir: str, key: str | None = None, name: str, description: str, llm_model_file: str | None = None, llm_model_class: str | None = None, supports_stream: bool = None, icon: str = 'llm_model.png', system_message: str | None = 'You are a helpful assistant that responds in Markdown format.', llm_arguments: Dict[str, Any] = {}, memory_arguments: Dict[str, Any] = {}, required_llm_arguments: Dict[str, Literal['STRING', 'INT', 'FLOAT', 'BOOL', 'SECRET_STRING', 'LONG_STRING']] = {}, inherits_from: str | None = None, is_persistent: bool = True)[source]
Bases:
StreamLitPydanticModelThis class is used to store the meta information for a model
- add_conversation(conversation: Conversation) None[source]
This method is used to add a conversation
- Parameters:
conversation – The conversation
- 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 show
- Returns:
The additional fields to show
- base_dir: str
- description: str
- classmethod fields_to_edit() list[str | Dict[str, Dict[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
- 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
- get_conversations() list[Conversation][source]
This method is used to get the conversations
- Returns:
The conversations
- icon: str
- inherits_from: str | None
- is_persistent: bool
- key: str | None
- llm_arguments: Dict[str, Any]
- llm_model_class: str | None
- llm_model_file: str | None
- memory_arguments: Dict[str, Any]
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'base_dir': FieldInfo(annotation=str, required=True, alias_priority=2, validation_alias=AliasChoices(choices=['base_dir', 'BaseDir']), description='The base dir of the app'), 'description': FieldInfo(annotation=str, required=True, alias_priority=2, validation_alias=AliasChoices(choices=['description', 'Description']), description='The description of the model', metadata=[MinLen(min_length=20)]), 'icon': FieldInfo(annotation=str, required=False, default='llm_model.png', alias_priority=2, validation_alias=AliasChoices(choices=['icon', 'Icon']), description='The icon for the model'), 'inherits_from': FieldInfo(annotation=Union[str, NoneType], required=False, alias_priority=2, validation_alias=AliasChoices(choices=['inherits_from', 'InheritsFrom']), description='The model to inherit from'), 'is_persistent': FieldInfo(annotation=bool, required=False, default=True, alias_priority=2, validation_alias=AliasChoices(choices=['is_persistent', 'IsPersistent']), description='Whether the model is persistent'), 'key': FieldInfo(annotation=Union[str, NoneType], required=False, description='The key for the model'), 'llm_arguments': FieldInfo(annotation=Dict[str, Any], required=False, default={}, alias_priority=2, validation_alias=AliasChoices(choices=['llm_arguments', 'LLMArguments']), description='The arguments for the LLM Model'), 'llm_model_class': FieldInfo(annotation=Union[str, NoneType], required=False, alias_priority=2, validation_alias=AliasChoices(choices=['llm_model_class', 'LLMModelClass']), description='The model class'), 'llm_model_file': FieldInfo(annotation=Union[str, NoneType], required=False, alias_priority=2, validation_alias=AliasChoices(choices=['llm_model_file', 'LLMModelFile']), description='The model file'), 'memory_arguments': FieldInfo(annotation=Dict[str, Any], required=False, default={}, alias_priority=2, validation_alias=AliasChoices(choices=['memory_arguments', 'MemoryArguments']), description='The arguments for the chat memory module'), 'name': FieldInfo(annotation=str, required=True, alias_priority=2, validation_alias=AliasChoices(choices=['name', 'Name']), description='The name of the model', metadata=[MinLen(min_length=3)]), 'required_llm_arguments': FieldInfo(annotation=Dict[str, Literal[str, str, str, str, str, str]], required=False, default={}, alias_priority=2, validation_alias=AliasChoices(choices=['required_llm_arguments', 'RequiredLLMArguments']), description='The required arguments for the model'), 'supports_stream': FieldInfo(annotation=bool, required=False, alias_priority=2, validation_alias=AliasChoices(choices=['supports_stream', 'SupportsStream']), description='Whether the model supports streaming'), 'system_message': FieldInfo(annotation=Union[str, NoneType], required=False, default='You are a helpful assistant that responds in Markdown format.', alias_priority=2, validation_alias=AliasChoices(choices=['system_message', 'SystemMessage']), description='The system message for the model')}
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.
- name: str
- required_llm_arguments: Dict[str, Literal['STRING', 'INT', 'FLOAT', 'BOOL', 'SECRET_STRING', 'LONG_STRING']]
- 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_value_for_custom_fields(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
- supports_stream: bool
- system_message: str | None
- classmethod validate_base_dir(value: str) str[source]
Validates the base dir
- Parameters:
value – The value of the base dir
- Returns:
The value of the base dir
- Raises:
ValueError – If the base dir is not found