Difference between revisions of "Bot Playground/AI"

From SmartBots Developers Docs
Jump to: navigation, search
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Smartbots AI is a conversation based AI which can be used with playground scripts in order to create AI Conversations.
+
{{DISPLAYTITLE:SmartBots AI}}
 +
[https://www.mysmartbots.com/docs/SmartBots_AI SmartBots AI] is a conversation-based AI which can be used with Playground scripts in order to create AI conversations.
  
== Conversations ==
+
== SmartBots AI for developers ==
  
*Conversations are the convenient way to manage conversations of the bot with different residents. Bot AI keeps track
+
The most convenient way to access SmartBots AI is to use conversations.
of a context within a conversation.
+
*Conversation options can be adjusted separately for each conversation.
+
*Conversation is being created by calling '''Bot.AI.getConversationByName(residentName)'''. The resulting object may be
+
reused for further communications with AI.
+
*Conversations are system-wide, tied to bot + specific resident. This means that if you should not set different options
+
(like instructions) for the same bot in different scripts. This will lead AI to lose conversation context
+
  
== Commands ==
+
You can send "raw" requests to the AI but conversations give you the way to keep track of context (previous messages and responses.
  
===Bot.AI.chat(message, senderName[, options])===
+
* You create a conversation by calling '''Bot.AI.getConversationByName(residentName)'''. The resulting object may be reused for further communications with AI.
<onlyinclude>'''Sends a chat message request to bot AI.'''</onlyinclude>
+
* SmartBots AI keeps track of a context within a conversation.
<syntaxhighlight lang="javascript">
+
* Conversation options can be adjusted separately for each conversation.
Bot.AI.chat(message, senderName[, options])
+
* Conversations are system-wide, tied to script + bot + specific resident.
</syntaxhighlight>
+
  
{{API Command Table}}
+
== Main concepts ==
{{API Required Vars|Bot.AI.chat}}
+
  
{{API Variable Group|Input}}
+
; Instructions
{{API Variable|message|yes}} chat message to the bot
+
: The rules for the bot: how to react, how to role-play, what to know. [https://www.mysmartbots.com/docs/SmartBots_AI/Instructions Check instructions examples]
{{API Variable|residentName|yes}} The name of the resident sending the message
+
; Token
{{API Variable|options|optional}} The name of the resident sending the message Format:
+
: Each request to SmartBots AI consumes tokens. [[Bot Playground/AI/Tokens|Read more here]] about tokens usage.
<pre>
+
{
+
instructions?: string;
+
// Previous messade ID, if responding to a particular previous AI message of the bot
+
parentMessageId?: string;
+
// Maximum number of tokens to generate in response
+
maxResponseTokens?: number;
+
}
+
</pre>
+
{{API Variable Group|Output}}
+
{{API Variable|text|}} The response of the bot
+
{{API Variable|messageId|}} The id of the response message. Can be specified as parentMessageId later
+
{{API Variable|usage|}}  The object which contains Token Usage. Format:  The object which contains all groups. Format:
+
<pre>
+
{
+
// Number of tokens in a request (message + instructions + history)
+
prompt_tokens: number;
+
// Number of tokens in a response
+
completion_tokens: number;
+
// Total tokens used
+
total_tokens: number;
+
// Tokens left on SmartBots AI balance
+
tokens_left: number;
+
}
+
</pre>
+
{{API Variables Table End}}
+
  
* In case of error functions throws an error with a message.
+
== AI commands reference ==
  
----
+
{{API_Table_start|Command|Description}}
 +
{{API_Group|Commands}}
 +
{{API_Entry|HTTP Bot Command|Bot.AI.chat}}
 +
{{API_Entry|HTTP Bot Command|Bot.AI.configure}}
 +
{{API_Entry|HTTP Bot Command|Bot.AI.getConversationByName}}
 +
{{API_Entry|HTTP Bot Command|Bot.AI.forgetConversation}}
 +
{{API_Entry|HTTP Bot Command|Conversation.chat}}
 +
{{API_Entry|HTTP Bot Command|Conversation.configure}}
  
===Bot.AI.configure(options)===
 
<onlyinclude>'''Configures AI options to be used in all further communications within the current script.'''</onlyinclude>
 
<syntaxhighlight lang="javascript">
 
Bot.AI.configure(options)
 
</syntaxhighlight>
 
 
{{API Command Table}}
 
{{API Required Vars|Bot.AI.configure}}
 
 
{{API Variable Group|Input}}
 
{{API Variable|options|yes}} configuration directives for the AI engine. Format:
 
<pre>
 
{
 
    // Main configuration instructions for the AI: role, behavior, response rules etc.
 
    instructions?: string;
 
 
    // If responding to a particular previous AI message of the bot
 
    parentMessageId?: string;
 
 
    // Maximum number of tokens to generate in response
 
    maxResponseTokens?: number;
 
 
    // The unique conversation id. Usually generated automatically based
 
    // on the sender and bot name.
 
    conversationId?: string;
 
}
 
</pre>
 
{{API Variable Group|Output}}
 
{{API Return none}}
 
{{API Variables Table End}}
 
 
----
 
 
===Bot.AI.getConversationByName(residentName)===
 
<onlyinclude>'''Get/create conversation with a specific resident. If conversation doesn't exist yet, creates it.'''</onlyinclude>
 
<syntaxhighlight lang="javascript">
 
Bot.AI.getConversationByName(residentName)
 
</syntaxhighlight>
 
 
{{API Command Table}}
 
{{API Required Vars|Bot.AI.configure}}
 
 
{{API Variable Group|Input}}
 
{{API Variable|residentName|yes}} Resident SL name
 
 
{{API Variable Group|Output}}
 
{{API Variable|result}} A conversation object.
 
{{API Variables Table End}}
 
 
----
 
 
===Bot.AI.forgetConversation(residentName)===
 
<onlyinclude>'''Forget (cancel) conversation of a bot with a specific resident.'''</onlyinclude>
 
<syntaxhighlight lang="javascript">
 
Bot.AI.forgetConversation(residentName)
 
</syntaxhighlight>
 
 
{{API Command Table}}
 
{{API Required Vars|Bot.AI.forgetConversation}}
 
 
{{API Variable Group|Input}}
 
{{API Variable|residentName|yes}} Resident SL name
 
 
{{API Variable Group|Output}}
 
{{API Variable|none}}
 
{{API Variables Table End}}
 
 
----
 
 
===Conversation.chat(message[, options])===
 
<onlyinclude>'''Sends a chat message request to bot AI within a conversation with a specific resident.'''</onlyinclude>
 
<syntaxhighlight lang="javascript">
 
Conversation.chat(message[, options])
 
</syntaxhighlight>
 
 
{{API Command Table}}
 
{{API Required Vars|Conversation.chat}}
 
 
{{API Variable Group|Input}}
 
{{API Variable|message|yes}} chat message to the bot
 
{{API Variable|options|optional}} configuration directives for the AI engine. Example:
 
<pre>
 
{
 
    // Main configuration instructions for the AI: role, behavior, response rules etc.
 
    instructions?: string;
 
   
 
    // Maximum number of tokens to generate in response
 
    maxResponseTokens?: number;
 
}
 
</pre>
 
 
{{API Variable Group|Output}}
 
{{API Variable|same value as Bot.AI.chat(...)}} This command returns the same value as Bot.AI.chat(...)
 
{{API Variables Table End}}
 
 
----
 
 
===Conversation.configure(options)===
 
<onlyinclude>'''Sets some configuration values for the future usage'''</onlyinclude>
 
<syntaxhighlight lang="javascript">
 
Conversation.configure(options)
 
</syntaxhighlight>
 
 
{{API Command Table}}
 
{{API Required Vars|Conversation.chat}}
 
 
{{API Variable Group|Input}}
 
{{API Variable|options|yes}} configuration directives for the AI engine. Example:
 
<pre>
 
{
 
    // Main configuration instructions for the AI: role, behavior, response rules etc.
 
    instructions?: string;
 
   
 
    // Maximum number of tokens to generate in response
 
    maxResponseTokens?: number;
 
}
 
</pre>
 
 
{{API Variable Group|Output}}
 
{{API Variable|none}}
 
{{API Variables Table End}}
 
  
 
{{NavMenu}}
 
{{NavMenu}}
 
__NOTOC__
 
__NOTOC__

Latest revision as of 15:50, 16 October 2023

SmartBots AI is a conversation-based AI which can be used with Playground scripts in order to create AI conversations.

SmartBots AI for developers

The most convenient way to access SmartBots AI is to use conversations.

You can send "raw" requests to the AI but conversations give you the way to keep track of context (previous messages and responses.

  • You create a conversation by calling Bot.AI.getConversationByName(residentName). The resulting object may be reused for further communications with AI.
  • SmartBots AI keeps track of a context within a conversation.
  • Conversation options can be adjusted separately for each conversation.
  • Conversations are system-wide, tied to script + bot + specific resident.

Main concepts

Instructions
The rules for the bot: how to react, how to role-play, what to know. Check instructions examples
Token
Each request to SmartBots AI consumes tokens. Read more here about tokens usage.

AI commands reference

Command Description

Commands

Bot.AI.chat Sends a chat message request to bot AI.
Bot.AI.configure Configures AI options to be used in all further communications within the current script.
Bot.AI.getConversationByName Get/create conversation with a specific resident. If conversation doesn't exist yet, creates it.
Bot.AI.forgetConversation Forget (cancel) conversation of a bot with a specific resident.
Conversation.chat Sends a chat message request to bot AI within a conversation with a specific resident.
Conversation.configure Sets some configuration values for the future usage