kylecorry31/ML4K-AI-Extension

Presetting the API key

Closed this issue · 9 comments

Is there a way that the API key can be read from the aix file, to save the need for students to use the API key block?

If the API key could be read from a properties/config file inside the aix file, then I could get ML4K to dynamically generate that (start from a default aix file of ML4K-AI-Extension, unzip it, modify the properties/config file with the API key, zip it back up, serve that patched aix file for download).

I think that'd be a helpful simplification... what do you think?

I will look into this, and assess the feasibility.

Research (WIP):

  • The aix file is just a zip file
  • The build config file contains an assets property, maybe there is a way of including assets when building an android studio project
  • It would also be possible to put a config file into the classes.jar file... That is also formatted like a zip

It does not look like it is possible to send a file containing the API key through AppInventor. @dalelane

@ewpatton Any ideas about this?

Custom assets are packaged in the .aix in a subdirectory assets/. You can read them at runtime by a call to Form.openAssetForExtension(Component, String), which takes an instance of the extension and the name of the asset.

What you could do is compile the AIX with a placeholder key file, and then when you serve up the .aix to the user you could update the key file in the assets directory to be read at runtime.

Thanks! I'll see what I can do to implement this feature

@kylecorry31 You can see an example in our Look extension here.

@ewpatton Thanks for the help!

@dalelane The latest version of the extension allows you to preset the API key, building instructions are here: https://github.com/kylecorry31/ML4K-AI-Extension/tree/v0.8-beta#building-with-preset-api-key

Let me know if you have any questions.

@kylecorry31 @ewpatton That's fantastic - thanks so much for doing that!

I've set up the site to support downloading the aix file with the API key already embedded in it.

image