#Music Assistant Chat GPT music search engine
1 messages ยท Page 1 of 1 (latest)
So @amber adder ๐ Iโm available. First : Do you want to come to a voice channel so that I show you live ๐? Would be faster for me and hopefully more interesting for you
Sure can!
**SOLVED. see below
Hey @livid sparrow , sorry for the long text. If you ever have time to take a look and maybe point me in the right direction, I would appreciate it!
I am working on taking your blueprint for the Music Assistant and changing it to use Plex for movies and TV. I have it almost working and needing some help with JSON
The issue is that Plex also wants a media_content_type key in the service data field. 'EPISODE' for tv shows or 'movie' for Movies.
The JSON I am getting from OpenAI already contains this information, I just need to grab it out with a template.
This is what the response looks like.
response_from_ai:
response:
speech:
plain:
speech: >-
{ "library_name": "Movies", "title": "Harry Potter and the Chamber of
Secrets" }
extra_data: null
card: {}
language: en
response_type: action_done
data:
targets: []
success: []
failed: []
conversation_id: 01HMHD5EJXSXJJ3BJC3QFF6AKG
What I am needing to do is grab the value for the key 'library_name' and do an if statement. This is what I have:
service: media_player.play_media
data:
media_content_id: '{{response_from_ai.response.speech.plain.speech|from_json}}'
media_content_type: >
{% if response_from_ai.response.speech.plain.speech.library_name == "Movies"
-%}
movie
{%- else -%}
EPISODE
{%- endif %}
target:
entity_id: media_player.plex_plex_for_apple_tv_apple_tv
However, it is not matching the first if statement and defaulting to the else statement for movies.
I was testing this with the template editor and it works like this:
{% set my_test_json = { "library_name": "Movies", "title": "Harry Potter and the Chamber of
Secrets" } %}
{% if my_test_json.library_name == "Movies" -%}
movie
{%- else -%}
EPISODE
{%- endif %}
I am assuming the key from the JSON is incorrect for "response_from_ai.response.speech.plain.speech.library_name"
Leaving this here if someone else needs this.
I had to change the if statement from:
{% if response_from_ai.response.speech.plain.speech.library_name == "Movies"
-%}
to
{% if (response_from_ai.response.speech.plain.speech|from_json).library_name == "Movies"
-%}
Oooooooj show me the results I am interested!!
Well, running into an issue, so almost solved lol. The automation is popping this up in the trace:
Stopped because an error was encountered at January 19, 2024 at 12:21:29 PM (runtime: 1.53 seconds)
Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
but with that change I am now getting the correct output from the if statement:
params:
domain: media_player
service: play_media
service_data:
media_content_id:
library_name: Movies
title: Harry Potter and the Chamber of Secrets
media_content_type: movie
entity_id:
- media_player.plex_plex_for_apple_tv_apple_tv
target:
entity_id:
- media_player.plex_plex_for_apple_tv_apple_tv
running_script: false
Moved this question over to the templates channel. If I get it resolved I'll put it in here