Elisp library for the OpenAI API
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.
Table of Contents
You will need to set up your API key before you can use this library.
(setq openai-key "[YOUR API KEY]")
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)))
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 nameedit
- is the api type, see OpenAI API referencetemperature
- 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))))
The API functions are followed by this pattern:
[PACKAGE NAME]-[API TYPE]-[REQUEST NAME]
For example:
(openai-file-list ...)
openai
- is the package namefile
- is the api type, see OpenAI API referencelist
- is the request name
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")
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!