ChatBotFunctions Model
- class smarter.apps.chatbot.models.ChatBotFunctions(*args, **kwargs)[source]
Bases:
TimestampedModelRepresents the set of callable functions that are available to a ChatBot instance within the Smarter platform.
This model is used to define and manage the specific functions that a chatbot can access or invoke during its operation. Each record in this model links a chatbot to a named function, enabling fine-grained control over the chatbot’s capabilities. The available functions are defined by a fixed set of choices, such as “weather”, “news”, “prices”, and “math”.
By associating functions with chatbots, the platform allows for extensible and customizable chatbot behavior, supporting use cases where different chatbots require access to different sets of features or integrations. This model is essential for scenarios where chatbots need to perform actions, retrieve information, or interact with external APIs in a controlled and auditable manner.
Model Relationships
Each ChatBotFunctions entry is linked to one
ChatBotinstance.Each entry specifies a function name from a predefined set of choices.
Usage Example
# Assign a function to a chatbot ChatBotFunctions.objects.create(chatbot=my_chatbot, name="weather") # List all functions available to a chatbot functions = ChatBotFunctions.objects.filter(chatbot=my_chatbot)
Notes
The set of available functions is controlled by the
CHOICESclass attribute.This model is intended for internal use to manage and audit chatbot capabilities.
Uniqueness is not enforced, so a chatbot may have multiple entries for the same function if needed.
- Parameters:
id (BigAutoField) – Primary key: ID
created_at (DateTimeField) – Created at
updated_at (DateTimeField) – Updated at
name (CharField) –
Name
The name of the function available to the ChatBot. Example: “weather”
Relationship fields:
- Parameters:
chatbot (
ForeignKeytoChatBot) –Chatbot (related name:
chatbotfunctions)The ChatBot instance associated with this function. Example: ChatBot(id=1, name=”my-chatbot”)
- CHOICES = [('get_current_weather', 'get_current_weather'), ('date_calculator', 'date_calculator'), ('calculator', 'calculator')]
The set of available function names that can be assigned to a ChatBot.
See Also:
smarter.apps.prompt.functions.function_weather.get_current_weather()smarter.apps.prompt.functions.function_date_calculator.date_calculator()smarter.apps.prompt.functions.function_calculator.calculator()
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- chatbot
-
Chatbot (related name:
chatbotfunctions)The ChatBot instance associated with this function. Example: ChatBot(id=1, name=”my-chatbot”)
- Type:
Type
- created_at
-
Created at
Timestamp indicating when the model instance was created. This field is automatically set to the current date and time when the instance is first created. It is indexed in the database for efficient querying.
- Type:
Type
- classmethod functions(chatbot)[source]
Returns a list of function names associated with the given ChatBot.
- classmethod get_cached_objects(invalidate=False, chatbot=None)[source]
Retrieve a queryset of ChatBotFunctions instances associated with a ChatBot using caching.
- get_name_display(*, field=<django.db.models.CharField: name>)
Shows the label of the
name. Seeget_FOO_display()for more information.
- id
-
Primary key: ID
- Type:
Type
- name
-
Name
Choices:
get_current_weatherdate_calculatorcalculator
The name of the function available to the ChatBot. Example: “weather”
- Type:
Type
- objects = <django.db.models.Manager object>
- updated_at
-
Updated at
Timestamp indicating when the model instance was last updated. This field is automatically updated to the current date and time whenever the instance is saved. It is indexed in the database for efficient querying.
- Type:
Type