Added custom request builder

This commit is contained in:
ohAlee 2023-02-20 16:49:45 +01:00
parent 20aa0e1732
commit 27ef6d5b2d
5 changed files with 20 additions and 11 deletions

View File

@ -4,7 +4,7 @@ plugins {
} }
group = 'it.ohalee.minecraftgpt' group = 'it.ohalee.minecraftgpt'
version = '1.2.0' version = '1.2.2'
sourceCompatibility = 1.17 sourceCompatibility = 1.17
targetCompatibility = 1.17 targetCompatibility = 1.17
@ -15,7 +15,7 @@ tasks.withType(JavaCompile).configureEach {
project.ext.majorVersion = '1' project.ext.majorVersion = '1'
project.ext.minorVersion = '2' project.ext.minorVersion = '2'
project.ext.apiVersion = '0' project.ext.apiVersion = '1'
project.ext.fullVersion = project.ext.majorVersion + '.' + project.ext.minorVersion + '.' + project.ext.apiVersion project.ext.fullVersion = project.ext.majorVersion + '.' + project.ext.minorVersion + '.' + project.ext.apiVersion
repositories { repositories {

View File

@ -2,6 +2,7 @@ package it.ohalee.minecraftgpt;
import com.theokanning.openai.OpenAiService; import com.theokanning.openai.OpenAiService;
import com.theokanning.openai.completion.CompletionRequest; import com.theokanning.openai.completion.CompletionRequest;
import org.bukkit.configuration.ConfigurationSection;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -14,18 +15,18 @@ public class OpenAI {
service = new OpenAiService(key, 0); service = new OpenAiService(key, 0);
} }
public static CompletableFuture<String> getResponse(StringBuilder cached, String message) { public static CompletableFuture<String> getResponse(ConfigurationSection section, StringBuilder cached, String message) {
cached.append("\nHuman:").append(message).append("\nAI:"); cached.append("\nHuman:").append(message).append("\nAI:");
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
CompletionRequest request = CompletionRequest.builder() CompletionRequest request = CompletionRequest.builder()
.prompt(cached.toString()) .prompt(cached.toString())
.model("text-davinci-003") .model(section.getString("model"))
.temperature(0.9) .temperature(section.getDouble("temperature"))
.maxTokens(150) .maxTokens(section.getInt("max-tokens"))
.topP(1.0) .topP(section.getDouble("top-p"))
.frequencyPenalty(0.0) .frequencyPenalty(section.getDouble("frequency-penalty"))
.presencePenalty(0.6) .presencePenalty(section.getDouble("presence-penalty"))
.stop(Arrays.asList("Human:", "AI:")) .stop(Arrays.asList("Human:", "AI:"))
.build(); .build();
return service.createCompletion(request).getChoices().get(0).getText(); return service.createCompletion(request).getChoices().get(0).getText();

View File

@ -53,7 +53,7 @@ public class PlayerHandlers implements Listener {
StringBuilder builder = Main.CACHE.getIfPresent(player); StringBuilder builder = Main.CACHE.getIfPresent(player);
if (builder == null) builder = new StringBuilder(); if (builder == null) builder = new StringBuilder();
OpenAI.getResponse(builder, e.getMessage()).whenComplete((response, throwable) -> { OpenAI.getResponse(plugin.getConfig().getConfigurationSection("chatgpt"), builder, e.getMessage()).whenComplete((response, throwable) -> {
if (throwable != null) { if (throwable != null) {
throwable.printStackTrace(); throwable.printStackTrace();
player.sendMessage(Messages.format(plugin.getConfig().getString("command.error"))); player.sendMessage(Messages.format(plugin.getConfig().getString("command.error")));

View File

@ -12,5 +12,13 @@ format:
- "&b%player%: &7%message%" - "&b%player%: &7%message%"
- "&bAI -> %player%: &a%message%" - "&bAI -> %player%: &a%message%"
chatgpt:
model: "text-davinci-003"
temperature: 0.9
max-tokens: 150
top-p: 1.0
frequency-penalty: 0.0
presence-penalty: 0.6
# https://beta.openai.com/account/api-keys # https://beta.openai.com/account/api-keys
API_KEY: "" API_KEY: ""

View File

@ -1,6 +1,6 @@
name: MinecraftGPT name: MinecraftGPT
main: it.ohalee.minecraftgpt.Main main: it.ohalee.minecraftgpt.Main
version: 1.2.0 version: 1.2.2
author: ohAlee author: ohAlee
description: A Minecraft plugin that uses ChatGPT description: A Minecraft plugin that uses ChatGPT
api-version: 1.16 api-version: 1.16