APIs and CORS
Your JavaScript code can call remote APIs from the page.
Here are some useful functions.
AI APIs
To call the
GPT API from OpenAI,
define the API key and prompt, and then:
AB.callGPT ( apikey, prompt, function ( reply ) { ... } );
// The reply is the 'payload' extracted from the full API return data.
// You define a function to do something with the reply.
// The full API return data is saved in AB.apidata
If you want to write a customised API call, look at the code for this World:
Chat with GPT model 669 runs ♦ 3 likes
By
Starter user Created: 18 Sep 2023
Modified: 3 Oct 2023
JavaScript page to chat with a GPT model. Calls OpenAI API. User needs to enter API key.
CORS
JavaScript can fetch resources (like images) from any site on the Internet
if the site is
CORS enabled.
For sites that are not, you can go through a CORS proxy.
Here is a handy function to get a CORS-enabled URL for your resource,
using
corsproxy.io.
AB.cors ( url ); // return CORS-enabled URL for this resource
So fetching url into your JS graphics World may fail,
but fetching AB.cors ( url ) may work.