diff --git a/LiveDemo/index.html b/LiveDemo/index.html index 8c54c91..68481a9 100644 --- a/LiveDemo/index.html +++ b/LiveDemo/index.html @@ -756,16 +756,28 @@ if (RequestBody.model == null) throwError('Missingargument: no AI "model" given'); try { - const Response = await fetch(APIServer, { - method: 'POST', - headers: { - accept: 'application/json', - 'content-type': 'application/json', - Authorization: `Bearer ${APIKey}`, - }, - body: JSON.stringify(RequestBody) - }); - return (await Response.json()).choices[0].message.content; + for (;;) { + const Response = await fetch(APIServer, { + method: 'POST', + headers: { + accept: 'application/json', + 'content-type': 'application/json', + Authorization: `Bearer ${APIKey}`, + }, + body: JSON.stringify(RequestBody) + }); + if (Response.status === 429) { + if (window.confirm('API Request Limit reached\n\nDo you want to continue? ' + + 'Then wait a minute and press "Ok" - otherwise press "Cancel" ' + + 'to abort the Blockly program') == true) { + continue; + } + else { + throw 'HTTP 439 (too many requests)'; + } + } + return (await Response.json()).choices[0].message.content; + } } catch (Signal) { throwError('RequestFailure: API request failed with ' + Signal); @@ -3996,13 +4008,16 @@ componentDidMount() { Playground.View = this; Playground.WorkspaceElement = this.base.querySelector('.Playground.Workspace > .Placeholder'); - const Workspace = Blockly.inject(Playground.WorkspaceElement, WorkspaceSpecification); + const Workspace = Playground.Workspace = Blockly.inject(Playground.WorkspaceElement, WorkspaceSpecification); restoreWorkspace(); Workspace.addChangeListener(preserveWorkspace); - Playground.Workspace = Workspace; + // Playground.Workspace = Workspace } render() { const { activeTab } = Playground; + function onChange(Event) { + loadExample(Event.target.value); + } return html `
Blockly AI Playground
@@ -4014,6 +4029,16 @@ onClick=${() => { Playground.activeTab = 1; this.rerender(); }} >User Interface
+ load Example + +