Giter VIP home page Giter VIP logo

openai-cli's Introduction

ChatGPT CLI Tool

This CLI tool allows you to send a prompt to OpenAI's GPT-4 model and receive a response directly from the command line. It uses axios for HTTP requests, yargs for command line argument parsing, and dotenv for environment variable management.

Prerequisites

  • Node.js
  • npm (Node Package Manager)
  • OpenAI API key

Installation

1.) Clone the repository:

git clone https://github.com/yourusername/chatgpt-cli-tool.git
cd chatgpt-cli-tool

2.) Install the required dependencies:

npm install

3.) Create a .env file in the root directory and add your OpenAI API key:

OPENAI_API_KEY=your_openai_api_key_here

Usage

To use the CLI tool, run the following command in this format:

node index.js -p "Enter prompt here"

Example

node index.js -p "Explain the concept of recursion in computer science."

Command Line Options

-p, --prompt: The prompt to send to ChatGPT. This option is required. -h, --help: Show help information.

Sample Output

Response from ChatGPT:
Choice 1: Recursion in computer science is a method where the solution to a problem depends on solutions to smaller instances of the same problem. A recursive function calls itself with modified parameters, allowing the problem to be solved in a step-by-step    manner until a base case is reached.

Error Handling

If the OpenAI API key is not found in the environment variables, the tool will display the following error message and exit:

OpenAI API key not found. Set the OPENAI_API_KEY environment variable.

If there's an error querying the OpenAI API, the tool will display the error message and exit:

Error querying OpenAI: [Detailed error message]

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request. Would like to ideally have a frontend GUI at some point.

openai-cli's People

Contributors

nullvaluez 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.