◐ GPT-Migrate ◑
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
**Easily migrate your codebase from one framework or language to another.**
If you've ever faced the pain of migrating a codebase to a new framework or language, this project is for you.
https://user-images.githubusercontent.com/25165841/250232917-bcc99ce8-99b7-4e3d-a653-f89e163ed825.mp4
Migration is a costly, tedious, and non-trivial problem. Do not trust the current version blindly and please use responsibly. Please also be aware that costs can add up quickly as GPT-Migrate is designed to write (and potentially re-write) the entirety of a codebase.
However, with the collective brilliance of the OSS community and the current state of LLMs, it is also a very tractable problem.
⚡️ Usage
1. Install Docker and ensure that it's running. It's also recommended that you use at least GPT-4, preferably GPT-4-32k.
📦 Installation using Poetry
1. Install Poetry by following the instructions on the official Poetry website.
2. Once Poetry is installed, navigate to the project directory and install the project dependencies using the following command:
This will create a virtual environment and install all the necessary dependencies in that environment.
2. Set your OpenRouter API key (default) and/or your OpenAI API key (to use the OpenAI API directly...in this case, set --model to gpt-4-32k or your desired model) and install the python requirements:
export OPENROUTER_API_KEY=
export OPENAI_API_KEY=
pip install -r requirements.txt
3. Run the main script with the target language you want to migrate to:
python main.py --targetlang nodejs
4. (Optional) If you'd like GPT-Migrate to validate the unit tests it creates against your app before it tests the migrated app with them, please have your existing app exposed and use the --sourceport flag. For executing this against the benchmark, open a separate terminal, navigate to the benchmarks/language-pair/source directory, and run python app.py after installing the requirements. It will expose on port 5000. Use this with the --sourceport flag.
By default, this script will execute the flask-nodejs benchmark. You can specify the language, source directory, and many other things using the options guide below.
💡 Options
You can customize the behavior of GPT-Migrate by passing the following options to the main.py script:
- --model: The Large Language Model to be used. Default is "gpt-4-32k".
- --temperature: Temperature setting for the AI model. Default is 0.
- --sourcedir: Source directory containing the code to be migrated. Default is "../benchmarks/flask-nodejs/source".
- --sourcelang: Source language or framework of the code to be migrated. No default value.
- --sourceentry: Entrypoint filename relative to the source directory. For instance, this could be an app.py or main.py file for Python. Default is "app.py".
- --targetdir: Directory where the migrated code will live. Default is "../benchmarks/flask-nodejs/target".
- --targetlang: Target language or framework for migration. Default is "nodejs".
- --operating_system: Operating system for the Dockerfile. Common options are 'linux' or 'windows'. Default is 'linux'.
- --testfiles: Comma-separated list of files that have functions to be tested. For instance, this could be an app.py or main.py file for a Python app where your REST endpoints are. Include the full relative path. Default is "app.py".
- --sourceport: (Optional) Port for testing the unit tests file against the original app. No default value. If not included, GPT-Migrate will not attempt to test the unit tests against your original app.
- --targetport: Port for testing the unit tests file against the migrated app. Default is 8080.