|
@@ -2,24 +2,38 @@
|
|
|
|
|
|
This is a [GNU Guile][guile] client for the [OpenAI API][openai-api].
|
|
|
It currently implements the Chat and Image APIs, with support for chat
|
|
|
-response streaming and inline image display in a [Geiser][geiser] REPL.
|
|
|
+response streaming and inline image display in a [Geiser][geiser]
|
|
|
+REPL.
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
-A [GNU Guix][guix] package definition is provided in the repository, so
|
|
|
-you can install it into your profile with the following:
|
|
|
+### Guix
|
|
|
+
|
|
|
+An up-to-date [GNU Guix][guix] package definition is provided in the
|
|
|
+repository, so you can install it into your profile with the
|
|
|
+following:
|
|
|
|
|
|
```shell
|
|
|
guix package -f path/to/guile-openai/guix.scm
|
|
|
```
|
|
|
|
|
|
-Alternatively, you can jump straight into an interactive environment by
|
|
|
-loading it with [Guile Studio][guile-studio]:
|
|
|
+Alternatively, you can jump straight into an interactive environment
|
|
|
+by loading it with [Guile Studio][guile-studio]:
|
|
|
|
|
|
```shell
|
|
|
guix shell guile guile-studio -f path/to/guile-openai/guix.scm -- guile-studio
|
|
|
```
|
|
|
|
|
|
+### Autotools
|
|
|
+
|
|
|
+A conventional build system is also provided:
|
|
|
+
|
|
|
+``` shell
|
|
|
+cd path/to/guile-openai
|
|
|
+./bootstrap
|
|
|
+./configure && make
|
|
|
+```
|
|
|
+
|
|
|
## Documentation
|
|
|
|
|
|
### Quick start
|
|
@@ -110,8 +124,8 @@ ultimately the OpenAI API is a paid service.
|
|
|
Send a chat completion request. Returns a *chat* record.
|
|
|
|
|
|
The *prompt* can be a string, which will be sent as a user message.
|
|
|
- Alternatively, prompt can be a list of `(role . content)` pairs, where
|
|
|
- content is a string and role is a symbol `system`, `user`, or
|
|
|
+ Alternatively, prompt can be a list of `(role . content)` pairs,
|
|
|
+ where content is a string and role is a symbol `system`, `user`, or
|
|
|
`assistant`.
|
|
|
|
|
|
The keyword arguments correspond to the request parameters described
|
|
@@ -129,7 +143,7 @@ ultimately the OpenAI API is a paid service.
|
|
|
|
|
|
A symbol or string identifying the model to use. Defaults to
|
|
|
`gpt-3.5-turbo`, but if you're lucky you might be able to use
|
|
|
- `gpt-4` here.
|
|
|
+ `gpt-4` or `gpt-4-32k` here.
|
|
|
|
|
|
- `#:temperature`
|
|
|
|
|
@@ -191,27 +205,54 @@ ultimately the OpenAI API is a paid service.
|
|
|
|
|
|
- `#:size`
|
|
|
|
|
|
- A number specifying the generated image size, either 256, 512, or 1024.
|
|
|
- The symbols `256x256`, `512x512` and `1024x1024` are also supported.
|
|
|
+ A number specifying the generated image size, either 256, 512,
|
|
|
+ or 1024. The symbols `256x256`, `512x512` and `1024x1024` are
|
|
|
+ also supported.
|
|
|
|
|
|
- `#:format`
|
|
|
|
|
|
- How the image data will be returned, either `url` (hosted on a cloud
|
|
|
- server), or `b64` (embedded in the response message, the default).
|
|
|
- In either case, the image data will be fetched and stored locally
|
|
|
- for display.
|
|
|
+ How the image data will be returned, either `url` (hosted on a
|
|
|
+ cloud server), or `b64` (embedded in the response message, the
|
|
|
+ default). In either case, the image data will be fetched and
|
|
|
+ stored locally for display.
|
|
|
|
|
|
- `#:user`
|
|
|
|
|
|
An optional username to associate with this request.
|
|
|
|
|
|
+- (**openai-image-edit** image prompt *[keyword arguments]*)
|
|
|
+
|
|
|
+ Send an image edit request. Returns an *image* record.
|
|
|
+
|
|
|
+ The *image* can be an *image* record or a string path to the image
|
|
|
+ file to be varied. The API requires the image to be a valid PNG
|
|
|
+ file, less than 4MB, and square.
|
|
|
+
|
|
|
+ The *prompt** must be a string describing the changes to be made to
|
|
|
+ the image.
|
|
|
+
|
|
|
+ The keyword arguments correspond to the request parameters described
|
|
|
+ in the [image edit request][image-edit-request] documentation:
|
|
|
+
|
|
|
+ - `#:mask`
|
|
|
+
|
|
|
+ An *image* record or a string path to an image file to use as the
|
|
|
+ edit mask. The model will only edit pixels which are fully
|
|
|
+ transparent (ie. alpha 0) in the mask image. The mask must have the
|
|
|
+ same dimensions as IMAGE. The default is fully opaque, so no pixels
|
|
|
+ will be edited and a copy of the original image will be returned.
|
|
|
+
|
|
|
+ - `#:n`, `#:size`, `#:format`, `#:user`
|
|
|
+
|
|
|
+ See `openai-image`.
|
|
|
+
|
|
|
- (**openai-image-variation** image *[keyword arguments]*)
|
|
|
|
|
|
Send an image variation request. Returns an *image* record.
|
|
|
|
|
|
The *image* can be an *image* record or a string path to the image
|
|
|
- file to be varied. The API requires the image to be a valid PNG file,
|
|
|
- less than 4MB, and square.
|
|
|
+ file to be varied. The API requires the image to be a valid PNG
|
|
|
+ file, less than 4MB, and square.
|
|
|
|
|
|
The keyword arguments correspond to the request parameters described
|
|
|
in the [image variation request][image-variation-request]
|
|
@@ -273,22 +314,130 @@ ultimately the OpenAI API is a paid service.
|
|
|
|
|
|
The embedding vector generated by the model.
|
|
|
|
|
|
+### Text Edit API
|
|
|
+
|
|
|
+- (**openai-text-edit** input instruction *[keyword arguments]*)
|
|
|
+
|
|
|
+ Send an edit request. Returns an *edit* record.
|
|
|
+
|
|
|
+ The *input* must be a string, which is the text to be edited. The
|
|
|
+ *instruction* is a string describing the changes to be made.
|
|
|
+
|
|
|
+ The keyword arguments correspond to the request parameters described
|
|
|
+ in the [edit request][edit-request] documentation:
|
|
|
+
|
|
|
+ - `#:model`
|
|
|
+
|
|
|
+ A symbol or string identifying the model to use. Defaults to
|
|
|
+ `text-davinci-edit-001`.
|
|
|
+
|
|
|
+ - `#:n`
|
|
|
+
|
|
|
+ The number of responses to generate, returned as multiple values.
|
|
|
+
|
|
|
+ - `#:temperature`
|
|
|
+
|
|
|
+ The sampling temperature to use, a number between 0 and 2.
|
|
|
+
|
|
|
+ - `#:top-p`
|
|
|
+
|
|
|
+ An alternative sampling parameter, a number between 0 and 1.
|
|
|
+
|
|
|
+- (**openai-code-edit** input instruction *[keyword arguments]*)
|
|
|
+
|
|
|
+ Identical to `openai-text-edit`, except it defaults to the
|
|
|
+ `code-davinci-edit-001` model.
|
|
|
+
|
|
|
+- (**openai-default-text-edit-model** 'text-davinci-edit-001)
|
|
|
+
|
|
|
+ Parameter for the default `#:model` value (text edit).
|
|
|
+
|
|
|
+- (**openai-default-text-edit-temperature** *unspecified*)
|
|
|
+
|
|
|
+ Parameter for the default `#:temperature` value (text edit).
|
|
|
+
|
|
|
+- (**openai-default-text-edit-top-p** *unspecified*)
|
|
|
+
|
|
|
+ Parameter for the default `#:top-p` value (text edit).
|
|
|
+
|
|
|
+- (**openai-default-code-edit-model** 'code-davinci-edit-001)
|
|
|
+
|
|
|
+ Parameter for the default `#:model` value (code edit).
|
|
|
+
|
|
|
+- (**openai-default-code-edit-temperature** *unspecified*)
|
|
|
+
|
|
|
+ Parameter for the default `#:temperature` value (code edit).
|
|
|
+
|
|
|
+- (**openai-default-code-edit-top-p** *unspecified*)
|
|
|
+
|
|
|
+ Parameter for the default `#:top-p` value (code edit).
|
|
|
+
|
|
|
+- (**edit?** edit)
|
|
|
+
|
|
|
+ Type predicate for edit responses.
|
|
|
+
|
|
|
+- (**edit-content** edit)
|
|
|
+
|
|
|
+ The edited content generated by the model.
|
|
|
+
|
|
|
+### Moderation API
|
|
|
+
|
|
|
+- (**openai-moderation** input *[keyword arguments]*)
|
|
|
+
|
|
|
+ Send a moderation request. Returns a *moderation* record.
|
|
|
+
|
|
|
+ The *input* must be a string to be classified by the moderation
|
|
|
+ model.
|
|
|
+
|
|
|
+ The keyword arguments correspond to the request parameters described
|
|
|
+ in the [moderation request][moderation-request] documentation:
|
|
|
+
|
|
|
+ - `#:model`
|
|
|
+
|
|
|
+ A symbol or string identifying the model to use. The default is
|
|
|
+ `*unspecified*`, which is equivalent to `text-moderation-latest`.
|
|
|
+
|
|
|
+- (**openai-default-moderation-model** *unspecified*)
|
|
|
+
|
|
|
+ Parameter for the default `#:model value`.
|
|
|
+
|
|
|
+- (**moderation?** moderation)
|
|
|
+
|
|
|
+ Type predicate for moderation responses.
|
|
|
+
|
|
|
+- (**moderation-flagged?** moderation)
|
|
|
+
|
|
|
+ Whether the content was in violation of OpenAI's content policy.
|
|
|
+
|
|
|
+- (**moderation-categories** moderation)
|
|
|
+
|
|
|
+ The list of categories which caused this content to be flagged.
|
|
|
+
|
|
|
+- (**moderation-scores** moderation)
|
|
|
+
|
|
|
+ An association list of the scores for this content in each category.
|
|
|
+
|
|
|
+- (**moderation-score** moderation category)
|
|
|
+
|
|
|
+ The moderation score for this content in the specified category.
|
|
|
+
|
|
|
## License
|
|
|
|
|
|
Copyright © 2023 Andrew Whatson <whatson@tailcall.au>
|
|
|
|
|
|
-guile-openai is free software: you can redistribute it and/or modify it
|
|
|
-under the terms of the GNU Affero General Public License as published by
|
|
|
-the Free Software Foundation, either version 3 of the License, or (at
|
|
|
-your option) any later version.
|
|
|
+guile-openai is free software: you can redistribute it and/or modify
|
|
|
+it under the terms of the GNU Affero General Public License as
|
|
|
+published by the Free Software Foundation, either version 3 of the
|
|
|
+License, or (at your option) any later version.
|
|
|
|
|
|
guile-openai is distributed in the hope that it will be useful, but
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
|
|
|
-General Public License for more details.
|
|
|
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
+Affero General Public License for more details.
|
|
|
|
|
|
-You should have received a copy of the GNU Affero General Public License
|
|
|
-along with guile-openai. If not, see <https://www.gnu.org/licenses/>.
|
|
|
+You should have received a copy of the GNU Affero General Public
|
|
|
+License along with guile-openai. If not, see
|
|
|
+<https://www.gnu.org/licenses/>.
|
|
|
|
|
|
See [COPYING](COPYING) for details.
|
|
|
|
|
@@ -299,5 +448,10 @@ See [COPYING](COPYING) for details.
|
|
|
[guix]: https://guix.gnu.org/
|
|
|
[chat-request]: https://platform.openai.com/docs/api-reference/chat/create
|
|
|
[image-request]: https://platform.openai.com/docs/api-reference/images/create
|
|
|
+[image-edit-request]:
|
|
|
+https://platform.openai.com/docs/api-reference/images/create-edit
|
|
|
[image-variation-request]: https://platform.openai.com/docs/api-reference/images/create-variation
|
|
|
[embedding-request]: https://platform.openai.com/docs/api-reference/embeddings
|
|
|
+[moderation-request]: https://platform.openai.com/docs/api-reference/moderations
|
|
|
+[edit-request]:
|
|
|
+https://platform.openai.com/docs/api-reference/edits
|