An experiment to use GPT on Test-Driven-Development.
Write what you expect the code to do, GPT generate code to pass all your tests.
- In TDD, we write all the tests first, and modify the code to make it pass all tests.
- In this repo, we do the same - write tests first, and "write" code to pass all tests. The main difference is we don't write the code, GPT does.
- It runs the tests, and takes in the failure message and the current code, then modify the code. And repeat this process.
- After a few iterations, GPT finishes the code that passes all tests.
/src
/tests
: The tests to pass. You need to write these./output/result.ts
(gitignore): The result code from GPT./gpt
: The core of this repo. Contains code that does the process above.
- Create a
.env
based on.example.env
, and add your OpenAPI API key. - Open
/tests/index.test.ts
, and write any tests you want for your function. - Optionally, you can go to
/gpt/index.ts
to tweak the 2 parameters. - Run
npm start
(runnpm i
first if haven't). GPT will run the process described above. - After it's finished, your function will be in
/ouput/result.ts
. (Or failure message)
If you want to be adventurous, or being lazy to write tests, check out my package AI-function-js - where you only need to describe what to do, it will just run for you, even without creating any code!