Mixins

This file contains the mixins for the provider model.

class smarter.apps.prompt.providers.mixins.InternalKeys[source]

Bases: object

This class contains the internal keys for the provider model.

CompletionTokens = 'completion_tokens'
PromptTokens = 'prompt_tokens'
TotalTokens = 'total_tokens'
class smarter.apps.prompt.providers.mixins.ProviderDbMixin(*args, **kwargs)[source]

Bases: AccountMixin

This mixin contains the database related methods for the provider model.

__init__(*args, **kwargs)[source]

Constructor method for the ProviderDbMixin class.

property chat: Chat

This method returns the chat instance.

property chat_history: QuerySet

This method returns the chat history instance.

property db_charges: QuerySet

This method returns the charge instance. prompt_tokens = models.IntegerField() completion_tokens = models.IntegerField() total_tokens = models.IntegerField()

property db_chat_plugin_usage: ChatPluginUsage

This method returns the chat plugin usage instance.

property db_chat_tool_call: ChatToolCall

This method returns the chat tool call instance.

db_insert_charge(provider, charge_type, completion_tokens, prompt_tokens, total_tokens, model, reference)[source]
This method inserts a new charge record.

provider=self.provider, charge_type=charge_type, completion_tokens=self.completion_tokens, prompt_tokens=self.prompt_tokens, total_tokens=self.total_tokens, model=self.model, reference=self.reference or “ChatProviderBase._insert_charge_by_type()”,

db_insert_chat_plugin_usage(*args, **kwargs)[source]

This method inserts the chat plugin usage instance.

db_insert_chat_tool_call(*args, **kwargs)[source]

This method inserts the chat tool call instance.

property db_message_history: list[dict]

This method returns the most recently persisted messages in the chat history.

db_refresh()[source]

This method refreshes the provider instance.

db_save(*args, **kwargs)[source]

This method saves the chat instance associated with the session_key.

property db_total_completion_tokens: int

This method returns the completion tokens.

property db_total_prompt_tokens: int

This method returns the prompt tokens.

property db_total_tokens: dict
property db_total_total_tokens: int

This method returns the total tokens.

property ready: bool

This method returns the ready status.

smarter.apps.prompt.providers.mixins.should_log(level)[source]

Check if logging should be done based on the waffle switch.