May the path be with you.
Yes, I saw these blocks. I cannot get them to work. BTW. I found this interesting that lookup in pairs can work in a similar way to get value for key in dictionary:
Reading your blocks right to left, I would think this is the path you need, one item per line:
candidates
1
content
parts
1
text
However, the text part is fouled by the markup between the Yoda quotes.
I am surprised you got it through the JSON conversion.
Could you export a draggable block of that JSON text, one that survives the Web1.JSONDecodeWithDictionaries block?
Correct. When we added the dictionaries implementation we tried to make sure that dictionaries and associative lists (lists of pairs) are interoperable. You can pass either type to either set of blocks and the language will coerce the representation. Of course, this is slower than passing it to the block that expects the correct type.
As for the get values at key path, the first argument specifies a list of the keys and/or indices that should be taken to retrieve a value somewhere in the object tree. It effectively collapses the nested blocks into a list of steps, so read the blocks from right to left to get the list you would need, e.g., ["candidates", 1, "content", "parts", 1, "text"]
This extension will help you to create this project without any additional effort and with more features like "streaming" and also enable you to use the "Gemini-pro-vision" model too
If you right click on a block and select "Download as PNG", it will create a PNG file with metadata that allows App Inventor to reconstruct the blocks when you drag and drop the image into the blocks editor.
If you were to apply a Do It to that global debug in your example, highlight all the data in the Do It result, hit Copy, then paste that JSON text into a text block, hopefully that would result in a text block full of legal JSON.
If you right click on that text block and choose Download Block as png (individual block, not all blocks), you would end up with a .png file.
Now here's the beauty of AI2.
That .png file, if left uneditted, can be posted here, and the posted file can be dragged into some one else's Blocks Editor workspace where it will magically appear, ready to feed some one else's app.
(Canned Reply: ABG - Download those blocks and post them here)
Please download and post each of those event block(s)/procedures here ...
P.S. These blocks can be dragged directly into your Blocks Editor workspace.
See Download Block Images for a demo.
candidates
1
content
parts
1
text
That block arrangement is working for me when using the Web component JsonTextDecodeWithDictionaries block.
See this guide
Taifun
Thanks, Taifun. I did not understand the MIT Dictionary examples.
I consulted with Bing, Bard, Perplexity, Claude 2 and ChatGPT -- all confirmed that there are no examples of nested lists using MITAI2 Dictionary blocks. So now we have one. This solution uses about the same number of blocks, but uses both the 'get value at key path' and 'get value for key' blocks. The blocks extract the contents of the "text" key. Is this a more elegant solution than the one using a combination of 'get value for key' and 'select list item'? You be the judge. Personally, I find it less intuitive.
partial json object with nested lists:
{"candidates": [{"content": {"parts": [{"text": "“Do or do not. There is no try.”"}],...
(these blocks can be imported into the blocks editor)
done!
Thanks, Kevinkun. Can you show the 'Do it' of those blocks? I can't get them to work for me.
The quote or quotes should be returned.
sorry the responseContent you supplied seems to be not valid json format. I can not test it.
Thanks, everyone for the help. It is indeed possible to extract the text with one Dictionary block!
and @Kevinkun 's more streamlined solution:
END
While Version 2 works fine, the support staff suggested a simpler solution for handling responseContent in the Web component's GotText event block which uses one Dictionary block. This is very instructive when you have the kind of json object response often returned by LLMs that contains nested lists.
Gemini_ProV3.aia (6.6 KB)
END