generated from LabyMod/addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from RappyLabyAddons/development
Release v1.1.4
- Loading branch information
Showing
23 changed files
with
258 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,10 @@ | ||
version = "0.1.0" | ||
|
||
plugins { | ||
id("java-library") | ||
} | ||
import net.labymod.labygradle.common.extension.LabyModAnnotationProcessorExtension.ReferenceType | ||
|
||
dependencies { | ||
labyProcessor() | ||
labyApi("api") | ||
|
||
// If you want to use external libraries, you can do that here. | ||
// The dependencies that are specified here are loaded into your project but will also | ||
// automatically be downloaded by labymod, but only if the repository is public. | ||
// If it is private, you have to add and compile the dependency manually. | ||
// You have to specify the repository, there are getters for maven central and sonatype, every | ||
// other repository has to be specified with their url. Example: | ||
// maven(mavenCentral(), "org.apache.httpcomponents:httpclient:4.5.13") | ||
} | ||
|
||
labyModProcessor { | ||
referenceType = net.labymod.gradle.core.processor.ReferenceType.INTERFACE | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
labyModAnnotationProcessor { | ||
referenceType = ReferenceType.INTERFACE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.rappytv.labygpt.api; | ||
|
||
import com.google.gson.Gson; | ||
import com.rappytv.labygpt.api.GPTMessage.GPTRole; | ||
import net.labymod.api.util.I18n; | ||
import net.labymod.api.util.io.web.request.Request; | ||
import net.labymod.api.util.io.web.request.Request.Method; | ||
import java.util.ArrayList; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
public class GPTRequest { | ||
|
||
private final static Gson gson = new Gson(); | ||
public static final ArrayList<GPTMessage> queryHistory = new ArrayList<>(); | ||
|
||
public static void sendRequestAsync(String query, String key, String username, | ||
String model, String behavior, Consumer<ApiResponse> responseConsumer) { | ||
|
||
if(queryHistory.isEmpty()) { | ||
queryHistory.add(new GPTMessage(behavior, GPTRole.System, "System")); | ||
} | ||
queryHistory.add(new GPTMessage(query, GPTRole.User, username)); | ||
|
||
Map<String, String> body = Map.of( | ||
"model", model, | ||
"messages", gson.toJson(queryHistory), | ||
"user", username | ||
); | ||
|
||
Request.ofGson(ResponseBody.class) | ||
.url("https://api.openai.com/v1/chat/completions") | ||
.method(Method.POST) | ||
.addHeader("Content-Type", "application/json") | ||
.addHeader("Authorization", "Bearer " + key) | ||
.json(body) | ||
.handleErrorStream() | ||
.async() | ||
.execute(response -> { | ||
boolean successful; | ||
String output = null; | ||
String error = null; | ||
ResponseBody responseBody = response.get(); | ||
|
||
if(response.hasException()) { | ||
successful = false; | ||
error = response.exception().getLocalizedMessage(); | ||
} else if(responseBody.error != null) { | ||
error = responseBody.error.message; | ||
if (error.isEmpty() && responseBody.error.code.equals("invalid_api_key")) { | ||
error = I18n.translate("labygpt.messages.invalidBearer"); | ||
} | ||
successful = false; | ||
} else if(responseBody.choices.isEmpty()) { | ||
successful = false; | ||
} else { | ||
GPTMessage message = responseBody.choices.getFirst().message; | ||
output = message.content.replace("\n\n", ""); | ||
queryHistory.add(new GPTMessage(output, GPTRole.Assistant, username)); | ||
successful = true; | ||
} | ||
responseConsumer.accept(new ApiResponse(successful, output, error)); | ||
}); | ||
} | ||
|
||
public record ApiResponse(boolean successful, String output, String error) { | ||
|
||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,39 @@ | ||
plugins { | ||
id("java-library") | ||
id("net.labymod.gradle") | ||
id("net.labymod.gradle.addon") | ||
id("net.labymod.labygradle") | ||
id("net.labymod.labygradle.addon") | ||
} | ||
|
||
group = "org.example" | ||
version = "1.0.0" | ||
|
||
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17)) | ||
val versions = providers.gradleProperty("net.labymod.minecraft-versions").get().split(";") | ||
|
||
tasks.withType<JavaCompile> { | ||
options.encoding = "UTF-8" | ||
} | ||
group = "org.example" | ||
version = providers.environmentVariable("VERSION").getOrElse("1.1.4") | ||
|
||
labyMod { | ||
defaultPackageName = "com.rappytv.labygpt" //change this to your main package name (used by all modules) | ||
defaultPackageName = "com.rappytv.labygpt.core" | ||
addonInfo { | ||
namespace = "labygpt" | ||
displayName = "LabyGPT" | ||
author = "RappyTV" | ||
description = "Communicate with ChatGPT right in your Chat. Powered by OpenAI." | ||
minecraftVersion = "*" | ||
version = System.getenv().getOrDefault("VERSION", "1.1.3") | ||
version = rootProject.version.toString() | ||
} | ||
|
||
minecraft { | ||
registerVersions( | ||
"1.8.9", | ||
"1.12.2", | ||
"1.16.5", | ||
"1.17.1", | ||
"1.18.2", | ||
"1.19.2", | ||
"1.19.3", | ||
"1.19.4", | ||
"1.20.1", | ||
"1.20.2", | ||
"1.20.4" | ||
) { version, provider -> | ||
configureRun(provider, version) | ||
} | ||
|
||
subprojects.forEach { | ||
if (it.name != "game-runner") { | ||
filter(it.name) | ||
registerVersion(versions.toTypedArray()) { | ||
runs { | ||
getByName("client") { | ||
devLogin = true | ||
} | ||
} | ||
} | ||
} | ||
|
||
addonDev { | ||
productionRelease() | ||
} | ||
} | ||
|
||
subprojects { | ||
plugins.apply("java-library") | ||
plugins.apply("net.labymod.gradle") | ||
plugins.apply("net.labymod.gradle.addon") | ||
|
||
repositories { | ||
maven("https://libraries.minecraft.net/") | ||
maven("https://repo.spongepowered.org/repository/maven-public/") | ||
} | ||
} | ||
|
||
fun configureRun(provider: net.labymod.gradle.core.minecraft.provider.VersionProvider, gameVersion: String) { | ||
provider.runConfiguration { | ||
mainClass = "net.minecraft.launchwrapper.Launch" | ||
jvmArgs("-Dnet.labymod.running-version=${gameVersion}") | ||
jvmArgs("-Dmixin.debug=true") | ||
jvmArgs("-Dnet.labymod.debugging.all=true") | ||
jvmArgs("-Dmixin.env.disableRefMap=true") | ||
plugins.apply("net.labymod.labygradle") | ||
plugins.apply("net.labymod.labygradle.addon") | ||
|
||
args("--tweakClass", "net.labymod.core.loader.vanilla.launchwrapper.LabyModLaunchWrapperTweaker") | ||
args("--labymod-dev-environment", "true") | ||
args("--addon-dev-environment", "true") | ||
} | ||
|
||
provider.javaVersion = when (gameVersion) { | ||
else -> { | ||
JavaVersion.VERSION_17 | ||
} | ||
} | ||
|
||
provider.mixin { | ||
val mixinMinVersion = when (gameVersion) { | ||
"1.8.9", "1.12.2", "1.16.5" -> { | ||
"0.6.6" | ||
} | ||
|
||
else -> { | ||
"0.8.2" | ||
} | ||
} | ||
|
||
minVersion = mixinMinVersion | ||
} | ||
} | ||
group = rootProject.group | ||
version = rootProject.version | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,13 @@ | ||
version = "0.1.0" | ||
|
||
plugins { | ||
id("java-library") | ||
} | ||
|
||
tasks.withType<JavaCompile> { | ||
options.encoding = "UTF-8" | ||
} | ||
import net.labymod.labygradle.common.extension.LabyModAnnotationProcessorExtension.ReferenceType | ||
|
||
dependencies { | ||
labyProcessor() | ||
api(project(":api")) | ||
|
||
// If you want to use external libraries, you can do that here. | ||
// The dependencies that are specified here are loaded into your project but will also | ||
// automatically be downloaded by labymod, but only if the repository is public. | ||
// If it is private, you have to add and compile the dependency manually. | ||
// You have to specify the repository, there are getters for maven central and sonatype, every | ||
// other repository has to be specified with their url. Example: | ||
// maven(mavenCentral(), "org.apache.httpcomponents:httpclient:4.5.13") | ||
} | ||
|
||
labyModProcessor { | ||
referenceType = net.labymod.gradle.core.processor.ReferenceType.DEFAULT | ||
// An example of how to add an external dependency that is used by the addon. | ||
// addonMavenDependency("org.jeasy:easy-random:5.0.0") | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
labyModAnnotationProcessor { | ||
referenceType = ReferenceType.DEFAULT | ||
} |
Oops, something went wrong.