Skip to content

frontend/jupyter: add "Ask a Question" option to LLM cell tool #8503

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
57 changes: 55 additions & 2 deletions src/packages/frontend/account/i18n-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@
*/

/*
Basically a drop-down to change the langauge (i18n localization)
Basically a drop-down to change the language (i18n localization)
*/

import { DownOutlined } from "@ant-design/icons";
import { Button, Dropdown, MenuProps, Modal, Space, Tooltip } from "antd";
import {
Button,
Dropdown,
MenuProps,
Modal,
Select,
SelectProps,
Space,
Tooltip,
} from "antd";
import { SizeType } from "antd/es/config-provider/SizeContext";
import { useState } from "react";
import { defineMessage, useIntl } from "react-intl";
Expand Down Expand Up @@ -54,6 +63,50 @@ Thank you for your patience and understanding as we work to make our application
description: "Content of translation information modal",
});

interface LanguageSelectorProps
extends Omit<SelectProps, "options" | "onChange"> {
value?: string;
onChange?: (language: string) => void;
}

/**
* A reusable language selector component for translation purposes.
*/
export function LanguageSelector({
value,
onChange,
...props
}: LanguageSelectorProps) {
const intl = useIntl();

let availableLocales = Object.keys(LOCALIZATIONS) as Locale[];

const options = availableLocales.map((locale) => {
const localization = LOCALIZATIONS[locale];
const other =
locale === value
? localization.name
: intl.formatMessage(localization.trans);
return {
value: locale,
label: `${localization.flag} ${localization.native} (${other})`,
};
});

return (
<Select
value={value}
onChange={onChange}
options={options}
placeholder="Select a language..."
showSearch
optionFilterProp="label"
popupMatchSelectWidth={false}
{...props}
/>
);
}

export function I18NSelector(props: Readonly<Props>) {
const { isWide = true, size, confirm = false } = props;

Expand Down
7 changes: 5 additions & 2 deletions src/packages/frontend/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"undeleting",
"revealjs",
"conat",
"SocketIO"
"SocketIO",
"formatjs",
"simplelocalize"
],
"ignoreWords": [
"antd",
Expand All @@ -70,7 +72,8 @@
"flyouts",
"buttonbar",
"noconf",
"flyoutdragbar"
"flyoutdragbar",
"descr"
],
"flagWords": [],
"ignorePaths": ["node_modules/**", "dist/**", "dist-ts/**", "build/**"],
Expand Down
2 changes: 1 addition & 1 deletion src/packages/frontend/frame-editors/llm/consts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// number of characters we send to an LLM for context
export const CUTOFF = 3000;
export const CUTOFF = 5000;

// this came from ./create-chat, but for all frame types
export const AI_ASSIST_TAG = "code-editor";
28 changes: 28 additions & 0 deletions src/packages/frontend/i18n/bin/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,31 @@ check_api_key() {
exit 1
fi
}

# Execute a function for each language, optionally in parallel
# Usage: run_for_each_lang <function_name>
run_for_each_lang() {
local func_name="$1"

if [ -z "$func_name" ]; then
echo "Error: function name is required" >&2
exit 1
fi

start_time=$(date +%s)

if command -v parallel &>/dev/null; then
echo "Parallel is installed. Running $func_name in parallel."
export -f "$func_name"
echo "$LANGS" | tr ' ' '\n' | parallel -j8 --delay 0.1 --will-cite "$func_name"
else
echo "Parallel is not installed. Running $func_name sequentially."
for L in $LANGS; do
"$func_name" "$L"
done
fi

end_time=$(date +%s)
execution_time=$((end_time - start_time))
echo "$func_name completed in ${execution_time} seconds."
}
14 changes: 10 additions & 4 deletions src/packages/frontend/i18n/bin/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
# It was necessary to write a custom formatter (see formatter.js) – not clear why, but it works. It's just a trivial mapping.
# "--ast" this is the main point of compiling: we use ICU messages, which no longer need to be parsed each time.
# This compile step is called by the `pnpm build` step as well, hence there is no need to keep the compiled files in the sources.
for L in $LANGS; do

# Each language is compiled into a separate file – this allows for dynamic imports.
compile() {
local lang="$1"
echo "compiling '$lang'"
pnpm exec formatjs compile \
--ast \
--format i18n/formatter.js \
--out-file ./i18n/trans/$L.compiled.json \
./i18n/trans/$L.json
done
--out-file ./i18n/trans/$lang.compiled.json \
./i18n/trans/$lang.json
}

run_for_each_lang compile
13 changes: 2 additions & 11 deletions src/packages/frontend/i18n/bin/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

check_api_key

# Each language is downloaded into a spearate file and compiled – this allows for dynamic imports.
# Each language is downloaded into a separate file and compiled – this allows for dynamic imports.
download() {
local lang="$1"
echo "calling download '$lang'"
Expand All @@ -14,13 +14,4 @@ download() {
--languageKey="$lang"
}

if command -v parallel &>/dev/null; then
echo "Parallel is installed. Running downloads in parallel."
export -f download
echo "$LANGS" | tr ' ' '\n' | parallel -j8 --delay 0.1 --will-cite download
else
echo "Parallel is not installed. Running downloads sequentially."
for L in $LANGS; do
download "$L"
done
fi
run_for_each_lang download
25 changes: 22 additions & 3 deletions src/packages/frontend/i18n/trans/ar_EG.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,8 @@
"jupyter.cell-buttonbar-menu.paste-cell-below": "لصق الخلية أدناه",
"jupyter.cell-buttonbar-menu.paste-clipboard": "لصق من الحافظة",
"jupyter.cell-buttonbar-menu.split-cell": "قسّم الخلية عند المؤشر",
"jupyter.cell-buttonbr.format-button.label": "تنسيق",
"jupyter.cell-buttonbr.format-button.tooltip": "نسّق هذا الكود ليبدو جميلاً",
"jupyter.cell-buttonbar.format-button.label": "تنسيق",
"jupyter.cell-buttonbar.format-button.tooltip": "نسّق هذا الكود ليبدو جميلاً",
"jupyter.commands.cell_toolbar_attachments.label": "شريط أدوات المرفقات",
"jupyter.commands.cell_toolbar_attachments.menu": "المرفقات",
"jupyter.commands.cell_toolbar_create_assignment.label": "إنشاء واجب باستخدام NBgrader",
Expand Down Expand Up @@ -812,6 +812,8 @@
"jupyter.editor.run_all_cells.label": "تشغيل جميع الخلايا",
"jupyter.editor.run_selected_cells.label": "تشغيل الخلايا المحددة",
"jupyter.editor.snippets_tooltip": "افتح لوحة تحتوي على مقتطفات الكود",
"jupyter.llm.cell-tool.actions.ask.descr": "اطرح سؤالاً مخصصاً حول الكود في هذه الخلية.",
"jupyter.llm.cell-tool.actions.ask.label": "اسأل",
"jupyter.llm.cell-tool.actions.bugfix.descr": "وصف مشكلة تلك الخلية للحصول على نسخة مصححة من الخطأ",
"jupyter.llm.cell-tool.actions.bugfix.label": "إصلاح الأخطاء",
"jupyter.llm.cell-tool.actions.document.descr": "إضافة التوثيق",
Expand All @@ -820,22 +822,39 @@
"jupyter.llm.cell-tool.actions.explain.label": "اشرح",
"jupyter.llm.cell-tool.actions.improve.descr": "حسّن الشيفرة في تلك الخلية",
"jupyter.llm.cell-tool.actions.improve.label": "تحسين",
"jupyter.llm.cell-tool.actions.md.ask.descr": "اطرح سؤالًا مخصصًا حول هذه الخلية مع سياق اختياري من الخلايا المحيطة.",
"jupyter.llm.cell-tool.actions.md.document.descr": "اكتب ملخصًا حول جميع الخلايا في السياق",
"jupyter.llm.cell-tool.actions.md.document.label": "توثيق",
"jupyter.llm.cell-tool.actions.md.formulize.descr": "أضف صيغًا رياضية لجعل النص أكثر قابلية للقراءة للعلماء.",
"jupyter.llm.cell-tool.actions.md.formulize.label": "إضافة صيغ",
"jupyter.llm.cell-tool.actions.md.proofread.descr": "تحسين اللغة، إصلاح الأخطاء الإملائية والنحوية.",
"jupyter.llm.cell-tool.actions.md.proofread.label": "تدقيق",
"jupyter.llm.cell-tool.actions.md.translate-text.descr": "ترجمة محتوى النص إلى لغة بشرية أخرى.",
"jupyter.llm.cell-tool.actions.md.translate-text.label": "ترجمة",
"jupyter.llm.cell-tool.actions.modify.descr": "عدل الكود في الخلية",
"jupyter.llm.cell-tool.actions.modify.label": "تعديل",
"jupyter.llm.cell-tool.actions.translate.descr": "ترجمة الشيفرة في تلك الخلية إلى لغة أخرى باستخدام الذكاء الاصطناعي.",
"jupyter.llm.cell-tool.actions.translate.label": "ترجمة",
"jupyter.llm.cell-tool.ask.label": "سؤال",
"jupyter.llm.cell-tool.ask.placeholder": "ماذا تريد أن تعرف عن هذا الرمز؟",
"jupyter.llm.cell-tool.assistant.title": "استخدم مساعد الذكاء الاصطناعي على هذه الخلية",
"jupyter.llm.cell-tool.bugfix.label": "خلل",
"jupyter.llm.cell-tool.bugfix.placeholder": "صف المشكلة التي تحتاج إلى إصلاحها...",
"jupyter.llm.cell-tool.document.label": "تركيز",
"jupyter.llm.cell-tool.document.placeholder": "على ماذا يجب أن تركز الوثائق؟ (اختياري)",
"jupyter.llm.cell-tool.explain.description": "كيف تشرح الشيفرة؟ إما {summary} عالي المستوى أو {step_by_step} تفسيرات.",
"jupyter.llm.cell-tool.explain.step-by-step": "خطوة بخطوة",
"jupyter.llm.cell-tool.explain.summary": "ملخص",
"jupyter.llm.cell-tool.explanation.ask": "اطرح أي سؤال حول الكود في هذه الخلية. سيقوم نموذج اللغة بتحليل الكود وتقديم إجابة بناءً على سؤالك المحدد.",
"jupyter.llm.cell-tool.explanation.bugfix": "اشرح مشكلة الكود في الخلية وسيحاول النموذج اللغوي المحدد إصلاحها. عادةً، سيخبرك إذا وجد مشكلة ويشرحها لك.",
"jupyter.llm.cell-tool.explanation.document": "سيقوم نموذج اللغة بإضافة سطور التوثيق إلى الكود في الخلية.",
"jupyter.llm.cell-tool.explanation.explain": "سيتم إرسال الكود في الخلية إلى النموذج اللغوي المحدد. سيوضح لك الكود بلغة بسيطة.",
"jupyter.llm.cell-tool.explanation.improve": "سيقوم نموذج اللغة المحدد بتحليل الكود واقتراح التحسينات. احذر، فالنتائج ليست مضمونة أن تكون صحيحة، وقد تسبب مشكلات دقيقة - راجعها بعناية.",
"jupyter.llm.cell-tool.explanation.formulize": "سيضيف نموذج اللغة الصيغ الرياضية المناسبة باستخدام ترميز LaTeX لجعل النص أكثر وضوحًا للعلماء.",
"jupyter.llm.cell-tool.explanation.improve": "سيقوم نموذج اللغة المحدد بتحليل الشفرة واقتراح تحسينات. احذر، فالنتائج لا يُضمن أن تكون صحيحة، وقد تسبب مشاكل طفيفة – راجعها بعناية.",
"jupyter.llm.cell-tool.explanation.modify": "سيقوم نموذج اللغة بتعديل الكود وفقًا للتعليمات المعطاة. اختر أحد النماذج وقم بتعديله، أو ابتكر تعليمات خاصة بك!",
"jupyter.llm.cell-tool.explanation.proofread": "سيقوم نموذج اللغة بمراجعة نص الماركداون، وتصحيح الأخطاء الإملائية والنحوية مع تحسين الوضوح وسهولة القراءة.",
"jupyter.llm.cell-tool.explanation.translate": "سيحاول نموذج اللغة ترجمة الكود في الخلية إلى لغة برمجة أخرى. قد لا يعمل الناتج على الإطلاق - ولكن إذا كنت أكثر دراية بلغة الهدف المختارة، فقد تجد من الأسهل فهم ما يحدث!",
"jupyter.llm.cell-tool.explanation.translate-text": "سيقوم نموذج اللغة بترجمة نصوص الماركداون إلى اللغة المحددة مع الحفاظ على التنسيق والهيكل.",
"jupyter.llm.cell-tool.footer.info": "إرسال هذه الرسالة إلى {model} سيبدأ محادثة في <A>إطار الدردشة الجانبية</A>. سيرد نموذج اللغة ويمكنك متابعة المحادثة في نفس الموضوع.",
"jupyter.llm.cell-tool.improve.label": "تحسين",
"jupyter.llm.cell-tool.improve.placeholder": "سرعة التنفيذ، القابلية للقراءة، …",
Expand Down
25 changes: 22 additions & 3 deletions src/packages/frontend/i18n/trans/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,8 @@
"jupyter.cell-buttonbar-menu.paste-cell-below": "Zelle darunter einfügen",
"jupyter.cell-buttonbar-menu.paste-clipboard": "Aus Zwischenablage einfügen",
"jupyter.cell-buttonbar-menu.split-cell": "Zelle am Cursor teilen",
"jupyter.cell-buttonbr.format-button.label": "Format",
"jupyter.cell-buttonbr.format-button.tooltip": "Formatieren Sie diesen Code, damit er gut aussieht",
"jupyter.cell-buttonbar.format-button.label": "Format",
"jupyter.cell-buttonbar.format-button.tooltip": "Formatieren Sie diesen Code, damit er gut aussieht",
"jupyter.commands.cell_toolbar_attachments.label": "Werkzeugleiste für Anhänge",
"jupyter.commands.cell_toolbar_attachments.menu": "Anhänge",
"jupyter.commands.cell_toolbar_create_assignment.label": "Aufgabe mit NBgrader erstellen",
Expand Down Expand Up @@ -812,6 +812,8 @@
"jupyter.editor.run_all_cells.label": "Alle Zellen ausführen",
"jupyter.editor.run_selected_cells.label": "Ausgewählte Zellen ausführen",
"jupyter.editor.snippets_tooltip": "Öffnen Sie ein Panel mit Code-Snippets.",
"jupyter.llm.cell-tool.actions.ask.descr": "Stellen Sie eine benutzerdefinierte Frage zu dem Code in dieser Zelle.",
"jupyter.llm.cell-tool.actions.ask.label": "Fragen",
"jupyter.llm.cell-tool.actions.bugfix.descr": "Beschreibe das Problem dieser Zelle, um eine fehlerbereinigte Version zu erhalten.",
"jupyter.llm.cell-tool.actions.bugfix.label": "Fehler beheben",
"jupyter.llm.cell-tool.actions.document.descr": "Dokumentation hinzufügen",
Expand All @@ -820,22 +822,39 @@
"jupyter.llm.cell-tool.actions.explain.label": "Erklären",
"jupyter.llm.cell-tool.actions.improve.descr": "Verbessern des Codes in dieser Zelle.",
"jupyter.llm.cell-tool.actions.improve.label": "Verbessern",
"jupyter.llm.cell-tool.actions.md.ask.descr": "Stellen Sie eine benutzerdefinierte Frage zu dieser Zelle mit optionalem Kontext aus den umliegenden Zellen.",
"jupyter.llm.cell-tool.actions.md.document.descr": "Schreiben Sie eine Zusammenfassung über alle Zellen im Kontext",
"jupyter.llm.cell-tool.actions.md.document.label": "Dokumentieren",
"jupyter.llm.cell-tool.actions.md.formulize.descr": "Fügen Sie mathematische Formeln hinzu, um den Text für Wissenschaftler lesbarer zu machen.",
"jupyter.llm.cell-tool.actions.md.formulize.label": "Formeln hinzufügen",
"jupyter.llm.cell-tool.actions.md.proofread.descr": "Sprache verbessern, Rechtschreib- und Grammatikfehler beheben.",
"jupyter.llm.cell-tool.actions.md.proofread.label": "Korrekturlesen",
"jupyter.llm.cell-tool.actions.md.translate-text.descr": "Übersetze den Textinhalt in eine andere menschliche Sprache.",
"jupyter.llm.cell-tool.actions.md.translate-text.label": "Übersetzen",
"jupyter.llm.cell-tool.actions.modify.descr": "Ändern des Codes in der Zelle",
"jupyter.llm.cell-tool.actions.modify.label": "Ändern",
"jupyter.llm.cell-tool.actions.translate.descr": "Übersetze den Code in dieser Zelle in eine andere Sprache mit KI.",
"jupyter.llm.cell-tool.actions.translate.label": "Übersetzen",
"jupyter.llm.cell-tool.ask.label": "Frage",
"jupyter.llm.cell-tool.ask.placeholder": "Was möchten Sie über diesen Code wissen?",
"jupyter.llm.cell-tool.assistant.title": "AI-Assistent für diese Zelle verwenden",
"jupyter.llm.cell-tool.bugfix.label": "Fehler",
"jupyter.llm.cell-tool.bugfix.placeholder": "Beschreiben Sie das zu behebende Problem…",
"jupyter.llm.cell-tool.document.label": "Fokus",
"jupyter.llm.cell-tool.document.placeholder": "Worauf sollte die Dokumentation fokussieren? (optional)",
"jupyter.llm.cell-tool.explain.description": "Wie erklärt man den Code? Entweder eine hochrangige {summary} oder {step_by_step} Erklärungen.",
"jupyter.llm.cell-tool.explain.step-by-step": "Schritt-für-Schritt",
"jupyter.llm.cell-tool.explain.summary": "Zusammenfassung",
"jupyter.llm.cell-tool.explanation.ask": "Stellen Sie jede Frage zum Code in dieser Zelle. Das Sprachmodell wird den Code analysieren und basierend auf Ihrer spezifischen Frage eine Antwort geben.",
"jupyter.llm.cell-tool.explanation.bugfix": "Erklären Sie das Problem des Codes in der Zelle, und das ausgewählte Sprachmodell wird versuchen, es zu beheben. Normalerweise wird es Ihnen mitteilen, ob es ein Problem gefunden hat und es Ihnen erklären.",
"jupyter.llm.cell-tool.explanation.document": "Das Sprachmodell wird Dokumentationszeilen zum Code in der Zelle hinzufügen.",
"jupyter.llm.cell-tool.explanation.explain": "Der Code in der Zelle wird an das ausgewählte Sprachmodell gesendet. Es wird den Code in einfacher Sprache erklären.",
"jupyter.llm.cell-tool.explanation.improve": "Das ausgewählte Sprachmodell wird den Code analysieren und Verbesserungen vorschlagen. Seien Sie sich bewusst, dass die Ergebnisse nicht garantiert korrekt sind und subtile Probleme verursachen könnten – überprüfen Sie sie sorgfältig.",
"jupyter.llm.cell-tool.explanation.formulize": "Das Sprachmodell wird geeignete mathematische Formeln unter Verwendung der LaTeX-Notation hinzufügen, um den Text für Wissenschaftler lesbarer zu machen.",
"jupyter.llm.cell-tool.explanation.improve": "Das ausgewählte Sprachmodell wird den Code analysieren und Verbesserungen vorschlagen. Beachten Sie, dass die Ergebnisse nicht garantiert korrekt sind und subtile Probleme verursachen können – überprüfen Sie sie sorgfältig.",
"jupyter.llm.cell-tool.explanation.modify": "Das Sprachmodell wird den Code gemäß den gegebenen Anweisungen ändern. Wählen Sie eine der Vorlagen aus und passen Sie sie an, oder denken Sie sich eigene Anweisungen aus!",
"jupyter.llm.cell-tool.explanation.proofread": "Das Sprachmodell wird den Markdown-Text korrigieren, indem es Rechtschreib- und Grammatikfehler behebt und gleichzeitig Klarheit und Lesbarkeit verbessert.",
"jupyter.llm.cell-tool.explanation.translate": "Das Sprachmodell wird versuchen, den Code in der Zelle in eine andere Programmiersprache zu übersetzen. Das Ergebnis könnte überhaupt nicht funktionieren – aber wenn du mit der ausgewählten Zielsprache vertrauter bist, findest du es vielleicht einfacher zu verstehen, was vor sich geht!",
"jupyter.llm.cell-tool.explanation.translate-text": "Das Sprachmodell wird den Markdown-Text in die ausgewählte Sprache übersetzen, während Formatierung und Struktur beibehalten werden.",
"jupyter.llm.cell-tool.footer.info": "Das Übermitteln dieser Nachricht an {model} wird einen Chat im <A>Seiten-Chat-Fenster</A> starten. Das Sprachmodell antwortet und Sie können das Gespräch im selben Thread fortsetzen.",
"jupyter.llm.cell-tool.improve.label": "Verbesserung",
"jupyter.llm.cell-tool.improve.placeholder": "Ausführungsgeschwindigkeit, Lesbarkeit, …",
Expand Down
Loading