Skip to content

Latest commit

 

History

History
132 lines (94 loc) · 4.5 KB

README.md

File metadata and controls

132 lines (94 loc) · 4.5 KB

License: GPL v3 JCS-ELPA

OpenAI.el

Elisp library for the OpenAI API

CI

The OpenAI Elisp library provides convenient access to the OpenAI API from applications written in the Elips language.

P.S. This package is expected to be used as a library, so there are only a few interactable commands you can use, and those are mostly examples.

📚 Documentation

Table of Contents

🔨 Usage

You will need to set up your API key before you can use this library.

(setq openai-key "[YOUR API KEY]")

The simplest example

Here is the simplest example that teaches you how to use this library. This is a function with a query and a callback function.

(openai-completion "How are you?"
                   (lambda (data)
                     (message "%s" data)))

📝 Customization

Most arguments are extracted (excepts the required one) as global variables. For example, one variable openai-completon-n is defined in openai-completion.el file. That variable is used for the completion request, for more information see https://beta.openai.com/docs/api-reference/completions. The naming convention is by the following pattern:

[PACKAGE NAME]-[API TYPE]-[NAME OF THE ARGUMENT]

For example:

(setq openai-edit-temperature 1)
  • openai - is the package name
  • edit - is the api type, see OpenAI API reference
  • temperature - is the argument for the Edit request.

You can change the model for a single request without changing its global value.

(let ((openai-edit-model "text-davinci-edit-001")  ; use another model for this request,
      (openai-edit-n 3))                           ; and i want three outcomes
  (openai-edit-create "What day of the wek is it?"
                      "Fix the spelling mistakes"
                      (lambda (data)
                        (message "%s" data))))

📢 API functions

The API functions are followed by this pattern:

[PACKAGE NAME]-[API TYPE]-[REQUEST NAME]

For example:

(openai-file-list ...)
  • openai - is the package name
  • file - is the api type, see OpenAI API reference
  • list - is the request name

🖥 Setting Model

You can also choose which model you want to use by going to the api website and looking at the id's. For code usage you probably want something that starts with code- whereas with more text related files you'll likely want something starting with text-.

(setq openai-completion-model "NAME-HERE")

🔗 References

Contribute

PRs Welcome Elisp styleguide Donate on paypal Become a patron

If you would like to contribute to this project, you may either clone and make pull requests to this repository. Or you can clone the project and establish your own branch of this tool. Any methods are welcome!