Difference between revisions of "Bot Playground/AI"

From SmartBots Developers Docs
Jump to: navigation, search
(Created page with "AI root {{NavMenu}} __NOTOC__")
 
Line 1: Line 1:
AI root
+
Smartbots AI is a conversation based AI which can be used with playground scripts in order to create AI Conversations.
  
{{NavMenu}}
+
== Conversations ==
__NOTOC__
+
 
 +
*Conversations are the convenient way to manage conversations of the bot with different residents. Bot AI keeps track
 +
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 ==
 +
 
 +
===Bot.AI.chat(message, senderName[, options])===
 +
<onlyinclude>'''Sends a chat message request to bot AI.'''</onlyinclude>
 +
<syntaxhighlight lang="javascript">
 +
Bot.AI.chat(message, senderName[, options])
 +
</syntaxhighlight>
 +
 
 +
{{API Command Table}}
 +
{{API Required Vars|Bot.AI.chat}}
 +
 
 +
{{API Variable Group|Input}}
 +
{{API Variable|message|yes}} chat message to the bot
 +
{{API Variable|residentName|yes}} The name of the resident sending the message
 +
{{API Variable|options|optional}} The name of the resident sending the message Format:
 +
<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 HTTP Standard 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.
 +
 
 +
----
 +
 
 +
===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}}

Revision as of 19:16, 6 October 2023

Smartbots AI is a conversation based AI which can be used with playground scripts in order to create AI Conversations.

Conversations

  • Conversations are the convenient way to manage conversations of the bot with different residents. Bot AI keeps track

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

Bot.AI.chat(message, senderName[, options])

Sends a chat message request to bot AI.

Bot.AI.chat(message, senderName[, options])

Reference

This command accepts the following parameters:

Variable Required Description


Input:
message yes chat message to the bot
residentName yes The name of the resident sending the message
options optional The name of the resident sending the message Format:
{
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;
}
Output:
(to be received in http_response LSL event, see docs for details)
result OK - command completed successfully
FAIL - command failed
resulttext Detailed reason for the failure.
custom The value from input "custom" parameter. See above.
text The response of the bot
messageId The id of the response message. Can be specified as parentMessageId later
usage The object which contains Token Usage. Format: The object which contains all groups. Format:
{
// 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;
}
  • In case of error functions throws an error with a message.

Bot.AI.configure(options)

Configures AI options to be used in all further communications within the current script.

Bot.AI.configure(options)

Reference

This command accepts the following parameters:

Variable Required Description


Input:
options yes configuration directives for the AI engine. Format:
{
     // 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;
}
Output:
result This function does not return anything

Bot.AI.getConversationByName(residentName)

Get/create conversation with a specific resident. If conversation doesn't exist yet, creates it.

Bot.AI.getConversationByName(residentName)

Reference

This command accepts the following parameters:

Variable Required Description


Input:
residentName yes Resident SL name
Output:
result A conversation object.

Bot.AI.forgetConversation(residentName)

Forget (cancel) conversation of a bot with a specific resident.

Bot.AI.forgetConversation(residentName)

Reference

This command accepts the following parameters:

Variable Required Description


Input:
residentName yes Resident SL name
Output:
none

Conversation.chat(message[, options])

Sends a chat message request to bot AI within a conversation with a specific resident.

Conversation.chat(message[, options])

Reference

This command accepts the following parameters:

Variable Required Description


Input:
message yes chat message to the bot
options optional configuration directives for the AI engine. Example:
{
     // Main configuration instructions for the AI: role, behavior, response rules etc.
     instructions?: string;
     
     // Maximum number of tokens to generate in response
     maxResponseTokens?: number;
}
Output:
same value as Bot.AI.chat(...) This command returns the same value as Bot.AI.chat(...)

Conversation.configure(options)

Sets some configuration values for the future usage

Conversation.configure(options)

Reference

This command accepts the following parameters:

Variable Required Description


Input:
options yes configuration directives for the AI engine. Example:
{
     // Main configuration instructions for the AI: role, behavior, response rules etc.
     instructions?: string;
     
     // Maximum number of tokens to generate in response
     maxResponseTokens?: number;
}
Output:
none