PluginDataStatic Model
- class smarter.apps.plugin.models.PluginDataStatic(*args, **kwargs)[source]
Bases:
PluginDataBaseStores the configuration and static data set for a Smarter plugin which is based on static data.
This model is used for plugins that return static (predefined) data to the LLM. The
static_datafield holds the JSON data that will be returned when the plugin is invoked. This enables plugins to provide consistent, deterministic responses without external dependencies.PluginDataStaticprovides methods for:Returning sanitized static data, either as a dictionary or a list, with optional truncation for large datasets.
Extracting and caching all keys present in the static data, supporting both flat and nested structures.
Ensuring that the static data conforms to the expected structure and is compatible with the plugin’s parameter schema.
This model is a concrete subclass of
PluginDataBase, and is referenced byPluginMetato provide the data payload for static-type plugins. It is also used in conjunction withPluginSelectorandPluginPromptto enable full plugin lifecycle management.Typical use cases include plugins that serve reference data, lookup tables, or any information that does not require dynamic computation or remote queries.
See also:
- Parameters:
id (BigAutoField) – Primary key: ID
created_at (DateTimeField) – Created at
updated_at (DateTimeField) – Updated at
description (TextField) – Description. A brief description of what this plugin returns. Be verbose, but not too verbose.
parameters (JSONField) –
Parameters. A JSON dict containing parameter names and data types. Example: {‘required’: [], ‘properties’: {‘max_cost’: {‘type’: ‘float’, ‘description’: ‘the maximum cost that a student is willing to pay for a course.’}, ‘description’: {‘enum’: [‘AI’, ‘mobile’, ‘web’, ‘database’, ‘network’, ‘neural networks’], ‘type’: ‘string’, ‘description’: ‘areas of specialization for courses in the catalogue.’}}}
A JSON dict containing parameter names and data types. Example: {‘required’: [], ‘properties’: {‘max_cost’: {‘type’: ‘float’, ‘description’: ‘the maximum cost that a student is willing to pay for a course.’}, ‘description’: {‘enum’: [‘AI’, ‘mobile’, ‘web’, ‘database’, ‘network’, ‘neural networks’], ‘type’: ‘string’, ‘description’: ‘areas of specialization for courses in the catalogue.’}}}
test_values (JSONField) –
Test values. A JSON dict containing test values for each parameter. Example: {‘city’: ‘San Francisco’}
A JSON dict containing test values for each parameter. Example: {‘city’: ‘San Francisco’}
static_data (JSONField) –
Static data. The JSON data that this plugin returns to OpenAI API when invoked by the user prompt.
The JSON data that this plugin returns to OpenAI API when invoked by the user prompt.
Relationship fields:
- Parameters:
plugin (
OneToOneFieldtoPluginMeta) – Plugin (related name:plugin_data_base_plugin)plugindatabase_ptr (
OneToOneFieldtoPluginDataBase) – Primary key: Plugindatabase ptr (related name:plugindatastatic)
- exception DoesNotExist
Bases:
DoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- data(params=None)[source]
Return the static data as a dictionary. This method attempts to parse and return the
static_datafield as a dictionary.
- classmethod get_cached_data_by_plugin(plugin, invalidate=False)[source]
Return a single instance of PluginDataStatic by plugin.
This method caches the results to improve performance.
- Parameters:
plugin (PluginMeta) – The plugin whose data should be retrieved.
- Returns:
A PluginDataStatic instance if found, otherwise None.
- Return type:
Union[PluginDataStatic, None]
- classmethod get_cached_object(invalidate=False, pk=None, plugin=None)[source]
Retrieve a model instance by primary key, using caching to optimize performance. This method is selectively overridden in models that inherit from MetaDataModel to provide class-specific function parameters.
Example usage:
# Retrieve by primary key instance = MyModel.get_cached_object(pk=1)
- Parameters:
invalidate (bool) – If True, invalidate the cache for this query before retrieving the object.
pk (int) – The primary key of the model instance to retrieve.
plugin (PluginMeta) – The PluginMeta instance associated with the data to retrieve.
- Returns:
The model instance if found, otherwise None.
- Return type:
Optional[“PluginDataBase”]
- plugindatabase_ptr
OneToOneFieldtoPluginDataBasePrimary key: Plugindatabase ptr (related name:
plugindatastatic)- Type:
Type
- plugindatabase_ptr_id
Internal field, use
plugindatabase_ptrinstead.
- property return_data_keys: list[str] | None
Return all keys present in the
static_dataattribute.This property extracts, caches and returns a list of all keys found in the
static_datafield, supporting both dictionary and list formats:If
static_datais a dictionary, all nested keys are recursively collected and returned as a flat list.If
static_datais a list of dictionaries, the keys are extracted from each dictionary and returned as a list, truncated tosmarter_settings.plugin_max_data_resultsitems if necessary.If
static_datais neither a dictionary nor a list, aSmarterValueErroris raised.
- Returns:
A list of all keys in the static data, or None if not applicable.
- Return type:
- Raises:
SmarterValueError – If
static_datais not a dict or list.
Example:
# If static_data is a dict: static_data = {"a": 1, "b": {"c": 2}} return_data_keys # ['a', 'b', 'c'] # If static_data is a list of dicts: static_data = [{"name": "Alice"}, {"name": "Bob"}] return_data_keys # ['Alice', 'Bob']
- sanitized_return_data(params=None)[source]
Return the static data for this plugin, either as a dictionary or a list.
This method returns the value of
self.static_datain a sanitized form:If
static_datais a dictionary, it is returned as-is.If
static_datais a list, it is truncated tosmarter_settings.plugin_max_data_resultsitems (if necessary) and converted to a dictionary usinglist_of_dicts_to_dict().If
static_datais neither a dictionary nor a list, aSmarterValueErroris raised.