27 lines
933 B
Common Lisp
27 lines
933 B
Common Lisp
(in-package #:cl-openai)
|
|
|
|
(defvar +openai-base-uri+ "api.openai.com")
|
|
|
|
;; How to remove this "REMOVE NIL" instruction? I'm pretty sure I've
|
|
;; seen it before in this macro `(when ,thing ,@(thing)) thingy.
|
|
(defun additional-api-args (&rest args &key (content-type "application/json") &allow-other-keys)
|
|
(remove nil
|
|
`(:additional-headers ,(bearer-auth)
|
|
:content-type ,content-type
|
|
:external-format-in :utf-8
|
|
:external-format-out :utf-8
|
|
:force-binary t
|
|
,@args)))
|
|
|
|
(defun decode-json-from-octets-string (octets)
|
|
(cl-json:decode-json-from-string
|
|
(flex:octets-to-string octets)))
|
|
|
|
(defun json-decode-http-request-to-string (uri &rest args)
|
|
(decode-json-from-octets-string
|
|
(apply #'drakma:http-request uri
|
|
(apply #'additional-api-args args))))
|
|
|
|
(defun server-path (&optional path)
|
|
(format nil "https://~a~:[~;/~a~]" +openai-base-uri+ path path))
|