From 65082b95fd9d8d08aabcab8e5aac8fd41f0465a1 Mon Sep 17 00:00:00 2001 From: swyxio Date: Wed, 6 Sep 2023 13:29:51 -0700 Subject: [PATCH] add falcon 180b --- src/lib/constants.ts | 2 + src/providers/falcon180bspace.js | 71 ++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/providers/falcon180bspace.js diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 247868a..8f2a186 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -17,6 +17,7 @@ import OpenRouter from '../providers/openrouter'; import Poe from 'providers/poe'; import InflectionPi from 'providers/inflection'; import StableChat from 'providers/stablechat'; +import Falcon180BSpace from 'providers/falcon180bspace'; export const allProviders = [ OpenAi, @@ -31,6 +32,7 @@ export const allProviders = [ InflectionPi, HuggingChat, StableChat, + Falcon180BSpace, OobaBooga, Together, OpenRouter, diff --git a/src/providers/falcon180bspace.js b/src/providers/falcon180bspace.js new file mode 100644 index 0000000..8e3debf --- /dev/null +++ b/src/providers/falcon180bspace.js @@ -0,0 +1,71 @@ +const Provider = require('./provider'); + +class Falcon180BSpace extends Provider { + static webviewId = 'webviewFalcon180BSpace'; + static fullName = 'Falcon 180B (HF Space, temporary)'; + static shortName = 'Falcon180BSpace'; + + static url = 'https://tiiuae-falcon-180b-demo.hf.space/?__theme=dark'; + + static handleInput(input) { + this.getWebview().executeJavaScript(`{ + var inputElement = document.querySelector('textarea[data-testid="textbox"]'); + if (inputElement) { + var nativeTextAreaValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set; + nativeTextAreaValueSetter.call(inputElement, \`${input}\`); + + var event = new Event('input', { bubbles: true}); + inputElement.dispatchEvent(event); + } + }`); + } + + static handleSubmit() { + this.getWebview().executeJavaScript(`{ + var btn = document.querySelector('button.primary'); + if (btn) { + btn.focus(); + btn.disabled = false; + btn.click(); + } + }`); + } + static handleCss() { + this.getWebview().addEventListener('dom-ready', () => { + // Hide the "Try asking" segment + setTimeout(() => { + this.getWebview().insertCSS(` + div[data-testid="markdown"] { + display: none; + } + #banner-image { + height: 30px; + } + `); + }, 100); + }); + } + static handleDarkMode(isDarkMode) { + if (isDarkMode) { + this.getWebview().executeJavaScript(`{ + if(document.querySelector('html').dataset.theme === 'light'){ + document.querySelector('.menu > ul > div:nth-child(2) > button').click() + } + } + `); + } else { + this.getWebview().executeJavaScript(`{ + if(document.querySelector('html').dataset.theme === 'business'){ + document.querySelector('.menu > ul > div:nth-child(2) > button').click() + } + } + `); + } + } + + static isEnabled() { + return window.electron.electronStore.get(`${this.webviewId}Enabled`, false); + } +} + +module.exports = Falcon180BSpace;