music-assistant / hass-music-assistant

Turn your Home Assistant instance into a jukebox, hassle free streaming of your favorite media to Home Assistant media players.
Apache License 2.0
1.4k stars 51 forks source link

Unable to play music using conversations - cannot access local variable 'media_item' #3207

Closed paducz closed 3 days ago

paducz commented 5 days ago

What version of Music Assistant has the issue?

2.3.3

What version of the Home Assistant Integration have you got installed?

2024.11.4

Have you tried everything in the Troubleshooting FAQ and reviewed the Open and Closed Issues and Discussions to resolve this yourself?

The problem

When instructing chatgpt (conversation agent) to play a music I am getting this error:

UnboundLocalError: cannot access local variable 'media_item' where it is not associated with a value 2024-11-20 19:59:43.864 DEBUG (MainThread) [homeassistant.components.openai_conversation] Tool response: {'error': 'IntentUnexpectedError', 'error_text': 'Error handling MassPlayMediaOnMediaPlayer'}

How to reproduce

Ask assisit to play James Arthur

Music Providers

Apple music

Player Providers

DLNA

Full log output

2024-11-20 19:59:43.858 DEBUG (MainThread) [homeassistant.components.openai_conversation] Response ChatCompletion(id='chatcmpl-AVkDOjEb6Vy1Bu9OiyqESy7jVrHRx', choices=[Choice(finish_reason='tool_calls', index=0, logprobs=None, message=ChatCompletionMessage(content=None, role='assistant', function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_l0r2fUul2qiqDHoNKexyNDJ1', function=Function(arguments='{"track":"Car\'s Outside"}', name='MassPlayMediaOnMediaPlayer'), type='function')], refusal=None))], created=1732129182, model='gpt-4o-mini-2024-07-18', object='chat.completion', service_tier=None, system_fingerprint='fp_0705bf87c0', usage=CompletionUsage(completion_tokens=21, prompt_tokens=5819, total_tokens=5840, prompt_tokens_details={'cached_tokens': 0, 'audio_tokens': 0}, completion_tokens_details={'reasoning_tokens': 0, 'audio_tokens': 0, 'accepted_prediction_tokens': 0, 'rejected_prediction_tokens': 0})) 2024-11-20 19:59:43.859 DEBUG (MainThread) [homeassistant.components.openai_conversation] Tool call: MassPlayMediaOnMediaPlayer({'track': "Car's Outside"}) 2024-11-20 19:59:43.860 ERROR (MainThread) [homeassistant.helpers.intent] Error handling MassPlayMediaOnMediaPlayer Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/intent.py", line 143, in async_handle result = await handler.async_handle(intent) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/mass/intent.py", line 254, in async_handle if not media_item: ^^^^^^^^^^ UnboundLocalError: cannot access local variable 'media_item' where it is not associated with a value 2024-11-20 19:59:43.864 DEBUG (MainThread) [homeassistant.components.openai_conversation] Tool response: {'error': 'IntentUnexpectedError', 'error_text': 'Error handling MassPlayMediaOnMediaPlayer'}

Additional information

No response

What version of Home Assistant Core are your running

2024.11.2

What type of installation are you running?

Home Assistant OS

On what type of hardware are you running?

Raspberry Pi

OzGav commented 5 days ago

Are you using the full LLM option?

paducz commented 4 days ago

I followed MA Specific Conversation Agent instructions. I am also using the mass intents...so probably yes?

OzGav commented 4 days ago

If HOME ASSISTANT is not your Conversation Agent which is set in your voice assistant config then you are using a full LLM. If this is the case then this is not likely a MA problem. Indeed the errors you have pasted in are HA errors. You should probably be asking in the HA Voice Assistants Discord Channel

image