Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stable chat provider #233

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Yes and no:
| Vercel Chat | Simple open source chat wrapper for GPT3 API |
| Local/GGML Models (via [OobaBooga](https://github.com/oobabooga/text-generation-webui)) | Requires Local Setup, see oobabooga docs |
| Phind | Developer focused chat with [finetuned CodeLlama](https://www.phind.com/blog/code-llama-beats-gpt4) |
| Stable Chat | Chat interface for [Stable Beluga](https://stability.ai/blog/stable-beluga-large-instruction-fine-tuned-models), an open LLM by Stability AI. |
| [OpenRouter](https://openrouter.ai) | Access GPT4, Claude, PaLM, and open source models |
| OpenAssistant | Coming Soon — [Submit a PR](https://github.com/smol-ai/GodMode/issues/37)! |
| Claude 1 | Requires Beta Access |
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Vercel from 'providers/vercel';
import OpenRouter from '../providers/openrouter';
import Poe from 'providers/poe';
import InflectionPi from 'providers/inflection';
import StableChat from 'providers/stablechat';

export const allProviders = [
OpenAi,
Expand All @@ -29,6 +30,7 @@ export const allProviders = [
Poe,
InflectionPi,
HuggingChat,
StableChat,
OobaBooga,
Together,
OpenRouter,
Expand Down
68 changes: 68 additions & 0 deletions src/providers/stablechat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const Provider = require('./provider');

class StableChat extends Provider {
static webviewId = 'webviewStableChat';
static fullName = 'Stable Chat (Stability AI)';
static shortName = 'StableChat';

static url = 'https://chat.stability.ai';

static handleInput(input) {
this.getWebview().executeJavaScript(`{
var inputElement = document.querySelector('textarea[placeholder="Type something here..."]');
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('textarea[placeholder="Type something here..."] + button');
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(`
// .mt-lg {
// display: none;
// }
// `);
// }, 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 = StableChat;