emacs-openai / chatgpt

Use ChatGPT inside Emacs
GNU General Public License v3.0
195 stars 21 forks source link

GPT-4 supports. #11

Open hongyi-zhao opened 1 year ago

hongyi-zhao commented 1 year ago

I tried this package with GPT-4 using the following configuration:

(defvar my-openai-api-key "sk-xxx")
(use-package openai
  :straight (openai :type git :host github :repo "emacs-openai/openai")
  :config
  (setq openai-key my-openai-api-key)
  )

(use-package chatgpt
  :straight (chatgpt :type git :host github :repo "emacs-openai/chatgpt")
  :config
  (setq chatgpt-model "gpt-4")
  )

But when I try to do query, the following error will be triggered:

Error in post-command-hook (chatgpt-input--post-command): (error "Cannot resize the root window of a frame")
hungry-delete-impl: End of buffer
[error] request--callback: peculiar error: 404
Internal error: 404

Regards, Zhao

jcs090218 commented 1 year ago

It seems like it is not available yet. 404 is expected unless you have already gained access from them through the waitlist. Moreover, the model name should be gpt-4-0314 and not gpt-4 (see their official page, the API section).

hongyi-zhao commented 1 year ago

But https://platform.openai.com/docs/models/gpt-4 lists the following:

Latest model Description Max tokens Training data
gpt-4 More capable than any GPT-3.5 model, able to do more complex tasks, and optimized for chat. Will be updated with our latest model iteration. 8,192 tokens Up to Sep 2021
gpt-4-0314 Snapshot of gpt-4 from March 14th 2023. Unlike gpt-4, this model will not receive updates, and will be deprecated 3 months after a new version is released. 8,192 tokens Up to Sep 2021
gpt-4-32k Same capabilities as the base gpt-4 mode but with 4x the context length. Will be updated with our latest model iteration. 32,768 tokens Up to Sep 2021
gpt-4-32k-0314 Snapshot of gpt-4-32 from March 14th 2023. Unlike gpt-4-32k, this model will not receive updates, and will be deprecated 3 months after a new version is released. 32,768 tokens Up to Sep 2021

Based on my tries, none of them working, but I really have access to it, as shown below:

image

jcs090218 commented 1 year ago

But https://platform.openai.com/docs/models/gpt-4 lists the following:

Ah, okay. Then you are right! Sorry, I only have a quick glance on this. 😅

Can you try raw curl? Does it work? I have no way to test this since I don't have access to the GPT-4 model. 😓

hongyi-zhao commented 1 year ago

I tried with the example shown here, but failed:

werner@X10DAi:~$ curl -x socks5h://127.0.0.1:18890 -i -X POST \
   -H "Authorization:Bearer sk-xxx" \
   -H "Content-Type:application/json" \
   -d \
'{"model":"gpt-4",
 "max_tokens": 2000,
  "temperature": 0.9,
  "n": 1,
   "stream": false,
 "messages":
[
   {
"role": "user",
"content": "add sample prompt description"
},
  { "role": "user", "content": "From now on call me test" },
   { "role": "assistant", "content": "From I live in the Kingdom of ruv" },
  { "role": "system", "content": "Amazing Right, your name is kid." },
  { "role": "user", "content": "tell me a story" }
]
}' \
 'https://api.openai.com/v1/chat/completions'
HTTP/2 404 
date: Fri, 12 May 2023 01:08:18 GMT
content-type: application/json; charset=utf-8
content-length: 179
vary: Origin
x-request-id: 73865e0152a53e025046c31a7def82b4
strict-transport-security: max-age=15724800; includeSubDomains
cf-cache-status: DYNAMIC
server: cloudflare
cf-ray: 7c5ec5119952f234-KHH
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

{
    "error": {
        "message": "The model: `gpt-4` does not exist",
        "type": "invalid_request_error",
        "param": null,
        "code": "model_not_found"
    }
}

But it really works for gpt-3.5-turbo:

werner@X10DAi:~$ curl -x socks5h://127.0.0.1:18890 -i -X POST \
  -H "Authorization:Bearer sk-xxx"  \
  -H "Content-Type:application/json"  \
  -d '{"model":"gpt-3.5-turbo",
 "max_tokens": 20,
  "temperature": 0.9,
  "n": 1,
   "stream": false,
 "messages":
[
   {
"role": "user",
"content": "add sample prompt description"
},
  { "role": "user", "content": "From now on call me test" },
   { "role": "assistant", "content": "From I live in the Kingdom of ruv" },
  { "role": "system", "content": "Amazing Right, your name is kid." },
  { "role": "user", "content": "tell me a story" }
]
}'  'https://api.openai.com/v1/chat/completions'
HTTP/2 200 
date: Fri, 12 May 2023 01:11:12 GMT
content-type: application/json
content-length: 376
access-control-allow-origin: *
cache-control: no-cache, must-revalidate
openai-model: gpt-3.5-turbo-0301
openai-organization: user-cycirv7tg3umtkc0ijlplsz5
openai-processing-ms: 689
openai-version: 2020-10-01
strict-transport-security: max-age=15724800; includeSubDomains
x-ratelimit-limit-requests: 3
x-ratelimit-limit-tokens: 40000
x-ratelimit-remaining-requests: 2
x-ratelimit-remaining-tokens: 39941
x-ratelimit-reset-requests: 20s
x-ratelimit-reset-tokens: 88ms
x-request-id: af35ab93131133f27139821ca070b0ec
cf-cache-status: DYNAMIC
server: cloudflare
cf-ray: 7c5ec94c0ed2f1d0-KHH
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

{"id":"chatcmpl-7FBbMy8ckS9HuXjpY5cxv1EJzMvWg","object":"chat.completion","created":1683853872,"model":"gpt-3.5-turbo-0301","usage":{"prompt_tokens":59,"completion_tokens":20,"total_tokens":79},"choices":[{"message":{"role":"assistant","content":"Once upon a time, there was a small village nestled in the middle of a dense forest. The"},"finish_reason":"length","index":0}]}

See here for the related discussion.

Could you please give an example template?

hongyi-zhao commented 1 year ago

It seems that is the desired behavior, as stated on the official website here:

image

See https://github.com/karthink/gptel/issues/59#issuecomment-1545244376 for the related discussion.

beyondpie commented 1 year ago

@jcs090218 Hi author, I think the error I have is the same here. So it's just because GPT-4 is not supported to be used as API. Thanks! Songpeng

beyondpie commented 1 year ago

@jcs090218 @hongyi-zhao Does this mean GPT-4 is now supported? https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4

jcs090218 commented 1 year ago

Does this mean GPT-4 is now supported?

It has been a while since I have followed the OpenAI development. Can you see if it works?

(setq chatgpt-model "gpt-4")
hongyi-zhao commented 1 year ago

I tried but still failed:

image

The official help says that:

On July 6, 2023 , we gave access to the GPT-4 API (8k) to all API users who have made a successful payment of $1 or more.

So, it should mean that you must first be a successful-paid user of its API instead of the web based access.

See https://stackoverflow.com/questions/76653119/openai-gpt-4-api-error-the-model-gpt-4-does-not-exist for the related discussion.