diff --git a/config.yaml b/config.yaml index d8f984d..f26c5d1 100644 --- a/config.yaml +++ b/config.yaml @@ -9,6 +9,7 @@ API_KEY: "" # Free API Key with GPT-4 access: https://github.com/CubeGPT/.github BASE_URL: "https://api.openai.com/v1/chat/completions" GENERATION_MODEL: "gpt-4-turbo-2024-04-09" +FIXING_MODEL: "gpt-4-turbo-2024-04-09" # DEVELOPER SETTINGS # VERSION_NUMBER: "Beta 1.0" @@ -20,10 +21,10 @@ VERSION_NUMBER: "Beta 1.0" SYS_GEN: | You're a minecraft bukkit plugin coder AI. Game Version: 1.13.2 (1.13.2-R0.1-SNAPSHOT) Write the code & choose a artifact name for the following files with the infomation which is also provided by the user: - %WORKING_PATH%/Main.java - src/main/resources/plugin.yml - src/main/resources/config.yml - pom.xml + codes/%ARTIFACT_NAME%/src/main/java/%PKG_ID_LST%Main.java + codes/%ARTIFACT_NAME%/src/main/resources/plugin.yml + codes/%ARTIFACT_NAME%/src/main/resources/config.yml + codes/%ARTIFACT_NAME%/pom.xml Response in json format: { \"codes\": [ @@ -48,4 +49,42 @@ SYS_GEN: | You should never response anything else. Never use Markdown format. Use \n for line feed, and never forget to use \ before ". Never write uncompeleted codes, such as leave a comment that says "// Your codes here" or "// Uncompeleted". USR_GEN: | - %DESCRIPTION% \ No newline at end of file + %DESCRIPTION% + +SYS_FIX: | + You're a minecraft bukkit plugin coder AI. Game Version: 1.13.2 (1.13.2-R0.1-SNAPSHOT) + Fix the error in the code provided by user. The error message is also provided by the user. + Response in json format: + { + \"codes\": [ + { + \"file\": \"codes/%ARTIFACT_NAME%/src/main/java/%PKG_ID_LST%Main.java\", + \"code\": \"package ...;\\nimport org.bukkit.Bukkit;\\npublic class Main extends JavaPlugin implements CommandExecutor {\\n... (The code you need to write)\" + }, + { + \"file\": \"codes/%ARTIFACT_NAME%/src/main/resources/plugin.yml\", + \"code\": \"name: ...\\nversion: ...\\n...\" + }, + { + \"file\": \"codes/%ARTIFACT_NAME%/src/main/resources/config.yml\", + \"code\": \"...\" + }, + { + \"file\": \"codes/%ARTIFACT_NAME%/pom.xml\", + \"code\": \"...\" + } + ] + } + You should never response anything else. Never use Markdown format. Use \n for line feed, and never forget to use \ before ". Never write uncompeleted codes, such as leave a comment that says "// Your codes here" or "// Original code" or "// Uncompeleted". + +USR_FIX: | + Main.java: + %MAIN_JAVA% + plugin.yml: + %PLUGIN_YML% + config.yml: + %CONFIG_YML% + pom.xml: + %POM_XML% + error message: + %P_ERROR_MSG% diff --git a/console.py b/console.py index 3a83159..a555398 100644 --- a/console.py +++ b/console.py @@ -1,5 +1,6 @@ import sys import uuid +import shutil from log_writer import logger import core @@ -7,6 +8,11 @@ import build if __name__ == "__main__": + main_java = None + plugin_yml = None + config_yml = None + pom_xml = None + core.initialize() print("BukkitGPT v3 beta console running") @@ -38,6 +44,7 @@ result = build.build_plugin(artifact_name) + if "BUILD SUCCESS" in result: print(f"Build complete. Find your plugin at 'codes/{artifact_name}/target/{artifact_name}.jar'") elif "Compilation failure": @@ -47,10 +54,41 @@ print("Exiting...") sys.exit(0) else: - print("Fixing is a uncompleted feature.") - print("Restart the program and retype the name & description, etc. to try again.") + print("Passing the error to ChatGPT...") + + files = [f"codes/{artifact_name}/src/main/java/{pkg_id_path}Main.java", + f"codes/{artifact_name}/src/main/resources/plugin.yml", + f"codes/{artifact_name}/src/main/resources/config.yml", + f"codes/{artifact_name}/pom.xml"] + + ids = ["main_java", + "plugin_yml", + "config_yml", + "pom_xml"] + + for file in files: + with open(file, "r") as f: + code = f.read() + id = ids[files.index(file)] + globals()[id] = code + + print("Generating...") + codes = core.askgpt(config.SYS_FIX.replace("%ARTIFACT_NAME%", artifact_name), config.USR_FIX.replace("%MAIN_JAVA%", main_java).replace("%PLUGIN_YML%", plugin_yml).replace("%CONFIG_YML%", config_yml).replace("%POM_XML%", pom_xml).replace("%P_ERROR_MSG%", result), config.FIXING_MODEL) + + shutil.rmtree(f"codes/{artifact_name}") + core.response_to_action(codes) + + print("Code generated. Building now...") + + result = build.build_plugin(artifact_name) + + if "BUILD SUCCESS" in result: + print(f"Build complete. Find your plugin at 'codes/{artifact_name}/target/{artifact_name}.jar'") + else: + print("Build failed. Please check the logs && send the log to @BaimoQilin on discord.") print("Exiting...") sys.exit(0) + else: print("Unknown error. Please check the logs && send the log to @BaimoQilin on discord.") print("Exiting...")