Skip to content

Commit

Permalink
feat: Fixing errors with ChatGPT
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou-Shilin committed Jun 12, 2024
1 parent e0f8bfc commit 1642011
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 7 deletions.
49 changes: 44 additions & 5 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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\": [
Expand All @@ -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%
%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%
42 changes: 40 additions & 2 deletions console.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import sys
import uuid
import shutil

from log_writer import logger
import core
import config
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")
Expand Down Expand Up @@ -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":
Expand All @@ -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...")
Expand Down

0 comments on commit 1642011

Please sign in to comment.