Skip to content

liyangguang/gpt-tdd

Repository files navigation

GPT TDD

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.

How it works

  1. In TDD, we write all the tests first, and modify the code to make it pass all tests.
  2. 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.
  3. It runs the tests, and takes in the failure message and the current code, then modify the code. And repeat this process.
  4. After a few iterations, GPT finishes the code that passes all tests.

File structure

  • /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.

How to use it

screen recording the steps

  1. Create a .env based on .example.env, and add your OpenAPI API key.
  2. Open /tests/index.test.ts, and write any tests you want for your function.
  3. Optionally, you can go to /gpt/index.ts to tweak the 2 parameters.
  4. Run npm start (run npm i first if haven't). GPT will run the process described above.
  5. After it's finished, your function will be in /ouput/result.ts. (Or failure message)

More

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!

About

Use GPT on TDD, to automate coding.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published