|
|
@@ -0,0 +1,142 @@
|
|
|
+import os
|
|
|
+from openai import OpenAI
|
|
|
+
|
|
|
+def identify_gradle_files(project_path):
|
|
|
+ gradle_files = []
|
|
|
+ for root, dirs, files in os.walk(project_path):
|
|
|
+ for file in files:
|
|
|
+ if file.endswith('.gradle'):
|
|
|
+ gradle_files.append(os.path.join(root, file))
|
|
|
+ return gradle_files
|
|
|
+
|
|
|
+def read_gradle_file(gradle_file_path):
|
|
|
+ with open(gradle_file_path, 'r') as file:
|
|
|
+ content = file.readlines()
|
|
|
+ return content
|
|
|
+
|
|
|
+def update_gradle_config_moudle(path):
|
|
|
+ client = OpenAI(
|
|
|
+ base_url='https://xiaoai.plus/v1',
|
|
|
+ api_key='sk-locN2LBEu7eEPV6NT3822YJhTAe0TSXMkzzM90cmALL3tsVI'
|
|
|
+ )
|
|
|
+ prompt = """
|
|
|
+ ## Configuration Requirements
|
|
|
+
|
|
|
+ ### 1. Change ndkVersion to "23.2.0" if ndkVersion exists
|
|
|
+
|
|
|
+ ### 2. Configure ABI Filters
|
|
|
+ - **Instruction**: Add the `abiFilters` configuration to the `externalNativeBuild` block within the 'defaultConfig' of `android` section.
|
|
|
+ - **Example Code**:
|
|
|
+ ```gradle
|
|
|
+ android {
|
|
|
+ // Other configurations...
|
|
|
+
|
|
|
+ externalNativeBuild {
|
|
|
+ ndk {
|
|
|
+ abiFilters 'riscv64'
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Other configurations...
|
|
|
+ }
|
|
|
+
|
|
|
+ ### 5. Do not change others if the Requirements do not mention
|
|
|
+
|
|
|
+ ### 6. Do not add anything that do not mention
|
|
|
+ """
|
|
|
+
|
|
|
+ text = ""
|
|
|
+
|
|
|
+ with open(path, 'r', encoding='utf-8') as file:
|
|
|
+ text = file.read()
|
|
|
+
|
|
|
+ direct = "请你直接将修改后的文件输出,除此之外不用其他描述"
|
|
|
+
|
|
|
+ completion = client.chat.completions.create(
|
|
|
+ model="gpt-3.5-turbo",
|
|
|
+ messages=[
|
|
|
+ {"role": "system", "content": "You are an AI assistant tasked with updating Gradle configuration files for a project. The goal is to ensure that the project is set up correctly with the specified configurations."},
|
|
|
+ {"role": "system", "content": prompt},
|
|
|
+ {"role": "user", "content": text + direct}
|
|
|
+ ]
|
|
|
+ )
|
|
|
+
|
|
|
+ content = completion.choices[0].message.content
|
|
|
+
|
|
|
+ with open(path, 'w', encoding='utf-8') as file:
|
|
|
+ file.write(content)
|
|
|
+
|
|
|
+ with open(path, 'r', encoding='utf-8') as file:
|
|
|
+ new_content = file.read()
|
|
|
+
|
|
|
+ new_content = new_content.replace("gradle\n", "")
|
|
|
+ new_content = new_content.replace("```", "")
|
|
|
+
|
|
|
+ with open(path, 'w', encoding='utf-8') as file:
|
|
|
+ file.write(new_content)
|
|
|
+
|
|
|
+def update_gradle_config_project(path):
|
|
|
+ client = OpenAI(
|
|
|
+ base_url='https://xiaoai.plus/v1',
|
|
|
+ api_key='sk-locN2LBEu7eEPV6NT3822YJhTAe0TSXMkzzM90cmALL3tsVI'
|
|
|
+ )
|
|
|
+ prompt = """
|
|
|
+ ## Configuration Requirements
|
|
|
+
|
|
|
+ ### 1. Update Gradle Plugin Version
|
|
|
+ - **Instruction**: If the `buildscript` exit, Set the Gradle plugin version to `com.android.tools.build:gradle:7.4.0-dev` and ensure the plugin path is correctly specified in the environment.
|
|
|
+
|
|
|
+ ### 2. Change ndkVersion to "23.2.0" if ndkVersion exists
|
|
|
+
|
|
|
+ ### 3. Configure the Local Maven Repository
|
|
|
+ - **Instruction**: If the file does not contain 'buildscript' and 'allprojects' sections, skip this rule.Add the "maven { url 'C:\\Users\\zh907\\AppData\\Local\\Android\\plugin\\repo' }" configuration to 'repositories' part of the `buildscript` and `allprojects` sections of the Gradle file.
|
|
|
+
|
|
|
+ ### 4. Do not change others if the Requirements do not mention
|
|
|
+
|
|
|
+ ### 5. Do not add 'buildscript' part if the file do not have
|
|
|
+ """
|
|
|
+
|
|
|
+ text = ""
|
|
|
+
|
|
|
+ with open(path, 'r', encoding='utf-8') as file:
|
|
|
+ text = file.read()
|
|
|
+
|
|
|
+ direct = "请你直接将修改后的文件输出,除此之外不用其他描述"
|
|
|
+
|
|
|
+ completion = client.chat.completions.create(
|
|
|
+ model="gpt-3.5-turbo",
|
|
|
+ messages=[
|
|
|
+ {"role": "system", "content": "You are an AI assistant tasked with updating Gradle configuration files for a project. The goal is to ensure that the project is set up correctly with the specified configurations."},
|
|
|
+ {"role": "system", "content": prompt},
|
|
|
+ {"role": "user", "content": text + direct}
|
|
|
+ ]
|
|
|
+ )
|
|
|
+
|
|
|
+ content = completion.choices[0].message.content
|
|
|
+
|
|
|
+ with open(path, 'w', encoding='utf-8') as file:
|
|
|
+ file.write(content)
|
|
|
+
|
|
|
+ with open(path, 'r', encoding='utf-8') as file:
|
|
|
+ new_content = file.read()
|
|
|
+
|
|
|
+ new_content = new_content.replace("gradle\n", "")
|
|
|
+ new_content = new_content.replace("```", "")
|
|
|
+
|
|
|
+ with open(path, 'w', encoding='utf-8') as file:
|
|
|
+ file.write(new_content)
|
|
|
+
|
|
|
+def main():
|
|
|
+ project_path = input("请输入项目路径:")
|
|
|
+ gradle_files = identify_gradle_files(project_path)
|
|
|
+ print("项目中的Gradle文件:")
|
|
|
+ for file in gradle_files:
|
|
|
+ print(file)
|
|
|
+ if file == project_path + '\\build.gradle':
|
|
|
+ update_gradle_config_project(file)
|
|
|
+ elif file.endswith('build.gradle'):
|
|
|
+ update_gradle_config_moudle(file)
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ main()
|