Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Latest commit

 

History

History
82 lines (60 loc) · 3.84 KB

EXAMPLES.md

File metadata and controls

82 lines (60 loc) · 3.84 KB

Usage Examples

This document is not yet completed! You may fully explore your options with the documentation or by looking through the source code of this library.

Table of Contents

➡️ Completions

Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.

Usage:

Client::init('YOUR_API_KEY')->completions()->create('what is 9+10?', 'text-davinci-003', [
    'max_tokens' => 2048 // NOTE: if you wonder why your replies are cut off, it's because the default is 16
], function (array $result) {
    $this->getServer()->broadcastMessage(TextFormat::GREEN . trim($result['choices'][0]['text']));
});

image

Idea: Interactable Q&A bot after fine-tuning the model. This can greatly increase Fine-tuning training and Model usage costs if used irresponsibly.

➡️ Edits

Given a prompt and an instruction, the model will return an edited version of the prompt.

Usage:

Client::init('YOUR_API_KEY')->edits()->create('What day of the wek is it?', 'Fix the spelling mistakes', 'text-davinci-edit-001', [], function (array $result) {
    $this->getServer()->broadcastMessage(TextFormat::GREEN . trim($result['choices'][0]['text']));
});

image

Idea: Automatically fix spelling mistakes in chat. If I am not wrong, this does not incur any usage costs. However, this may change in the future so please confirm that yourself.

➡️ Images

Given a prompt and/or an input image, the model will generate a new image. There are also image edits and image variations not shown in the example. Related guide: Image generation.

Usage:

// NOTE: use the asynchronous callback parameter provided to prevent file_put_contents from blocking the main thread
Client::init('YOUR_API_KEY')->images()->create('minecraft', [], null, function (array $result) use ($dataFolder) {
    $image = file_get_contents($result['data'][0]['url']);
    if ($image !== false) {
        file_put_contents($dataFolder . 'image.png', $image);
    }
});

prompt: minecraft

image

Idea: Allow players to generate images with a command and have it put up as maps on item frames. This can greatly increase DALL·E API usage costs if used irresponsibly.

➡️ Moderations

Given a input text, outputs if the model classifies it as violating OpenAI's content policy. Related guide: Moderations.

Usage:

Client::init('YOUR_API_KEY')->moderations()->create('I want to kill them.', [], function (array $result) use ($player) {
    if ($result['results'][0]['flagged']) {
        $player->sendMessage('Your message was flagged as inappropriate!');
    }
});

image

Idea: Automatically filter out inappropriate messages. This can greatly increase Model usage costs if used irresponsibly.