Skript-GPT [Skript Addon] icon

Skript-GPT [Skript Addon] -----

A Skript Addon that allows users to interface with the OpenAI API



SkriptGPT.png
Skript-GPT
A Skript Addon that allows users to interface with the OpenAI API and lets them send completion requests.

Include AI in your minecraft Skripts. Create anything, from a random weapons generator to an in-game assistant at service of your players.

[​IMG]



[​IMG]

Effects
GPT Chat Completion Request


Generate a response to a prompt string using the OpenAI ChatGPT API, based on an input prompt.

Code (Text):
(generate|make) [a] chat[gpt] completion with (prompt|input) %string% [and model %-string%] [and max tokens %-number%] [and temperature %-number%]
(generate|make) [a] chat[gpt] completion with conversation %conversationmessages% [and model %-string%] [and max tokens %-number%] [and temperature %-number%]

Code (Text):
command /chatgpt [<text>]:
            trigger:
                if arg is set:
                    send message "&7%player%:&f %arg%" #echo message
                    set {_c} to a new conversation message #creates a new conversation message type.
                    set {_c}'s gpt content to arg #sets the content to the argument. Role is user by default.
                    add {_c} to {gpt::%player%::*} #Store the conversation message into a list. This list will contain all the conversation messages between the player and the AI.
                    generate a chat completion with conversation {gpt::%player%::*} #Actually prompt all of the conversation messages to ChatGPT.
                    set {_p} to last generated prompt #Retrieve response. It is a conversation message type.
                    add {_p} to {gpt::%player%::*} #Save the response as part of the conversation
                    send "&7ChatGPT:&f %{_p}%" #Show the response to the player. Converting the response into a string can be done implicitly.
                else:
                    send message "&cYou cleared your previous conversation."
                    clear {gpt::%player%::*}

Code (Text):
command /chat <text>:
    trigger:
       generate a chat gpt completion with prompt "Who are you?"
       set {_name} to generated prompt
       send {_name}
       #It will say "I am an helpful assistant from OpenAI!"

GPT Completion Request


Generate a completion of an input string using the OpenAI ChatGPT API, based on an input prompt. ATTENTION! This syntax does not use the ChatGPT endpoint. You won't receive back a conversation from the AI, just a chat completion. It will try to predict what the message is, it won't respond as an assistant. The echo part tells if to include a copy of the input prompt back into the response.

Code (Text):
(generate|make) [a] [gpt] completion with (prompt|input) %string% [and model %-string%] [and max tokens %-number%] [and temperature %-number%]

(generate|make) [a] [gpt] completion with (prompt|input) %string% [and model %-string%] [and max tokens %-number%] [and temperature %-number%] without echo
Code (Text):
   command /completion <text>:
        trigger:
            generate a gpt completion with prompt "Who are you?"
            set {_name} to generated prompt
            send {_name}
            #This will not respond with "I am ChatGPT, an helpful assistant made by OpenAI!"
            #It will say instead "I am a human" or "I am Zara" or any other possible endings to that incipit.

Types

Conversation Message

This type holds information about a message in a conversation with ChatGPT. It has two main parts, the role (which can only be set to "assistant", "system" or "user") and the content, which is basically whatever string the user or the AI want to send.

Code (Text):
%conversationmessage%

%conversationmessages%
conversation message


Usage

Code (Text):
send "%conversationmessage%" #implicitly converting it into a string will show its content.

set {_c} to %string% parsed as conversation message #builds a string with default role "user"
generate chat completion with conversation %conversationmessages% #Use conversation persistence.
Code (Text):


    command /setbias <text>:
trigger:
    #This is an example on how to bias your chatgpt conversation.
    #Basically all of your messages will be in the style of the previous one.
    #Pretend the arg is "You're a robot assistant, that talks in a robotic way saying bzz-bzz in between few words. You have a lot of knowledge and usually tell interesting stuff about robots. Your name is HAL"
    set {_bias} to new conversation message with role system #create new conversation message element. Its role is set to system.
    set {_bias}'s gpt content to arg #we set its content to the arg.
    set {gpt::%player%::0} to {_bias} #We append at the beginning of the conversation this element.
    set {gpt::%player%::*} to {gpt::%player%::*} #We fix the indices so we count from 1
    #from now on, sending a chat completion request with this list will also feed at the beginning a bias about how the AI should behave. Note that resetting the conversation with clear {gpt::%player%::*}  will remove the bias and clear everything.
   

Code (Text):
    command /showconv:
trigger:
    #we suppose all the conv is stored in {gpt::%player%::*}. The list is made of conversation messages.
    loop {gpt::%player%::*}:
        if loop-value's gpt role is "user":
            send message "%player%: %loop-value%" #we can also use %gpt content of loop-value%. Basically if the role of the message is user, we are sure it has been sent by the player. If we want to display it to them we send them a message with their name (to make it customized, instead of generic "user") and their message
        else:
            send message "%gpt role of loop-value%: %loop-value%"

Expressions

Generated Prompt

Returns the last generated response from a Chat Completion request. Call this immediately after sending a new chatgpt prompt, and save it into a variable.

Code (Text):
[the] [last] generated prompt


Code (Text):
    command /chat <text>:[/SIZE][/SIZE][/SIZE][/SIZE]
[SIZE=5][SIZE=4][SIZE=5][SIZE=4]trigger:
    generate a chat gpt completion with prompt "Who are you?"
    set {_name} to generated prompt
    send {_name}

New Conversation Message

Returns a conversation message type with a role and an empty content. if the [with role] part of the syntax is not specified, defaults to user.

Code (Text):
[a] new conversation message [with role [user|assistant|system]]


command /chatcompletion [<text>]:
trigger:
if arg is set:
send message "&7%player%:&f %arg%"
set {_c} to a new conversation message with role user
set {_c}'s gpt content to arg
add {_c} to {gpt::%player%::*}
generate a chatgpt completion with conversation {gpt::%player%::*}
set {_p} to last generated prompt
add {_p} to {gpt::%player%::*}
send "&7ChatGPT:&f %{_p}%"
else:
send message "&cYou cleared your previous conversation."
clear {gpt::%player%::*}

GPT Role of Conversation Message

Returns a string, which indicates the sender of the message. The role can only be either "system", "user" or "assistant".

Code (Text):
gpt role of %conversationmessage%[/SIZE][/SIZE][/SIZE][/SIZE]
[SIZE=5][SIZE=4][SIZE=5][SIZE=4]%conversationmessage%'s gpt role


Code (Text):
set {_msg} to new conversation message #defaults role to "user" [/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE]
[SIZE=5][SIZE=4][SIZE=5][SIZE=4][SIZE=5][SIZE=4]set gpt role of {_msg} to "system"



GPT Content of Conversation Message

Returns the content of a conversation message.

Code (Text):
gpt content of %conversationmessage%[/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE]
[SIZE=5][SIZE=4][SIZE=5][SIZE=4][SIZE=5][SIZE=4][SIZE=4][SIZE=5][SIZE=4][SIZE=4]%conversationmessage%'s gpt content


Code (Text):
command /inspectconv <offlineplayer>:[/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE][/SIZE]
[SIZE=5][SIZE=4][SIZE=5][SIZE=4][SIZE=5][SIZE=4][SIZE=4][SIZE=5][SIZE=4][SIZE=4][SIZE=5][SIZE=4][SIZE=4][SIZE=5][SIZE=4][SIZE=4][SIZE=5][SIZE=4][SIZE=4]trigger:
    if {gpt::%arg%::*} is set:
        send message "&7Conversation of %arg%:"
        loop {gpt::%arg%::*}:
            send message "%gpt role of loop-value%: %gpt content of loop-value%"



How to use conversation persistence?
After you red the docs, you might wondering whati is conversation persistence and how to implement it in your skript. Conversation persistence allows the assistant to remember what you told it in the past. It's like remembering your past messages, and it can be more helpful and contextual with your prompts. To implement it, you just have to store all the prompts from a player (and the AI responses) under the form of a Conversation Message in a Skript list. After that, simply feed the list back in the assistant (with the Chat Completion Request expression) and you'll get back a response that is based on the whole conversation, and not only the last prompt.














Resource Information
Author:
----------
Total Downloads: 1,067
First Release: Mar 26, 2023
Last Update: Mar 31, 2023
Category: ---------------
All-Time Rating:
11 ratings
Find more info at github.com...
Version -----
Released: --------------------
Downloads: ------
Version Rating:
----------------------
-- ratings