39.2. Modelsο
39.2.1. Model Loadingο
- class memories.models.load_model.LoadModel[source]ο
Bases:
object- __init__(use_gpu=True, model_provider=None, deployment_type=None, model_name=None, api_key=None, endpoint=None, device=None)[source]ο
Initialize model loader with configuration.
- Parameters:
use_gpu (bool) β Whether to use GPU if available
model_provider (str) β The model provider (e.g., βdeepseekβ, βazure-aiβ, βmistralβ)
deployment_type (str) β Either βlocalβ or βapiβ
model_name (str) β Short name of the model from BaseModel.MODEL_MAPPINGS
api_key (str) β API key for the model provider (required for API deployment type)
endpoint (str) β Endpoint URL for the model provider (optional)
device (str) β Specific GPU device to use (e.g., βcuda:0β, βcuda:1β)
- get_response(prompt, **kwargs)[source]ο
Generate a response using either local model or API.
- Parameters:
prompt (str) β The input prompt
**kwargs β Additional generation parameters including: max_length: Maximum length of generated response temperature: Sampling temperature (0.0 to 1.0) top_p: Nucleus sampling parameter top_k: Top-k sampling parameter num_beams: Number of beams for beam search
- Returns:
- Response dictionary containing:
text: The generated response text metadata: Generation metadata (tokens, time, etc) error: Error message if generation failed
- Return type:
Dict[str, Any]
- get_response_with_context(prompt, context_data, **kwargs)[source]ο
Generate a response using context-aware prompting.
- Parameters:
prompt (str) β The input prompt
context_data (Dict[str, Any]) β Dictionary containing contextual information including: - location_info: Location details - raw_data_summary: Summary of raw data from different sources - analysis_results: Results of various analyses - scenario_projections: Future scenario projections - historical_trends: Historical trend analysis
**kwargs β Additional generation parameters including: max_length: Maximum length of generated response temperature: Sampling temperature (0.0 to 1.0) top_p: Nucleus sampling parameter top_k: Top-k sampling parameter num_beams: Number of beams for beam search
- Returns:
- Response dictionary containing:
text: The generated response text metadata: Generation metadata including context usage error: Error message if generation failed
- Return type:
Dict[str, Any]
- chat_completion(messages, tools=None, tool_choice='auto', **kwargs)[source]ο
Generate a chat completion response using either local model or API.
- Parameters:
messages (List[Dict[str, str]]) β List of message dictionaries with βroleβ and βcontentβ keys. Roles can be βuserβ, βassistantβ, βsystemβ, or βfunctionβ.
tools (List[Dict[str, Any]] | None) β Optional list of tool/function definitions that the model can use. Each tool should have a βtypeβ, βfunctionβ with βnameβ, βdescriptionβ, βparametersβ.
tool_choice (str) β How to handle tool selection. Options: - βautoβ: Let the model decide if it should call a function - βnoneβ: Donβt call any functions - Dict with specific function to call
**kwargs β Additional parameters including: temperature: Sampling temperature (0.0 to 1.0) max_tokens: Maximum tokens in the response top_p: Nucleus sampling parameter frequency_penalty: Frequency penalty parameter presence_penalty: Presence penalty parameter
- Returns:
- Response dictionary containing:
message: The assistantβs message tool_calls: List of tool calls if any metadata: Generation metadata error: Error message if generation failed
- Return type:
Dict[str, Any]
39.2.2. Base Modelο
- class memories.models.base_model.BaseModel[source]ο
Bases:
objectBase model class that can be shared across modules
- initialize_model(model, use_gpu=True, device=None)[source]ο
Initialize a model with the specified configuration.
39.2.3. API Connectorsο
API connectors for various model providers.
- class memories.models.api_connector.APIConnector[source]ο
Bases:
ABCBase class for API connectors.
- __init__(api_key=None)[source]ο
Initialize the API connector.
- Parameters:
api_key (str | None) β
- class memories.models.api_connector.OpenAIConnector[source]ο
Bases:
APIConnectorConnector for OpenAI API.
- chat_completion(messages, tools=None, tool_choice='auto', **kwargs)[source]ο
Generate a chat completion using the OpenAI API.
- Parameters:
messages (List[Dict[str, str]]) β List of message dictionaries with βroleβ and βcontentβ keys
tools (List[Dict[str, Any]] | None) β Optional list of tools/functions the model can use
tool_choice (str) β How to handle tool selection (βautoβ, βnoneβ, or specific)
**kwargs β Additional parameters for the API call
- Returns:
Dict containing the response message, tool calls, and metadata
- Return type:
- class memories.models.api_connector.DeepseekConnector[source]ο
Bases:
APIConnectorConnector for Deepseek API.
- class memories.models.api_connector.AnthropicConnector[source]ο
Bases:
APIConnectorConnector for Anthropic API.
- class memories.models.api_connector.AzureAIConnector[source]ο
Bases:
APIConnectorConnector for Azure AI API.
- memories.models.api_connector.get_connector(provider, api_key=None, endpoint=None)[source]ο
Get the appropriate API connector based on provider.
- Parameters:
- Returns:
APIConnector instance
- Raises:
ValueError β If provider is not supported
- Return type:
- class memories.models.api_connector.APIConnector[source]ο
Bases:
ABCBase class for API connectors.
- __init__(api_key=None)[source]ο
Initialize the API connector.
- Parameters:
api_key (str | None) β
- class memories.models.api_connector.OpenAIConnector[source]ο
Bases:
APIConnectorConnector for OpenAI API.
- chat_completion(messages, tools=None, tool_choice='auto', **kwargs)[source]ο
Generate a chat completion using the OpenAI API.
- Parameters:
messages (List[Dict[str, str]]) β List of message dictionaries with βroleβ and βcontentβ keys
tools (List[Dict[str, Any]] | None) β Optional list of tools/functions the model can use
tool_choice (str) β How to handle tool selection (βautoβ, βnoneβ, or specific)
**kwargs β Additional parameters for the API call
- Returns:
Dict containing the response message, tool calls, and metadata
- Return type:
- class memories.models.api_connector.AnthropicConnector[source]ο
Bases:
APIConnectorConnector for Anthropic API.
- class memories.models.api_connector.DeepseekConnector[source]ο
Bases:
APIConnectorConnector for Deepseek API.
39.2.4. Deployment Typesο
The system supports two deployment types:
Local Deployment: Models are loaded and run locally on your machine
API Deployment: Models are accessed through provider APIs (OpenAI, Anthropic, Deepseek)
39.2.5. Supported Providersο
deepseek-ai: Models from Deepseek AI
openai: Models from OpenAI
anthropic: Models from Anthropic
meta: Models from Meta
mistral: Models from Mistral AI