Coder Social home page Coder Social logo

pair-programming-with-chatgpt's Introduction

Pair Programming with ChatGPT

This repository contains a Python notebook that demonstrates how to use the OpenAI API, particularly the ChatGPT model, as a pair-programming partner. The notebook provides various templates to interact with ChatGPT for different programming tasks such as improving existing code, exploring multiple ways to rewrite code, simplifying code, writing test cases, making code more efficient, and debugging.

Prerequisites

  • You need an API key from OpenAI. Store it in a .env file in the format:
OPENAI_API_KEY=sk-...

Dependencies

  • openai: For interacting with the OpenAI API.
  • tiktoken: To count how many tokens are in a text string without making an API call.
  • dotenv: To load environment variables from a .env file.
  • IPython: For displaying Markdown and other rich output formats in Jupyter.

How to Use

  1. Clone the repository.

  2. Install the required dependencies.

  3. Add your OpenAI API key to the .env file.

  4. Run the code:

    python pair_programmer/app.py

    You will get an output like this:

    Running on local URL:  http://127.0.0.1:7861
    
    To create a public link, set `share=True` in `launch()`.
    
  5. Open the URL in your browser.

Templates Provided

  1. Improve Existing Code: Provide a code snippet and get suggestions on how to improve it.
  2. Ask for Multiple Ways of Rewriting Your Code: Provide a code snippet and get multiple ways to achieve the same functionality.
  3. Recommend the Most Pythonic Way: Provide a code snippet and get the most Pythonic way to write it.
  4. Simplify Code: Provide a complex code snippet and get a simplified version of it.
  5. Write Test Cases: Provide a code snippet and get test cases for it.
  6. Make Code More Efficient: Provide a code snippet and get a more efficient version of it.
  7. Debug Code: Provide a buggy code snippet and get debugging help.
  8. Explain Code: Provide a code snippet and get a detailed explanation of how it works.
  9. Document Code: Provide a code snippet and get documentation for it.
  10. Write Docstrings: Provide a code snippet and get docstrings for the functions or classes.
  11. Optimize Code: Provide a code snippet and get an optimized version of it.
  12. Create Readme: Write a Readme.md file based on the pasted code.

Note

The notebook uses the gpt-4-0613 model from OpenAI for completions. You can change the model by modifying the model parameter in the get_completion function.

pair-programming-with-chatgpt's People

Watchers

Paul Glad Mihai avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.