pywinassistant icon indicating copy to clipboard operation
pywinassistant copied to clipboard

KeyError: 'choices'

Open dayana123456789 opened this issue 9 months ago • 7 comments

Exception in thread Thread-11 (run_assistant): Traceback (most recent call last): File "C:\Users\dayan\anaconda3\envs\pywin\Lib\threading.py", line 1052, in _bootstrap_inner self.run() File "C:\Users\dayan\anaconda3\envs\pywin\Lib\threading.py", line 989, in run self._target(*self._args, **self._kwargs) File "C:\Users\dayan\pywinassistant\core\assistant.py", line 164, in run_assistant assistant(assistant_goal=action, called_from="assistant") File "C:\Users\dayan\pywinassistant\core\driver.py", line 253, in assistant assistant_goal = imaging(window_title=app_name, additional_context=additional_context, screenshot_size='Full screen')['choices'][0]['message']['content']

KeyError: 'choices' when i instruct to open to open firefox and then tell to type youtube and its its showing error pywin

dayana123456789 avatar May 09 '24 16:05 dayana123456789

Getting the same error also...

Running assistant... Prompt: edge browser go to YouTube and browse Tesla videos Called from: assistant Listening... Listening... Listening... AI selected application: Microsoft Edge AI Analyzing: Microsoft Text Input Application

Generating a test case with the assistant. Image visioning started. Analyzing the application Microsoft Text Input Application for context.

Exception in thread Thread-5 (run_assistant): Traceback (most recent call last): File "C:\Users<name>\AppData\Local\miniconda3\envs\llm2\Lib\threading.py", line 1038, in _bootstrap_inner self.run() File "C:\Users<name>\AppData\Local\miniconda3\envs\llm2\Lib\threading.py", line 975, in run self._target(*self._args, **self._kwargs) File "C:\Code\pywinassistant\pywinassistant-main\core\assistant.py", line 164, in run_assistant assistant(assistant_goal=action, called_from="assistant") File "C:\Code\pywinassistant\pywinassistant-main\core\driver.py", line 253, in assistant assistant_goal = imaging(window_title=app_name, additional_context=additional_context, screenshot_size='Full screen')['choices'][0]['message']['content'] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^ KeyError: 'choices'

studrew avatar May 09 '24 16:05 studrew

Same error for me. Was thinking that it had something to do with my editing of the files (running it on Groq) but weird to see others having the same issue. I'm going to try to port to Ollama later today and will update if I get the same error

dot-Justin avatar May 09 '24 16:05 dot-Justin

Seems that the GPT-4 vision model, the object "choices" is failing. I'm now looking into this issue. This completely blocks the usage of PyWinAssistant. For context, what is your screen resolution? It might be related to a max token limit.

henyckma avatar May 09 '24 17:05 henyckma

Dual 1920 x1200. Tried turning off one of my monitors and changed the resolution to 1280x720... no change... still got the error.

studrew avatar May 09 '24 17:05 studrew

Some users stated that the Chat Completions API object "choices" from the GPT-4 vision model started to fail since yesterday. The issue seems to be somewhere on the vision request:

https://github.com/a-real-ai/pywinassistant/blob/5d8a2188022b8f17c68847d2b8b3d2f5060a9cc9/core/core_imaging.py#L46

"max_tokens": 300 } response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload) return response.json()

And the actual call:

https://github.com/a-real-ai/pywinassistant/blob/5d8a2188022b8f17c68847d2b8b3d2f5060a9cc9/core/core_api.py

I'm now working on the fix. My API keys are not working so I'm working on fixing my blocking issue too.

henyckma avatar May 09 '24 18:05 henyckma

Some users stated that the Chat Completions API object "choices" from the GPT-4 vision model started to fail since yesterday. The issue seems to be somewhere on the vision request:

https://github.com/a-real-ai/pywinassistant/blob/5d8a2188022b8f17c68847d2b8b3d2f5060a9cc9/core/core_imaging.py#L46

"max_tokens": 300 } response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload) return response.json()

And the actual call:

https://github.com/a-real-ai/pywinassistant/blob/5d8a2188022b8f17c68847d2b8b3d2f5060a9cc9/core/core_api.py

I'm now working on the fix. My API keys are not working so I'm working on fixing my blocking issue too.

if I'm asking to type on chrome its showing error

dayana123456789 avatar May 10 '24 14:05 dayana123456789

Hey I have resolved the issue...... You need to provide openAI api key in core_imaging py file. That's all it will work fine

Thank you contributors for such an amazing work @henyckma @Razorbob

dayana123456789 avatar May 10 '24 15:05 dayana123456789

@dayana123456789 So it's working well for you? Also it should work in any type or resolution. I haven't tried multiple monitors, but be aware that having more pixels being read by the VLLM can increase costs.

henyckma avatar May 10 '24 17:05 henyckma

The fix was to add the API keys correctly:

add your API Key in /core/core_api.py -> line 3: client = OpenAI(api_key='insert_your_api_key_here') add your API Key in /core/core_imaging.py -> line 12: api_key = 'insert_your_api_key_here'

For more information, you could check the Readme.md for the complete usage and installation guide.

Special thanks to @NadavIs56 !

henyckma avatar May 10 '24 20:05 henyckma