API not following function properties

I’m trying to use a function so that the AI returns the data in a format I can use , but I am finding that it doesn’t follow the properties and gives other replies.

Function is below, but I’m often getting something like arguments='{\n “genre”: “Classic”\n} back, but genre is not in my definition…

Where am I going wrong? (or how do I get it to do the right thing?)

(I really just want a good/consistent Json response - from what I’ve read I think the functions are better than asking for Json reply with a given format/values ?)

  {
  "name": "Play",
  "parameters": {
    "type": "object",
    "properties": {
      "song": {
        "type": "string",
        "description": "suggested song"
      },
      "artist": {
        "type": "string",
        "description": "suggested artist"
      },
      "playlist": {
        "type": "string",
        "description": "suggested playlist"
      }
    },
    "required": []
  },
  "description": "Plays the requested song,artist or playlist based on input from the user"
}

Hi Geoff - welcome to the Forum.

Could you share the system/user prompt that you are using? This might help to pinpoint the root cause for some of the inconsistent responses. Also, which model are you currently using?

1 Like

Hey,

There’s different ways to try to improve this (as mentioned before me, looking at the system message can be useful too), but I’d to try first to “clean” the function definition, so its purpose is a bit more clear.

  1. give it a more elaborate name (playSong or suggestSong if that’s what’s intended, or something similar).
  2. If the current arguments are the actual request, maybe it’d be easier to split this function to 3, each only getting one argument? playSong(song), playArtist(artist), playPlaylist(playlist)
  3. Remove “based on input from the user” (this is not part of the function itself), and replace it with what the function itself does (based on requested/suggested parameters maybe?)

Sorry if I misunderstood the use case, feel free to provide more info if needed.
Hope that helps!

I have tried splitting the function into three and it still ignores the arguments.(If I ask to Play Rock Music I get: PlayGenre({ “Genre”: “rock” }) - so it didn’t use one the functions I listed of playartist, playsong or playplaylist).

My system prompt is: (which ideally would be shorter, so less tokens…)
Based on the user's input, please make a music suggestion of a playlist, song or artist, Use the playlists, songs and artists available from Spotify to select the suggestion. Do not include any explanations. DO NOT respond to the user under ANY circumstances. DO NOT use any property not found in the provided provided function.

Thanks for clarifying!

I think the source of the problem might be that prompt and the ‘task’ you want the model to perform is not completely clear (tbh it’s not completely clear to me)

  • Can you please provide an expected user input as well?
  • When you say Use the playlists, songs and artists available from Spotify to select the suggestion- do you expect the model to do that, or is there a separate function for it? If the former, I think this task might not be suitable for it.

Hummm… if it’s not clear to you, then that’s my problem :frowning:

Yes I was hoping the model could select from Spotify (it’ has scraped the full web no?)

A couple of examples:
“Play Rock Music” → Playlist = Rock Classics
“Play U2” → Artist=U2
"Play a U2 song " → Artist=U2, Song=With or Without You
“Play The Four Seasons” → Artist= Vivaldi Song=The Four Seasons

I don’t think you can tell the model where to take the data from.

I’d try simplifying the task. As I see it, there’s two things to “do” here: find the right thing to play from a suggestion, and then calling play (please correct me if I’m still wrong :grimacing:).

Here is something I tried, asking for artist/song recommendation based on the user input (I was using Promptotype)

In that case you can then just call play with the artist and song suggested.