a-real-ai/pywinassistant

KeyError: 'choices'

Closed this issue · 9 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

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'

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

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.

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

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:

def analyze_image(base64_image, window_title, additional_context='What’s in this image?'):

"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.

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:

def analyze_image(base64_image, window_title, additional_context='What’s in this image?'):

"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

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 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.

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 !