Google Bard API Project

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.

1 Like

See this guide

Taifun


Pretty cool!

(these blocks can be imported into the blocks editor)

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!

not totally.
you can use 'get value at key path' with one block:

1 Like

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

I think, the only relevant request header is the Content-Type, the others are optional
And: the Content-Length usually is the length of the text from the PostText method and not some constant value... but as there is no error, this header also seams to be optional

Taifun

Taifun has pointed out that the only header blocks required are the Content-Type. I have confirmed this so further simplification was possible. The new header blocks are now:

and the updated aia file is:

Gemini_ProV4.aia (6.4 KB)


END

1 Like

Hey, why it's not working? I am using ur V4 version. I am from Italy btw

Ciao. I believe you need to select Italian as your language for the text to speech component. See the Properties section for the TTS component here: https://ai2.appinventor.mit.edu/reference/components/media.html#TextToSpeech.AvailableLanguages

i am not using it as text to speech

i was just testing while chatting with the AI but it gives an error sayingError: 400application/json

I have reworked the code and version 4 is working for me.
Gemini_ProV3.aia (5.4 KB)

Is it possible for sending an image prompt to gemini?

Hi -- I no longer am working with Gemini. I suggest that you look at the documentation at aistudio.google.com -- it has examples of submitting images for analysis for several languages. There is a 'get code' option in the upper right corner where you can select a specific language. I have used the cURL language in the past as it is closest to how to set up the headers and prompts for MIT App Inventor. Good luck!