choices =: 'choices' jsongetkv parsed
NB. for now just return the first choice. In general there will
NB. likely be multiple array elements that will need to interpreted
NB. 1{:: selects the value of the key-value pair
NB. since it's an array select the first element and unbox
firstChoice =: > 0{ 1 {:: choices
NB. get the 'message' key-value pair
message =: 'message' jsongetkv firstChoice
NB. select the value of the key value pair then look for the content entry
content =: 'content' jsongetkv 1 {:: message
NB. return the value of the content key-value pair which is the
NB. answer string returned by the LLM
1{:: content
So my question is there any best practice for how to navigate J boxes that represent JSON structures? The fetch command can’t navigate the whole way on its own because of the array boxed in value for choices.
Using fetch commands it seems it needs to be broken up into separate fetches:
(1,1){:: (1,1){:: 0{:: 1{:: 'choices' jsongetkv__mchat parsed__mchat
I have to use an i. access based on the key ‘choices’ because that is not always in the same position in the intial dictionary. jsongetkv does an i. lookup and uses the index to fetch the whole record.
Also if I try to fetch in one combined fetch I get an index error.
Here is the ‘choices’entry so you can see the decoded JSON structure truncated so it can fit on a laptop screen without wrapping:
┌───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│choices│┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ ││┌─────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────
│ │││index │0
│ ││├─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────
│ │││message │┌───────────┬──────────────────────────────────────────────────────────────────────────────────────────
│ │││ ││role │assistant
│ │││ │├───────────┼──────────────────────────────────────────────────────────────────────────────────────────
│ │││ ││content │One fascinating aspect of space is the phenomenon of gravitational lensing. This occurs wh
│ │││ │├───────────┼──────────────────────────────────────────────────────────────────────────────────────────
│ │││ ││refusal │
│ │││ │├───────────┼──────────────────────────────────────────────────────────────────────────────────────────
│ │││ ││annotations│
│ │││ │└───────────┴──────────────────────────────────────────────────────────────────────────────────────────
│ ││├─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────
│ │││logprobs │
│ ││├─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────
│ │││finish_reason│stop
│ ││└─────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────
│ │└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
└───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
So once you have looked up ‘choices’ that has a value of an array of 1 entry in this particular request-response with chatGPT. The message and content entries appear to be in the same relative location across different LLMs. So just wondering if there is a preferred way to access these embedded JSON structures.
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.