Skip to content

Commit d0c264d

Browse files
authored
Merge pull request #8 from Zhou-Shilin/beta-1.1-dev
Beta 1.1 dev
2 parents 952b86f + 449e520 commit d0c264d

12 files changed

+257
-191
lines changed

.github/workflows/build-linux.yml

-44
This file was deleted.

.github/workflows/build-windows.yml

-43
This file was deleted.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ You can use BukkitGPT on any device with [Python 3+](https://www.python.org/).
5454

5555
And you need to install the depencies with this command:
5656
```
57-
pip install -r requirements.txt
57+
python -m pip install -U -r requirements.txt
5858
```
5959

6060
## Quick Start

build.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
from subprocess import Popen, PIPE, STDOUT
22
from log_writer import logger
33

4+
45
def build_plugin(artifact_name):
56
project_path = f"codes/{artifact_name}"
6-
build_command = ["cd", project_path, "&&", "mvn", "-V", "-B", "clean", "package", "--file", "pom.xml"]
7-
7+
build_command = [
8+
"cd",
9+
project_path,
10+
"&&",
11+
"mvn",
12+
"-V",
13+
"-B",
14+
"clean",
15+
"package",
16+
"--file",
17+
"pom.xml",
18+
]
19+
820
process = Popen(build_command, stdout=PIPE, stderr=STDOUT, shell=True)
921

1022
def log_subprocess_output(pipe):
1123
output = ""
12-
for line in iter(pipe.readline, b''):
24+
for line in iter(pipe.readline, b""):
1325
str_line = str(line)
1426
output += str_line
1527
logger(f"building -> {str_line}")
@@ -22,7 +34,8 @@ def log_subprocess_output(pipe):
2234

2335
return output
2436

37+
2538
if __name__ == "__main__":
2639
result = build_plugin("ExamplePlugin2")
2740
print(result)
28-
print(type(result))
41+
print(type(result))

config.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import yaml
22
from log_writer import logger
33

4+
45
def load_config():
56
"""
67
Loads the configuration from the 'config.yaml' file and sets the global variables accordingly.
@@ -15,10 +16,13 @@ def load_config():
1516
config_content = yaml.safe_load(conf)
1617
for key, value in config_content.items():
1718
if key == "GENERATE_MODEL" and value == "gpt-4":
18-
globals()[key] = "gpt-4-turbo-preview" # Force using gpt-4-turbo-preview if the user set the GENERATE_MODEL to gpt-4. Because gpt-4 is not longer supports json modes.
19+
globals()[
20+
key
21+
] = "gpt-4-turbo-preview" # Force using gpt-4-turbo-preview if the user set the GENERATE_MODEL to gpt-4. Because gpt-4 is not longer supports json modes.
1922
globals()[key] = value
2023
logger(f"config: {key} -> {value}")
2124

25+
2226
def edit_config(key, value):
2327
"""
2428
Edits the config file.
@@ -33,7 +37,7 @@ def edit_config(key, value):
3337

3438
with open("config.yaml", "r") as conf:
3539
config_content = conf.readlines()
36-
40+
3741
with open("config.yaml", "w") as conf:
3842
for line in config_content:
3943
if line.startswith(key):
@@ -42,7 +46,7 @@ def edit_config(key, value):
4246
elif value == False:
4347
write_value = "False"
4448
else:
45-
write_value = f"\"{value}\""
49+
write_value = f'"{value}"'
4650
if "#" in line:
4751
conf.write(f"{key}: {write_value} # {line.split('#')[1]}\n")
4852
else:
@@ -52,4 +56,5 @@ def edit_config(key, value):
5256

5357
return True
5458

55-
load_config()
59+
60+
load_config()

config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Recommend -> gpt-4-turbo (Better performance, more expensive), gpt-4-o (Good performance, cheaper)
77

88
API_KEY: "" # Free API Key with GPT-4 access: https://github.com/CubeGPT/.github/discussions/1
9-
BASE_URL: "https://api.openai.com/v1/chat/completions"
9+
BASE_URL: "https://api.openai.com/v1"
1010

1111
GENERATION_MODEL: "gpt-4-turbo-2024-04-09"
1212
FIXING_MODEL: "gpt-4-turbo-2024-04-09"

console.py

+43-21
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Get user inputs
2121
name = input("Enter the plugin name: ")
2222
description = input("Enter the plugin description: ")
23-
23+
2424
artifact_name = name.replace(" ", "")
2525
package_id = f"org.cubegpt.{uuid.uuid4().hex[:8]}"
2626

@@ -35,18 +35,25 @@
3535

3636
print("Generating plugin...")
3737

38-
codes = core.askgpt(config.SYS_GEN.replace("%ARTIFACT_NAME%", artifact_name).replace("%PKG_ID_LST%", pkg_id_path), config.USR_GEN.replace("%DESCRIPTION", description), config.GENERATION_MODEL)
38+
codes = core.askgpt(
39+
config.SYS_GEN.replace("%ARTIFACT_NAME%", artifact_name).replace(
40+
"%PKG_ID_LST%", pkg_id_path
41+
),
42+
config.USR_GEN.replace("%DESCRIPTION", description),
43+
config.GENERATION_MODEL,
44+
)
3945
logger(f"codes: {codes}")
4046

4147
core.response_to_action(codes)
4248

4349
print("Code generated. Building now...")
4450

45-
4651
result = build.build_plugin(artifact_name)
4752

4853
if "BUILD SUCCESS" in result:
49-
print(f"Build complete. Find your plugin at 'codes/{artifact_name}/target/{artifact_name}.jar'")
54+
print(
55+
f"Build complete. Find your plugin at 'codes/{artifact_name}/target/{artifact_name}.jar'"
56+
)
5057
elif "Compilation failure":
5158
print("Build failed. Passing the error to ChatGPT and let it to fix it?")
5259
fix = input("Y/n: ")
@@ -56,24 +63,31 @@
5663
else:
5764
print("Passing the error to ChatGPT...")
5865

59-
files = [f"codes/{artifact_name}/src/main/java/{pkg_id_path}Main.java",
60-
f"codes/{artifact_name}/src/main/resources/plugin.yml",
61-
f"codes/{artifact_name}/src/main/resources/config.yml",
62-
f"codes/{artifact_name}/pom.xml"]
63-
64-
ids = ["main_java",
65-
"plugin_yml",
66-
"config_yml",
67-
"pom_xml"]
68-
66+
files = [
67+
f"codes/{artifact_name}/src/main/java/{pkg_id_path}Main.java",
68+
f"codes/{artifact_name}/src/main/resources/plugin.yml",
69+
f"codes/{artifact_name}/src/main/resources/config.yml",
70+
f"codes/{artifact_name}/pom.xml",
71+
]
72+
73+
ids = ["main_java", "plugin_yml", "config_yml", "pom_xml"]
74+
6975
for file in files:
7076
with open(file, "r") as f:
7177
code = f.read()
7278
id = ids[files.index(file)]
7379
globals()[id] = code
74-
80+
7581
print("Generating...")
76-
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)
82+
codes = core.askgpt(
83+
config.SYS_FIX.replace("%ARTIFACT_NAME%", artifact_name),
84+
config.USR_FIX.replace("%MAIN_JAVA%", main_java)
85+
.replace("%PLUGIN_YML%", plugin_yml)
86+
.replace("%CONFIG_YML%", config_yml)
87+
.replace("%POM_XML%", pom_xml)
88+
.replace("%P_ERROR_MSG%", result),
89+
config.FIXING_MODEL,
90+
)
7791

7892
shutil.rmtree(f"codes/{artifact_name}")
7993
core.response_to_action(codes)
@@ -83,17 +97,25 @@
8397
result = build.build_plugin(artifact_name)
8498

8599
if "BUILD SUCCESS" in result:
86-
print(f"Build complete. Find your plugin at 'codes/{artifact_name}/target/{artifact_name}.jar'")
100+
print(
101+
f"Build complete. Find your plugin at 'codes/{artifact_name}/target/{artifact_name}.jar'"
102+
)
87103
else:
88-
print("Build failed. Please check the logs && send the log to @BaimoQilin on discord.")
104+
print(
105+
"Build failed. Please check the logs && send the log to @BaimoQilin on discord."
106+
)
89107
print("Exiting...")
90108
sys.exit(0)
91-
109+
92110
else:
93-
print("Unknown error. Please check the logs && send the log to @BaimoQilin on discord.")
111+
print(
112+
"Unknown error. Please check the logs && send the log to @BaimoQilin on discord."
113+
)
94114
print("Exiting...")
95115
sys.exit(0)
96116

97117

98118
else:
99-
print("Error: Please run console.py as the main program instead of importing it from another program.")
119+
print(
120+
"Error: Please run console.py as the main program instead of importing it from another program."
121+
)

0 commit comments

Comments
 (0)