openai-openapi-client

2024-10-12

Openai API client

Upstream URL

codeberg.org/kilianmh/openai-openapi-client

Author

Kilian M. Hämmerle

License

AGPLv3+
README

1Openai-Openapi-Client

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

1.1USAGE

For using the openai api you need to generate an bearer authorization token and then set it asbearer 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.

1.2EXAMPLE

  ;; 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
   )

1.3LICENSE

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

Dependencies (6)

  • cl-str
  • dexador
  • jzon
  • openapi-generator
  • quri
  • uiop

Dependents (0)

    • GitHub
    • Quicklisp