Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alxschwrz/codex_py2cpp
Converts python code into c++ by using OpenAI CODEX.
https://github.com/alxschwrz/codex_py2cpp
ai code-generation codex cpp openai python
Last synced: 3 days ago
JSON representation
Converts python code into c++ by using OpenAI CODEX.
- Host: GitHub
- URL: https://github.com/alxschwrz/codex_py2cpp
- Owner: alxschwrz
- License: mit
- Created: 2022-05-15T16:07:22.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-10T07:39:55.000Z (4 months ago)
- Last Synced: 2024-08-03T23:24:05.612Z (4 months ago)
- Topics: ai, code-generation, codex, cpp, openai, python
- Language: Python
- Homepage:
- Size: 31.3 KB
- Stars: 490
- Watchers: 15
- Forks: 46
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-codex - Converting Python code to C++
README
🦾 codex_py2cpp 🤖
OpenAI Codex Python to C++ Code GeneratorYour Python Code is too slow? 🐌
You want to speed it up but forgot how to code in C++? ⌨
Convert your Python script to C++ Code using OpenAI Codex.## How it works
Reads a Python file and creates an input prompt which is then fed to OpenAI Codex to generate corresponding C++ code. The generated
code is getting compiled using g++ and if compilation is successful the executable is saved.To generate your own files you need to get access to the Codex API (https://openai.com/blog/openai-codex/).
## Installation
```bash
git clone https://github.com/alxschwrz/codex_py2cpp.git
cd codex_py2cpp
pip3 install -r requirements.txt
```
## Run example
Reads the file "simpleScript.py", and feeds the corresponding input prompt to OpenAI Codex. Compilable solutions
are stored in the form of .cpp and .exe files.
```
python3 python2cppconverter.py
```If the generated C++ code got compiled, test it with
```
./simpleScript.exe
```
You hopefully get the same output as when running
```
python3 simpleScript.py
```
Check how much faster you are now ...
```
time ./simpleScript.exe
time python3 simpleScript.py
```### Example Code Generation:
[In]: Python Snippet
[Out]: How the CODEX conversion might look like```python
def add_something(x, y):
print("casually adding some stuff together")
z = x + y
return zif __name__ == "__main__":
print('Okay, lets go')
print(add_something(5, 2))
``````cpp
// C++ Code generated from Python Code:
#include
using namespace std;int add_something(int x, int y) {
cout << "casually adding some stuff together" << endl;
int z = x + y;
return z;
}int main() {
cout << "Okay, lets go" << endl;
cout << add_something(5, 2) << endl;
return 0;
}
```Please test your generated code before usage. This does not produce robust code conversions, but is intended to experiment with codex. [WIP]
## CreditsThis project is based on the OpenAI Codex project.
Inspired by https://github.com/tom-doerr