glibsonoran / Plush-for-ComfyUI

Custom node for ComfyUI/Stable Diffustion
GNU General Public License v3.0
152 stars 15 forks source link

Three requests to OpenAI API when initializing? #124

Closed Jonseed closed 1 month ago

Jonseed commented 1 month ago

It looks like Plush is making three requests to OpenAI API when it initializes. Is this normal behavior?

HTTP Request: GET https://api.openai.com/v1/models "HTTP/1.1 200 OK"
Retrying request to /openai/v1/models in 0.864713 seconds
Retrying request to /openai/v1/models in 1.650666 seconds

If it was OK the first time, why does it make two additional requests?

glibsonoran commented 1 month ago

When you start up Plush attempts to fetch the model lists from: OpenAI, Groq and Ollama (Anthropic doesn't make their lists available remotely). If the OpenAI request fails (maybe you don't have an API key) it retries twice. It shouldn't be retrying if it got the models the first time.
Let me take a look.

glibsonoran commented 1 month ago

This is what I get on startup:

HTTP Request: GET https://api.openai.com/v1/models "HTTP/1.1 200 OK"
HTTP Request: GET https://api.groq.com/openai/v1/models "HTTP/1.1 200 OK"

Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) 
after connection broken by 
'ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000027281430550>,
 'Connection to localhost timed out. (connect timeout=2)')': /api/tags

The first is the openAI model retrieve, the second is groq and the third is a timeout looking for Ollama models. Not sure why you're seeing what you're seeing. Do you have a valid OpenAI api key?

glibsonoran commented 1 month ago

You know now that I think of it, the rgthree suite does, or at least used to, include some enhancements to how ComfyUI handles datacom including retries if I remember right. I remember back when I was first putting my nodes together I went in to a settings menu and turned the rgthree datacomm enhancements off because they were causing to much delay on startup. You might take a look at that if you have the suite installed.

Jonseed commented 1 month ago

I have a valid OpenAI API key, and it is applied to the environment (I'm using Conda, so it is set as a .bat file in my conda-envs\comfy\etc\conda\activate.d folder). I've used the node to make requests to the OpenAI API and get responses, so I know my key is working ok.

I also thought it was strange that it was retrying twice when the first time it got the models OK. Why retry if the first time it works?

I'm not using Groq, but I am using Ollama, and I get a valid initialization of that separately when I use it (not on startup, although this might be from the ComfyUI-Ollama custom node): HTTP Request: GET http://127.0.0.1:11434/api/tags "HTTP/1.1 200 OK"

I checked the rgthree suite, and I don't see anything about datacomm enhancements in the settings menu.

Jonseed commented 1 month ago

Is it a failed request to contact Groq? And so it retries?

glibsonoran commented 1 month ago

Maybe, if so it's not showing your the initial domain though: HTTP Request: GET https://api.groq.com/openai/v1/models "HTTP/1.1 200 OK"

Jonseed commented 1 month ago

I haven't set a Groq API key anywhere... Does it still try to contact Groq without an API key? This may be causing over 2 seconds of delay on my Comfy startup (loading the frontend webpage).

Jonseed commented 1 month ago

It says it is making a request to /openai/v1/models endpoint, so that seems like it would be Groq, not OpenAI (since that is at the /v1/models endpoint).

Jonseed commented 1 month ago

Maybe, if so it's not showing your the initial domain though: HTTP Request: GET https://api.groq.com/openai/v1/models "HTTP/1.1 200 OK"

Does it only show the initial domain if the request is successful?

Jonseed commented 1 month ago

I just got and added a Groq API key, and the failed requests went away. So that is probably what it was. You might want to only send requests to Groq (and OpenAI) if there is an API key present in the environment?

glibsonoran commented 1 month ago

Yah, I'll take a look and see if I can avoid trying to connect with no key.

glibsonoran commented 1 month ago

should work now. No fetch on missing env var/key.