ChatBotFunctions Model

class smarter.apps.chatbot.models.ChatBotFunctions(*args, **kwargs)[source]

Bases: TimestampedModel

Represents 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 ChatBot instance.

  • 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 CHOICES class 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:

Relationship fields:

Parameters:

chatbot (ForeignKey to ChatBot) –

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

ForeignKey to ChatBot

Chatbot (related name: chatbotfunctions)

The ChatBot instance associated with this function. Example: ChatBot(id=1, name=”my-chatbot”)

Type:

Type

chatbot_id

Internal field, use chatbot instead.

classmethod choices_list()[source]
created_at

DateTimeField

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.

Parameters:

chatbot (ChatBot) – The ChatBot instance to retrieve functions for.

Returns:

List of function names.

Return type:

List[str]

classmethod get_cached_objects(invalidate=False, chatbot=None)[source]

Retrieve a queryset of ChatBotFunctions instances associated with a ChatBot using caching.

Parameters:
  • invalidate (bool, optional) – Whether to invalidate the cache for this retrieval.

  • chatbot (Optional[ChatBot]) – The ChatBot instance for which to retrieve functions.

Return type:

models.QuerySet[“ChatBotFunctions”]

get_name_display(*, field=<django.db.models.CharField: name>)

Shows the label of the name. See get_FOO_display() for more information.

id

BigAutoField

Primary key: ID

Type:

Type

name

CharField

Name

Choices:

  • get_current_weather

  • date_calculator

  • calculator

The name of the function available to the ChatBot. Example: “weather”

Type:

Type

objects = <django.db.models.Manager object>
updated_at

DateTimeField

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