rksm / org-ai

Emacs as your personal AI assistant. Use LLMs such as ChatGPT or LLaMA for text generation or DALL-E and Stable Diffusion for image generation. Also supports speech input / output.
GNU General Public License v3.0
639 stars 52 forks source link

Can you help me solve the connection waiting? #68

Open e665107 opened 11 months ago

e665107 commented 11 months ago

Hi , friend When i press C-c C-c , i get the notice as follow:

REQUEST {"messages":[{"role":"user","content":"hello"}],"model":"gpt-3.5","stream":true} Contacting host: api.openai.com:443

I have got the api key and set it like this : (setq org-ai-use-auth-source nil)

(use-package org-ai :ensure t :commands (org-ai-mode org-ai-global-mode) :init (add-hook 'org-mode-hook #'org-ai-mode) ; enable org-ai in org-mode (org-ai-global-mode) ; installs global keybindings on C-c M-a (setq org-ai-openai-api-token "~/.emacs.d/authinfo.gpg") :config (setq org-ai-default-chat-model "gpt-3.5") ; if you are on the gpt-4 beta: (org-ai-install-yasnippets)) ; if you are using yasnippet and want ai snippets

Where do i get stuck in?

rksm commented 11 months ago

(setq org-ai-openai-api-token "~/.emacs.d/authinfo.gpg") seems wrong, you want the token itself.

By default it will be set to (auth-source-pick-first-password :host "api.openai.com" :user "org-ai"), i.e. that you should have a line like

machine api.openai.com login org-ai password sk-...

in your ~/.authinfo.gpg file. Alternatively, you can set the token directly with (setq org-ai-openai-api-token "sk-...").

e665107 commented 11 months ago

Hi, friend: I have do that depend on your suggestion. But it doesn't work! Where do i need change?

(setq org-ai-use-auth-source nil)

(use-package org-ai :ensure t :commands (org-ai-mode org-ai-global-mode) :init (add-hook 'org-mode-hook #'org-ai-mode) ; enable org-ai in org-mode (org-ai-global-mode) ; installs global keybindings on C-c M-a ;; (setq org-ai-openai-api-token "~/.emacs.d/authinfo.gpg") (setq org-ai-openai-api-token "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") :config (setq org-ai-default-chat-model "gpt-3.5") ; if you are on the gpt-4 beta: (org-ai-install-yasnippets)) ; if you are using yasnippet and want ai snippets

rksm commented 11 months ago

Run M-x org-ai-prompt, it should popup an error message if the command fails. Alternatively run C-c C-c on an org-mode ai block and afterwards run M-x org-ai-open-request-buffer. The request buffer might have an erro message in it as well.

e665107 commented 11 months ago

I have do that as your suggestion: following is the message printed, when i pressed the C-c C-c, it gets stuck in the Contacting host: api.openai.com:443! Do i need log out from the chatgpt official website?

REQUEST {"messages":[{"role":"user","content":"nil"}],"model":"gpt-3.5-turbo","stream":true} Contacting host: api.openai.com:443 Quit REQUEST {"messages":[{"role":"user","content":"nil\nchatgpt"}],"model":"gpt-3.5-turbo","stream":true} Contacting host: api.openai.com:443 REQUEST {"messages":[{"role":"user","content":"hello"}],"model":"gpt-3.5-turbo","stream":true} Contacting host: api.openai.com:443 Mark set Mark activated

rksm commented 11 months ago

Do i need log out from the chatgpt official website?

No that should not be necessary. Can you run M-x org-ai-open-request-buffer after running a prompt. There might be an error message in there. It's typically a mismatch in the API key or something.

e665107 commented 11 months ago

Yes, but after i have run the org-ai-open-request-buffer, it prints nothing,

image

rksm commented 11 months ago

Change the model from gpt-3.5 to gpt-3.5-turbo.

If this doesn't help please evaluate the following expression and post the result:

(let* ((url-request-extra-headers `(("Authorization" . ,(encode-coding-string (string-join `("Bearer" ,(org-ai--openai-get-token)) " ") 'utf-8))
                                    ("Content-Type" . "application/json")))
       (url-request-method "POST")
       (url-request-data (org-ai--payload :messages (org-ai--collect-chat-messages "Hello, how are you?")
                      :model "gpt-3.5-turbo"
                                          :stream t)))
  (pop-to-buffer (url-retrieve-synchronously org-ai-openai-chat-endpoint)))
e665107 commented 11 months ago

I have do that as you suggest! The result is : Contacting host: api.openai.com:443 open-network-stream: make client process failed: Connection timed out, :name, api.openai.com, :buffer, #, :host, api.openai.com, :service, 443, :nowait, nil, :tls-parameters, nil, :coding, nil

Mark set [2 times] image