Run JSON / Javascript / Python scripts in thunkable

Hi!

I tried Makersuite and wanted to integrate my projects with Thunkable. Since Makersuite can generate code, Does anyone have ideas for running the code?

You can run Javascript using the Web Viewer in Thunkable. See this: Is it possible to use javascript in app?

Thanks, But I don’t have a link. Can I use the Colab link (generated by Maker Suite) in the API’s
set link block and get the response?

I don’t know what you mean by a link. You would use the Javascript code that you generated with the Web Viewer as explained in that topic. If Maker Suite doesn’t have API access then, no, you couldn’t do that. If you’re accessing Maker Suite’s API then I guess so.

The Javascript is generated by Makersuite. Makersuite is a platform like Dialogflow, but it uses PaLM 2 ( Pathways Language Model ) developed by Google.
Sorry If I didn’t understand

I want to run this code (which is written in cURL):

curl \
  -H 'Content-Type: application/json' \
  -X POST 'https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001:generateText?key='${API_KEY} \
  -d '{ "prompt": { "text": "Word Type Adjective\nWord Beauty\noutput: Beautiful \nWord Type Noun\nWord Running\noutput: Run\nWord Type Adverb\nWord Impatient\noutput: Impatiently\nWord Type Adjective\nWord Generate\noutput:"}, "temperature": 0.7, "top_k": 40, "top_p": 0.95, "candidate_count": 1, "max_output_tokens": 1024, "stop_sequences": [], "safety_settings": [{"category":"HARM_CATEGORY_DEROGATORY","threshold":1},{"category":"HARM_CATEGORY_TOXICITY","threshold":1},{"category":"HARM_CATEGORY_VIOLENCE","threshold":2},{"category":"HARM_CATEGORY_SEXUAL","threshold":2},{"category":"HARM_CATEGORY_MEDICAL","threshold":2},{"category":"HARM_CATEGORY_DANGEROUS","threshold":2}]}'

If you’re making a POST call to an API then you can learn how to do that by searching the forums. There are examples but each POST call is slightly different.

Were you able to make that POST call in a third-party app/website such as Postman? That’s a good first step before trying to do so in Thunkable. Someone here might be able to help you translate that curl command into blocks. But again, I’d recommend looking around the forums.

Thanks for your reply.

I did find some topics related to Converting cURL Commands and Getting Responses from Google App Script or Colab but they did not have any Solutions.

I read the API Docs to understand how to use the API. To use this API:

I think @Thunkable_Staff have any Ideas?

Thank You

But where shall I place the Web Viewer?

(My App has a chat layout )

This isn’t executable code within Thunkable. What you can do is convert this curl call to use the api connector.

In other words you need to convert the text code to block code

2 Likes

Hi, If I understand your question correctly, you want to know where you should place the webview which has the JS file. If you don’t want to show the webviewer carrying the local (in assets) JS file, you can make it 1px in height on the screen you want to use the JS code in. I do this with all my webviews with JS files inside.

Fiddle around with the Web API blocks to convert your cURL code into blocks.

Note, don’t make them invisible, as doing so has sometimes caused problems in my project. 1px height will suffice.

1 Like

This is my code. In the screen to display the output I will set Variable generate code to 1

Hello, Firstly, your key does not need $ ... \, it’s just to signify in the url that the API key goes there. So just grab your base url till “generateText”, then append ?key=abc, where abc is your key.

Secondly, i recommend you try the Web API component’s POST call, set the URL appended by the API key, and set the body to the body component.

Look around in the community and you will find tons of web api examples, and you’ll eventually get he idea of properly formatting our api content.

I’m just going to second what @kartik14 and @jared have already said: use the Web API blocks, not the Web Viewer.

2 Likes

The POST block does not have the option to send additional data.