Skip to content

Commit

Permalink
Enhance language support and settings in Smart Chat
Browse files Browse the repository at this point in the history
- Updated language handling in SmartThread to use a more direct settings approach.
- Introduced a new language dropdown configuration in SmartThreads with options fetched from a utility function.
- Expanded ScTranslations.json to include additional languages and their respective names, improving multilingual support.
- Added a utility function to retrieve language options for better modularity and maintainability.
  • Loading branch information
brianpetro committed Dec 3, 2024
1 parent 1912c07 commit dbf6c13
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
3 changes: 2 additions & 1 deletion smart-chats/smart_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export class SmartThread extends SmartSource {
}],
context: {},
};
const language = this.env.settings?.language || 'en';
// const language = this.env.settings?.language || 'en';
const language = this.settings.language;

// INLINE PROCESSING
// Handle internal embedded links (![[link]])
Expand Down
12 changes: 11 additions & 1 deletion smart-chats/smart_threads.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SmartSources } from "smart-sources";
import { render as chat_template } from "./components/threads.js";

import { get_language_options } from "./utils/self_referential_keywords.js";
/**
* @class SmartThreads
* @extends SmartSources
Expand Down Expand Up @@ -118,6 +118,13 @@ export class SmartThreads extends SmartSources {
*/
get settings_config() {
return {
"language": {
name: "Language",
type: "dropdown",
options_callback: 'get_language_options',
description: "The language to use for the chat.",
default: 'en'
},
"review_context": {
name: "Review Context",
type: "toggle",
Expand All @@ -138,6 +145,9 @@ export class SmartThreads extends SmartSources {
}
};
}
get_language_options() {
return get_language_options();
}

/**
* Gets the currently active thread based on the chat box data-thread-key
Expand Down
41 changes: 41 additions & 0 deletions smart-chats/utils/ScTranslations.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,68 @@
{
"en": {
"name": "English",
"pronouns": ["my", "I", "me", "mine", "our", "ours", "us", "we"],
"prompt": "Based on your notes",
"initial_message": "Hi, I'm ChatGPT with access to your notes via Smart Connections. Ask me a question about your notes and I'll try to answer it."
},
"es": {
"name": "Español",
"pronouns": ["mi", "yo", "", "", "mis"],
"prompt": "Basándose en sus notas",
"initial_message": "Hola, soy ChatGPT con acceso a tus apuntes a través de Smart Connections. Hazme una pregunta sobre tus apuntes e intentaré responderte."
},
"fr": {
"name": "Français",
"pronouns": ["me", "mon", "ma", "mes", "moi", "nous", "notre", "nos", "je", "j'", "m'"],
"prompt": "D'après vos notes",
"initial_message": "Bonjour, je suis ChatGPT et j'ai accès à vos notes via Smart Connections. Posez-moi une question sur vos notes et j'essaierai d'y répondre."
},
"de": {
"name": "Deutsch",
"pronouns": ["mein", "meine", "meinen", "meiner", "meines", "mir", "uns", "unser", "unseren", "unserer", "unseres"],
"prompt": "Basierend auf Ihren Notizen",
"initial_message": "Hallo, ich bin ChatGPT und habe über Smart Connections Zugang zu Ihren Notizen. Stellen Sie mir eine Frage zu Ihren Notizen und ich werde versuchen, sie zu beantworten."
},
"it": {
"name": "Italiano",
"pronouns": ["mio", "mia", "miei", "mie", "noi", "nostro", "nostri", "nostra", "nostre"],
"prompt": "Sulla base degli appunti",
"initial_message": "Ciao, sono ChatGPT e ho accesso ai tuoi appunti tramite Smart Connections. Fatemi una domanda sui vostri appunti e cercherò di rispondervi."
},
"pt": {
"name": "Português",
"pronouns": ["meu", "eu", "mim", "minha", "nosso", "nosso", "nós", "nós"],
"prompt": "Com base em suas anotações",
"initial_message": "Olá, sou ChatGPT com acesso às suas notas via Smart Connections. Faça-me uma pergunta sobre suas anotações e tentarei respondê-la."
},
"pt-br": {
"name": "Português (Brasil)",
"pronouns": ["eu", "me", "mim", "meu", "meus", "minha", "minhas", "nosso", "nossos", "nossa", "nossas", "nós", "nos", "a gente"],
"prompt": "Baseado no que li das suas notas",
"initial_message": "Olá, sou ChatGPT e posso acessar suas notas por meio do plugin Smart Connections. Pergunte-me algo sobre suas notas e tentarei responder."
},
"ja": {
"name": "日本語",
"pronouns": ["", "自分", "", "", "私達", "この"],
"prompt": "このノートに基づいて",
"initial_message": "こんにちは、スマートコネクションであなたのノートにアクセスできるChatGPTです。あなたのノートに関する質問を私に投げかけてください。"
},
"zh": {
"name": "中文(简体)",
"pronouns": ["", "我的", "我们", "我们的"],
"prompt": "根据你的笔记",
"initial_message": "你好,我是 ChatGPT,可以通过 Smart Connections 访问你的笔记。问我一个关于你笔记的问题,我会尽力回答。"
},
"zh-TW": {
"name": "中文(繁体)",
"pronouns": ["", "我的", "我們", "我們的"],
"prompt": "根據您的筆記",
"initial_message": "嗨,我是ChatGPT,可以透過Smart Connections來查看您的筆記喔。如果您有關於筆記的問題,隨時可以問我,我會盡力回答您。"
},
"ru": {
"name": "Русский",
"pronouns": ["я", "моё", "мое", "мой", "мне", "моих", "мои", "моём", "моем", "наш", "наше", "нашем", "нашему", "нашим", "наши", "мы"],
"prompt": "На основе ваших записей",
"initial_message": "Привет, я ChatGPT, и у меня есть доступ к вашим записям с помощью Smart Connections. Задайте мне вопрос, и я попробую ответить на него."
}
}
4 changes: 4 additions & 0 deletions smart-chats/utils/self_referential_keywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ export function contains_self_referential_keywords(user_input, language) {
if (check_str.match(new RegExp(`\\b(${language_settings.pronouns.join("|")})\\b`, "gi"))) return true;
return false;
}

export function get_language_options(){
return Object.entries(ScTranslations).map(([language, language_settings]) => ({ value: language, name: language_settings.name }));
}

0 comments on commit dbf6c13

Please sign in to comment.