emacs-openai / openai

Elisp library for the OpenAI API
GNU General Public License v3.0
100 stars 17 forks source link

Implements Chat API #4

Closed jcs090218 closed 1 year ago

jcs090218 commented 1 year ago

OpenAI has recently released their ChatGPT to beta, implement the https://platform.openai.com/docs/api-reference/chat is the next step.

jcs090218 commented 1 year ago

I've implemented ChatGPT in #8, this is how you use it.


(openai-chat '[(("role" . "user")
                ("content" . "Hello!"))]
             (lambda (data)
               (message "%s" data))
             :max-tokens 4000
             :temperature 1.0)

Result:

((id . chatcmpl-6vEGtmoH7VR74Uh73p1DPwoiIFKyZ) (object . chat.completion) (created . 1679097575) (model . gpt-3.5-turbo-0301) (usage (prompt_tokens . 9) (completion_tokens . 10) (total_tokens . 19)) (choices . [((message (role . assistant) (content . 

Hello! How can I assist you today?)) (finish_reason . stop) (index . 0))]))

To play with it, use M-x openai-chat-say.