Skip to content

Commit

Permalink
feat: adds logic to make it work without a key
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseops committed Oct 8, 2023
1 parent 2fd14b2 commit 359492f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions streaming-client-api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
'use strict';
import DID_API from './api.json' assert { type: 'json' };
// import DID_API from './api.json' assert { type: 'json' };
let DID_API;
try {
const r = await fetch('api.json');
DID_API = await r.json();
} catch {
DID_API = {
key: '',
url: 'https://api.d-id.com',
};
}

const QUESTIONS = [
{
Expand Down Expand Up @@ -145,7 +155,7 @@ document.getElementById('send-button').addEventListener('click', async function
}
botMessage.appendChild(loadingDiv);
if (highestElement.similarity > 0.2) {
if(streamingOn){
if (streamingOn) {
await startStream(highestElement.id);
botMessage.removeChild(loadingDiv);
botMessage.textContent = highestElement.answer;
Expand Down Expand Up @@ -407,7 +417,11 @@ async function fetchWithRetries(url, options, retries = 1) {
document.getElementById('startButton').onclick = async () => {
document.getElementById('startButton').classList.add('hidden');
document.getElementById('loading').classList.remove('hidden');
await connect();
if(DID_API.key){
await connect();
} else {
await new Promise(r => setTimeout(r, 2000));
}
document.getElementById('loading').classList.add('hidden');
document.getElementById('content').classList.remove('hidden');
document.getElementById('buttons').classList.remove('hidden');
Expand Down

0 comments on commit 359492f

Please sign in to comment.