extended_openai_conversation icon indicating copy to clipboard operation
extended_openai_conversation copied to clipboard

Plex Integration issues

Open geman220 opened this issue 1 year ago • 3 comments

This could potentially be a user error, but following the example here:

https://github.com/jekalmin/extended_openai_conversation/blob/main/examples/function/plex/README.md

The results are pretty unreliable. Sometimes the assist says it cannot access the Plex server, sometimes it responds with information but includes [YOUR PLEX KEY] (literally that's not a placeholder). Other times it will say "I found movie on the Plex server" and that's it. I wrote a small Python script that will read the latest 5 movies added to Plex, then created a sensor in HA that stores the titles of those movies, then I can expose that sensor, and the integration works well. I'm just curious if I am misunderstanding the Plex example here, or if there is a better way to implement that sort of feature. Feel free to close if I am off base here.

geman220 avatar Feb 03 '24 19:02 geman220

Thanks for reporting an issue! Let me try this and get back soon.

jekalmin avatar Feb 09 '24 15:02 jekalmin

@jekalmin Hey man, great work with this integration! I am really enjoying it so far. You made my local assistant smarter than Google Home has been in years.

Only issue I am having right now is the Plex and Music casting. I tried the example above to absolutely no avail (over 24 hours of trial and error). It seems the function is able to ATTEMPT to search, but it can never get past that point. It is unable to pull and parse a JSON from my remote plex server. I can, however, copy-paste the URL pushed to OpenAI and put it in a browser, and the API call works fine.

Is there something I am missing here?

meharrington90 avatar Mar 07 '24 08:03 meharrington90

Could you share the JSON result of API? I was going to try it, but unfortunately plex forbids logging in from my country :(

jekalmin avatar Mar 09 '24 07:03 jekalmin

Sorry for delayed response. Could you try following? I added "headers" in rest function.

- spec:
    name: search_plex
    description: Use this function to search for media in Plex.
    parameters:
      type: object
      properties:
        query:
          type: string
          description: The search query to look up media on Plex.
      required:
      - query
      - token
  function:
    type: rest
    resource_template: "https://YOUR.PLEX.SERVER.TLD/search?query={{query}}&X-Plex-Token=YOURPLEXTOKEN"
    headers:
      accept: "application/json"
    value_template: >-
      ```csv
      title,year,director,type,key
      {% for metadata in value_json["MediaContainer"]["Metadata"] %}
        {{ metadata["title"]|replace(",", " ") }},
        {{ metadata["year"] }},
        {{ metadata["Director"][0]["tag"] if metadata["Director"] else "N/A" }},
        {{ metadata["type"] }},
        {{ metadata["key"] }}
      {% endfor -%}
      ```

jekalmin avatar Jan 31 '25 16:01 jekalmin