Coder Social home page Coder Social logo

chatgptscript's Introduction

chatGPTscript

A straight-forward python script to communicate with openAI API using a command line interface to retrieve responses from the text-davinci-003 model.

Install

In order to use this program make sure to clone this repository into your desired directory using gh repo clone Vincent881909/chatGPTscript. Cotinue to install the necessary libraries by running:

pip install -r requirements.txt

Make sure to set your API key as a environment variable called OPENAI_KEY. This serves for confidentiality reasons. In order to generate a API key visit this link. We also want to to create an alias in order to run the script from anywhere in the terminal to allow for quick access. To set a environment variable and creating a alias (depedning on your shell) write to .zshrc or .bashrc file. Run nano ~/.zshrc to open the editor and then export your API key and create an alias:

export OPENAI_KEY='INSERT_YOUR_KEY_HERE'
alias chatgpt='python3 PATH/TO/YOUR/SCRIPT.py'

Make sure to save the changes with control + o to write to the file and press enter to confirm. Exit the editor with control + x. To execute the content of the file run source ~/.zshrc. Now you will be able to run the program from any directory. Refer to Usage to get an indea on how to use it.

Usage

You have two options when it comes to providing the program with your prompt:

  • Single response by providing your prompt as a program argument
  • Loop that continously asks for your input

If you provide a prompt as a program argument the program will return a single response and exit. You can run chatgpt YOUR_PROMPT and the program will return your single response and exit. Note here, that your prompt cannot contain a '?' since the character is a special character in the terminal. It is used to signify a wildcard character, which means it can be used to represent any character or set of characters in a string. Therefore, it cannot be used as a program argument. This script adjusted the response tokens so it works well with short responses. For example, if you want to know how to write to a file in the terminal you could run chatgpt How do I write to a file in the terminal. Or perhaps you want to create a function to convert a string to lowercase. You could run chatgpt Create a function in c++ that converts a string to all lowercase .

If no program arguments are provided, the program will continue to ask for your input until you hit 'q' which will exit the program. Please also note that the generated response will be copied to your clipboard in case you need to quickly paste it elsewhere.

Please bare in mind that the openAI API is not free and has limited usage before you get billed. Refer to openai for more info.

chatgptscript's People

Contributors

vincent881909 avatar

Watchers

 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.