How to Implement OpenAPI Structure to Retrieve Maximum Stat from My API?

Hello fellow developers,

I’m currently working on an API that provides data on football player performances. The API returns data in the following structure:

[
    {"Big Chances Created":0.0,"Competition":"Liga_Betclic","Date":"Fri, 05 Aug 2022 00:00:00 GMT","Matchday":1,"Minutes Played":78.0,"Non Penalty xG":0.1815599948167801,"Passes":5.0,"Player":"Gon\u00e7alo Ramos","Season":"2022_2023","Shots On Target":0.0,"Team":"Benfica","Total Shots":2.0,"assists":1.0,"keypasses":2.0,"xG":0.1815599948167801,"xT":-0.021226246608421206,"xa":0.06622999906539917},
    {"Big Chances Created":0.0,"Competition":"Liga_Betclic","Date":"Tue, 30 Aug 2022 00:00:00 GMT","Matchday":3,"Minutes Played":71.0,"Non Penalty xG":1.3662300109863281,"Passes":7.0,"Player":"Gon\u00e7alo Ramos","Season":"2022_2023","Shots On Target":2.0,"Team":"Benfica","Total Shots":3.0,"assists":0.0,"keypasses":0.0,"xG":1.3662300109863281,"xT":-0.0007703914307057858,"xa":0.0},
    {"Big Chances Created":0.0,"Competition":"Liga_Betclic","Date":"Sat, 13 Aug 2022 00:00:00 GMT","Matchday":2,"Minutes Played":84.0,"Non Penalty xG":1.5657299980521202,"Passes":13.0,"Player":"Gon\u00e7alo Ramos","Season":"2022_2023","Shots On Target":2.0,"Team":"Benfica","Total Shots":4.0,"assists":0.0,"keypasses":0.0,"xG":1.5657299980521202,"xT":0.1038257721811533,"xa":0.0},
    {"Big Chances Created":1.0,"Competition":"Liga_Betclic","Date":"Sat, 27 Aug 2022 00:00:00 GMT","Matchday":4,"Minutes Played":63.0,"Non Penalty xG":0.5436800010502338,"Passes":7.0,"Player":"Gon\u00e7alo Ramos","Season":"2022_2023","Shots On Target":1.0,"Team":"Benfica","Total Shots":4.0,"assists":0.0,"keypasses":1.0,"xG":0.5436800010502338,"xT":0.24460069996712264,"xa":0.6025000214576721},
    {"Big Chances Created":0.0,"Competition":"Liga_Betclic","Date":"Sat, 01 Oct 2022 00:00:00 GMT","Matchday":8,"Minutes Played":70.0,"Non Penalty xG":0.0,"Passes":11.0,"Player":"Gon\u00e7alo Ramos","Season":"2022_2023","Shots On Target":0.0,"Team":"Benfica","Total Shots":0.0,"assists":0.0,"keypasses":0.0,"xG":0.0,"xT":-0.016031971645134035,"xa":0.0}
]

This is the response when I look for a specific player.
Now, I want to implement OpenAPI to retrieve the game (match) with the highest xG (expected goals) from this API. Essentially, I need to find the match with the maximum xG value among all matches in the response.

How can I go about implementing this using OpenAPI? What endpoints and operations should I define in the OpenAPI specification to achieve this?

I appreciate any guidance or code snippets that can help me get started with implementing this feature in my API.

Thank you in advance for your help!

Best regards,
L.

I don’t think you really need AI for that dude. You’ve got five objects, all in the same format, ready to be deserialized from json and have their xG value compared just using your language’s basic “greater than” operator. Otherwsie you’re sending like a thousand tokens in the context.

Maybe I’m misunderstanding, but this should work as is.

i.e. If you make a prompt along the lines of:

show me the match with the highest xG for player X

ChatGPT should work out to a) call your current endpoint (e.g. /matches?player_id=1 or whatever it is), and then tell you the one with the highest xG from that list.

Have you tried implementing this already?

Things that could prevent it from working:

  • incomplete/incorrect openapi specification. e.g. endpoint description is not clear, or the response object fields are not correctly specified
  • too many matches returned (could max out the context length)

ps. If you’re making a football stats plugin, I would love to try using it to help with fantasy football. :heart:

I’m not sure a LLM like GPT is suited for this. First, it’s actually worse at math than the average human, as it tokenizes numbers weirdly

image

The first is “zero point zero-one six-hundred-three”. The second is “zero point eighteen hundred-fifty-five”. So you’ll encounter the occasional bug where it thinks .016031971645134035 is bigger than 0.1815599948167801

Asking it to process data like this is prone to mistakes.

I’m not sure what you could get from GPT here. You might as well process the code yourself. You could ask it for anomalies and outliers. Or ask it to interpret the data into human readable text. But otherwise it doesn’t seem very useful.

1 Like