Added custom request builder
This commit is contained in:
parent
20aa0e1732
commit
27ef6d5b2d
@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'it.ohalee.minecraftgpt'
|
||||
version = '1.2.0'
|
||||
version = '1.2.2'
|
||||
|
||||
sourceCompatibility = 1.17
|
||||
targetCompatibility = 1.17
|
||||
@ -15,7 +15,7 @@ tasks.withType(JavaCompile).configureEach {
|
||||
|
||||
project.ext.majorVersion = '1'
|
||||
project.ext.minorVersion = '2'
|
||||
project.ext.apiVersion = '0'
|
||||
project.ext.apiVersion = '1'
|
||||
project.ext.fullVersion = project.ext.majorVersion + '.' + project.ext.minorVersion + '.' + project.ext.apiVersion
|
||||
|
||||
repositories {
|
||||
|
@ -2,6 +2,7 @@ package it.ohalee.minecraftgpt;
|
||||
|
||||
import com.theokanning.openai.OpenAiService;
|
||||
import com.theokanning.openai.completion.CompletionRequest;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -14,18 +15,18 @@ public class OpenAI {
|
||||
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:");
|
||||
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
CompletionRequest request = CompletionRequest.builder()
|
||||
.prompt(cached.toString())
|
||||
.model("text-davinci-003")
|
||||
.temperature(0.9)
|
||||
.maxTokens(150)
|
||||
.topP(1.0)
|
||||
.frequencyPenalty(0.0)
|
||||
.presencePenalty(0.6)
|
||||
.model(section.getString("model"))
|
||||
.temperature(section.getDouble("temperature"))
|
||||
.maxTokens(section.getInt("max-tokens"))
|
||||
.topP(section.getDouble("top-p"))
|
||||
.frequencyPenalty(section.getDouble("frequency-penalty"))
|
||||
.presencePenalty(section.getDouble("presence-penalty"))
|
||||
.stop(Arrays.asList("Human:", "AI:"))
|
||||
.build();
|
||||
return service.createCompletion(request).getChoices().get(0).getText();
|
||||
|
@ -53,7 +53,7 @@ public class PlayerHandlers implements Listener {
|
||||
StringBuilder builder = Main.CACHE.getIfPresent(player);
|
||||
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) {
|
||||
throwable.printStackTrace();
|
||||
player.sendMessage(Messages.format(plugin.getConfig().getString("command.error")));
|
||||
|
@ -12,5 +12,13 @@ format:
|
||||
- "&b%player%: &7%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
|
||||
API_KEY: ""
|
@ -1,6 +1,6 @@
|
||||
name: MinecraftGPT
|
||||
main: it.ohalee.minecraftgpt.Main
|
||||
version: 1.2.0
|
||||
version: 1.2.2
|
||||
author: ohAlee
|
||||
description: A Minecraft plugin that uses ChatGPT
|
||||
api-version: 1.16
|
||||
|
Loading…
Reference in New Issue
Block a user