From 21cd9b97d15ecf636f6f5a954a35f37d7604f6b6 Mon Sep 17 00:00:00 2001 From: Hans Scharler Date: Thu, 10 Oct 2024 10:33:13 -0400 Subject: [PATCH] Added support for Llama-3.2-3B-Instruct LLM --- README.md | 1 + assets/images/icons/if-icon-gold.svg | 14 ++++++++ assets/js/app.js | 52 +++++++++++++++++++++++----- index.html | 10 +++--- 4 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 assets/images/icons/if-icon-gold.svg diff --git a/README.md b/README.md index dbe5b13..f26cbf1 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ OpenRounter requires an OpenRouter Model ID for the OpenRouter Chat Completions - `anthropic/claude-3.5-sonnet` - `anthropic/claude-3.5-sonnet:beta` - `meta-llama/llama-3.1-70b-instruct` +- `meta-llama/llama-3.2-3b-instruct:free` - `mistralai/mistral-tiny` - `mistralai/mistral-small` - `mistralai/mistral-large` diff --git a/assets/images/icons/if-icon-gold.svg b/assets/images/icons/if-icon-gold.svg new file mode 100644 index 0000000..955a555 --- /dev/null +++ b/assets/images/icons/if-icon-gold.svg @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/assets/js/app.js b/assets/js/app.js index bc57bf5..db0f049 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -333,15 +333,53 @@ function sendRequestToAIService(userChoice, endStory = false, userIcon = '') { function processResponse(content, endStory) { try { - content = content.replace(/^(`{2,3}json)?/, '').replace(/`{3}$/, '').trim(); - const response = JSON.parse(content); + let response = content; + + if (typeof content === 'string') { + content = content.replace(/^(`{2,3}json)?/, '').replace(/`{3}$/, '').trim(); + response = JSON.parse(content); + } else if (content.choices && content.choices[0] && content.choices[0].message) { + response = JSON.parse(content.choices[0].message.content); + } else if (typeof content === 'object') { + response = content; + } + else { + if (gameState.history.length === 0) { + storyInProgress = false; + alert('An error occurred. Please try again.'); + reloadApp(); + return; + } + else { + scrollLeftBtn.style.display = 'block'; + scrollRightBtn.style.display = 'block'; + optionsDiv.style.display = 'block'; + alert('An error occurred. Please try again.'); + return; + } + } + let iconToUse = validateIcon(response.icon); let storyTitle = response.storyTitle || gameState.seedIdea; storyInProgress = true; - if (response.description) { + if (typeof response.description === 'object' && response.description.text) { + appendStory(response.description.text, validateIcon(response.description.icon)); + if (response.description.location) { + gameState.location = response.description.location; + } + } else { appendStory(response.description, iconToUse); + if (response.location) { + gameState.location = response.location; + } } + + let options = response.options || (response.description && response.description.options); + if (options && options.length > 0) { + displayOptions(options); + } + if (endStory) { const story = { @@ -366,18 +404,14 @@ function processResponse(content, endStory) { restartButton.style.display = 'block'; return; } - if (response.location) { - gameState.location = response.location; - } - if (response.options && response.options.length > 0) { - displayOptions(response.options); - } } catch (e) { if (gameState.history.length === 0) { storyInProgress = false; alert('An error occurred. Please try again.'); reloadApp(); } + scrollLeftBtn.style.display = 'block'; + scrollRightBtn.style.display = 'block'; optionsDiv.style.display = 'block'; alert('An error occurred. Please try again.'); } diff --git a/index.html b/index.html index 6fe6bdf..e5c163c 100644 --- a/index.html +++ b/index.html @@ -4,11 +4,11 @@ Infinite IF | Interactive Fiction App Powered by AI | Chimeric AI - + - +