CodeAI (CAI) is a Python program designed to optimize and enhance your C/C++ code. It leverages Large Language Models (LLMs) to automate code transformations, ensuring that the output code maintains its compilability, correctness, and performance. It can interact with Google BARD, OpenAI's GPT, and Microsoft Bing APIs.
BARD API is not currently supported in Sweden.
-
Automated Code Optimization: CAI utilizes AI to refactor and optimize your existing code, potentially leading to more efficient and performant output.
-
Compilability Assurance: The transformed code is ensured to be compilable.
-
Correctness Verification: CAI verifies the functional equivalence of the original and transformed codes.
-
Performance Measurement: The application benchmarks and compares the performance of the original and transformed code, ensuring that the changes have improved performance.
You can use the application by running the following command:
cai-run -i <input_file> -o <output_file> -t <task> -l <language> -a <AI API> -c -comp <compiler>
Where:
<input_file>
is the path to the original code.<output_file>
is the path where the transformed code will be saved.<task>
is the task you want the AI to perform on the code.<language>
can be either C or C++.<AI API>
is the name of the AI API to use; it can be BARD, GPT, or BING.<compiler>
is the compiler to use for checking the compilability of the code, it can be gcc or g++. For example:
cai-run -i examples/2sum.cpp -o test.cpp -t "Improve the performance of the code and use the same main function as the original code" -l C++ -a BARD -c -comp gcc
Alternatively, you can also run python cai.py
.
Note that you need to export _BARD_API_KEY
and OPENAI_API_KEY
variables in your operating system in order to use Bard and OpenAI's GPT. You can run the following command or add it to .bashrc
or .zshrc
:
export _BARD_API_KEY="bard_api_key"
export OPENAI_API_KEY="openai_api_key"
To use Bing, you should save the cookies in the bing_cookies_1.json
. Check Get API Key section for more information.
Check the following links for different LLMs:
- bardapi: https://github.com/dsdanielpark/Bard-API/blob/main/assets/bard_api.gif
- openai: https://platform.openai.com/account/api-keys
- EdgeGPT: https://github.com/acheong08/EdgeGPT#chatbot
You can test different classes by running the test units in the `tests/ folder, similar to the following command:
python -m unittest test_ai_interface.py
TODO: Currently, they are not working properly.
You can build a python package using the following command:
python setup.py sdist bdist_wheel
or
pip install .
CodeAI is released under the GPL 3.0 License.