Openai api client automatically generated from openapi spec.
Find a file
2024-07-30 15:15:41 +02:00
src Update: commit cd3c3feb77931b5fd1e8b9c1eb5fb1697821a0d0 2024-07-26 15:26:27 +02:00
.gitignore Initial commit 2024-05-04 12:08:42 +02:00
openai-openapi-client.asd Docs: add system description 2024-07-26 15:28:59 +02:00
README.org Fix: small typo 2024-07-30 15:15:41 +02:00

Openai-Openapi-Client

A Common Lisp client for the Openai api automatically generated from the official openai openapi repository using the openapi.yaml on cd3c3feb77931b5fd1e8b9c1eb5fb1697821a0d0.

USAGE

For using the openai api you need to generate an bearer authorization token and then set it as bearer special variable or supply it via the bearer header to each function call.

By default the output is a string. If you set parse to non-nil, or supply parse non-nil value to a function call, then the result will be parsed with com.inuoe.jzon into a native cl data-structure.

EXAMPLE

  ;; This works only with active bearer key as value of *bearer*!
  (openai-openapi-client:list-engines)
  ;; replace your api key in bearer!
  ;; here we also use the serapeum library for conveniently creating hash-tables
  (openai-openapi-client:create-chat-completion
   :bearer  "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"
   :model "gpt-3.5-turbo-0125"
   :response-format (serapeum:dict "type" "json_object")
   :tools
   (list
    (serapeum:dict
     "type" "function"
     "function"
     (serapeum:dict "name" "analyze_text"
		    "description" "Analyze the following text."
		    "parameters"
		    (serapeum:dict "type" "object"
				   "properties"
				   (serapeum:dict "explanation"
						  (serapeum:dict "type" "string"
								 "description" "Give a short summary in less than 200 characters."))))))
   :tool-choice (serapeum:dict "type" "function"
			       "function" (serapeum:dict "name" "analyze_text"))
   :messages (list
	      (serapeum:dict "role" "system"
			     "content" "You are a text analyzer. Your output will be json.
    You get a tip if the results are good.")
	      (serapeum:dict "role" "assistant"
			     "content" "Make sure to name the type text.")
	      (serapeum:dict "role" "user"
			     "content" "Given a prompt, the model will return one or more predicted completions,
  and can also return the probabilities of alternative tokens at each position."))
   :parse t ;; result will be parsed
   :seed 1 ;; make sure the result is deterministic
   )

LICENSE

This library was generated with openapi-generator and is distributed under AGPLv3+ license.