Code Monkey home page Code Monkey logo

openai-cli's Introduction

OpenAI command-line client

Installation

To install OpenAI CLI in Python virtual environment, run:

pip install openai-cli

Token authentication

OpenAI API requires authentication token, which can be obtained on this page: https://beta.openai.com/account/api-keys

Provide token to the CLI either through a command-line argument (-t/--token <TOKEN>) or through an environment variable (OPENAI_API_TOKEN).

Usage

Currently only text completion API is supported.

Example usage:

$ echo "Are cats faster than dogs?" | openai complete -
It depends on the breed of the cat and dog. Generally,
cats are faster than dogs over short distances,
but dogs are better at sustained running.

Interactive mode supported (Press Ctrl+C to exit):

$ openai repl
Prompt: Can generative AI replace humans?

No, generative AI cannot replace humans.
While generative AI can be used to automate certain tasks,
it cannot replace the creativity, intuition, and problem-solving
skills that humans possess.
Generative AI can be used to supplement human efforts,
but it cannot replace them.

Prompt: ^C

Run without arguments to get a short help message:

$ openai
Usage: openai [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  complete  Return OpenAI completion for a prompt from SOURCE.
  repl      Start interactive shell session for OpenAI completion API.

Build a standalone binary using pex and move it into PATH:

$ make openai && mv openai ~/bin/
$ openai repl
Prompt:

Alternative API URL

CLI invokes https://api.openai.com/v1/completions by default. To override the endpoint URL, set OPENAI_API_URL environment variable.

Example usage

Here's an example usage scenario, where we first create a Python module with a Fibonacci function implementation, and then generate a unit test for it:

openai-cli's People

Contributors

abravalheri avatar azhx avatar bhrutledge avatar darkvertex avatar hugovk avatar jaraco avatar kolanich avatar peterdemin avatar unosd avatar webknjaz avatar wimglenn avatar zacharyburnett 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.