Skip to content

Commit

Permalink
Merge pull request #25 from RappyLabyAddons/development
Browse files Browse the repository at this point in the history
Release v1.1.4
  • Loading branch information
RappyTV authored Dec 7, 2024
2 parents d6896b2 + 93ae5fd commit 44ba016
Show file tree
Hide file tree
Showing 23 changed files with 258 additions and 419 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,22 @@ on:
branches: [ "master", "main" ]
workflow_dispatch:

env:
PUBLIC_RELEASE_BUILD: true
PUBLIC_RELEASE_BUILD_TOKEN: ${{ secrets.PUBLIC_RELEASE_BUILD_TOKEN }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'
java-version: '21'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build --full-stacktrace
- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/*-release.jar
24 changes: 4 additions & 20 deletions api/build.gradle.kts
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
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.rappytv.labygpt.api;

import com.google.gson.annotations.SerializedName;

public class GPTMessage {
public String content;
public GPTRole role;
Expand All @@ -10,4 +12,13 @@ public GPTMessage(String content, GPTRole role, String name) {
this.role = role;
this.name = name;
}

public enum GPTRole {
@SerializedName("system")
System,
@SerializedName("user")
User,
@SerializedName("assistant")
Assistant
}
}
69 changes: 69 additions & 0 deletions api/src/main/java/com/rappytv/labygpt/api/GPTRequest.java
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) {

}
}
94 changes: 17 additions & 77 deletions build.gradle.kts
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
}
29 changes: 6 additions & 23 deletions core/build.gradle.kts
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
}
Loading

0 comments on commit 44ba016

Please sign in to comment.