diff --git a/src/assets/locale/da/common.json b/src/assets/locale/da/common.json index 5a60ec5..0c48185 100644 --- a/src/assets/locale/da/common.json +++ b/src/assets/locale/da/common.json @@ -101,5 +101,6 @@ "translate": "Oversæt", "custom": "Brugerdefineret" }, - "citations": "Citater" + "citations": "Citater", + "downloadCode": "Download Kode" } \ No newline at end of file diff --git a/src/assets/locale/de/common.json b/src/assets/locale/de/common.json index 0444973..c70fa49 100644 --- a/src/assets/locale/de/common.json +++ b/src/assets/locale/de/common.json @@ -101,5 +101,6 @@ "translate": "Übersetzen", "custom": "Benutzerdefiniert" }, - "citations": "Zitate" + "citations": "Zitate", + "downloadCode": "Code herunterladen" } \ No newline at end of file diff --git a/src/assets/locale/en/common.json b/src/assets/locale/en/common.json index 7198457..24adfdf 100644 --- a/src/assets/locale/en/common.json +++ b/src/assets/locale/en/common.json @@ -105,5 +105,6 @@ "segmented": { "ollama": "Ollama Models", "custom": "Custom Models" - } + }, + "downloadCode": "Download Code" } \ No newline at end of file diff --git a/src/assets/locale/es/common.json b/src/assets/locale/es/common.json index 33dd76a..b713319 100644 --- a/src/assets/locale/es/common.json +++ b/src/assets/locale/es/common.json @@ -100,5 +100,6 @@ "rephrase": "Reformular", "translate": "Traducir" }, - "citations": "Citas" + "citations": "Citas", + "downloadCode": "Descargar Código" } \ No newline at end of file diff --git a/src/assets/locale/fa/common.json b/src/assets/locale/fa/common.json index 1dd3ddd..432934e 100644 --- a/src/assets/locale/fa/common.json +++ b/src/assets/locale/fa/common.json @@ -94,5 +94,6 @@ }, "advanced": "تنظیمات بیشتر مدل" }, - "citations": "منابع" + "citations": "منابع", + "downloadCode": "دانلود کد" } \ No newline at end of file diff --git a/src/assets/locale/fr/common.json b/src/assets/locale/fr/common.json index 03cd970..8c214b1 100644 --- a/src/assets/locale/fr/common.json +++ b/src/assets/locale/fr/common.json @@ -100,5 +100,6 @@ "rephrase": "Reformuler", "translate": "Traduire" }, - "citations": "Citations" + "citations": "Citations", + "downloadCode": "Télécharger le code" } \ No newline at end of file diff --git a/src/assets/locale/it/common.json b/src/assets/locale/it/common.json index 6e7cd38..6aba664 100644 --- a/src/assets/locale/it/common.json +++ b/src/assets/locale/it/common.json @@ -100,5 +100,6 @@ "rephrase": "Riformulare", "translate": "Tradurre" }, - "citations": "Citazioni" + "citations": "Citazioni", + "downloadCode": "Scarica Codice" } \ No newline at end of file diff --git a/src/assets/locale/ja-JP/common.json b/src/assets/locale/ja-JP/common.json index 4bb7061..814ca9d 100644 --- a/src/assets/locale/ja-JP/common.json +++ b/src/assets/locale/ja-JP/common.json @@ -100,5 +100,6 @@ "rephrase": "言い換え", "translate": "翻訳" }, - "citations": "引用" + "citations": "引用", + "downloadCode": "コードをダウンロード" } \ No newline at end of file diff --git a/src/assets/locale/ml/common.json b/src/assets/locale/ml/common.json index 9f00717..693d9fb 100644 --- a/src/assets/locale/ml/common.json +++ b/src/assets/locale/ml/common.json @@ -99,5 +99,6 @@ "rephrase": "പുനഃരൂപീകരിക്കുക", "translate": "വിവർത്തനം ചെയ്യുക" }, - "citations": "ഉദ്ധരണികൾ" + "citations": "ഉദ്ധരണികൾ", + "downloadCode": "കോഡ് ഡൗൺലോഡ് ചെയ്യുക" } \ No newline at end of file diff --git a/src/assets/locale/no/common.json b/src/assets/locale/no/common.json index 99c91ce..665cae5 100644 --- a/src/assets/locale/no/common.json +++ b/src/assets/locale/no/common.json @@ -101,5 +101,6 @@ "translate": "Oversett", "custom": "Egendefinert" }, - "citations": "Sitater" + "citations": "Sitater", + "downloadCode": "Last ned kode" } \ No newline at end of file diff --git a/src/assets/locale/pt-BR/common.json b/src/assets/locale/pt-BR/common.json index c09c1b4..dbf6af6 100644 --- a/src/assets/locale/pt-BR/common.json +++ b/src/assets/locale/pt-BR/common.json @@ -100,5 +100,6 @@ "rephrase": "Reformular", "translate": "Traduzir" }, - "citations": "Citações" + "citations": "Citações", + "downloadCode": "Baixar Código" } \ No newline at end of file diff --git a/src/assets/locale/ru/common.json b/src/assets/locale/ru/common.json index 582896c..5b4fedd 100644 --- a/src/assets/locale/ru/common.json +++ b/src/assets/locale/ru/common.json @@ -100,5 +100,6 @@ "rephrase": "Перефразировать", "translate": "Перевести" }, - "citations": "Цитаты" + "citations": "Цитаты", + "downloadCode": "Скачать код" } \ No newline at end of file diff --git a/src/assets/locale/zh/common.json b/src/assets/locale/zh/common.json index ddb08b4..9019aa5 100644 --- a/src/assets/locale/zh/common.json +++ b/src/assets/locale/zh/common.json @@ -100,5 +100,6 @@ "rephrase": "重述", "translate": "翻译" }, - "citations": "引用" + "citations": "引用", + "downloadCode": "下载代码" } \ No newline at end of file diff --git a/src/components/Common/CodeBlock.tsx b/src/components/Common/CodeBlock.tsx index 9fd759d..af1e363 100644 --- a/src/components/Common/CodeBlock.tsx +++ b/src/components/Common/CodeBlock.tsx @@ -1,5 +1,6 @@ +import { programmingLanguages } from "@/utils/langauge-extension" import { Tooltip, Modal } from "antd" -import { CheckIcon, ClipboardIcon, EyeIcon, Maximize2Icon } from "lucide-react" +import { CheckIcon, ClipboardIcon, DownloadIcon } from "lucide-react" import { FC, useState } from "react" import { useTranslation } from "react-i18next" import { Prism as SyntaxHighlighter } from "react-syntax-highlighter" @@ -23,30 +24,36 @@ export const CodeBlock: FC = ({ language, value }) => { }, 4000) } - const handlePreview = () => { - setPreviewVisible(true) - } - const handlePreviewClose = () => { setPreviewVisible(false) } + const handleDownload = () => { + const blob = new Blob([value], { type: "text/plain" }) + const url = window.URL.createObjectURL(blob) + const a = document.createElement("a") + a.href = url + a.download = `code_${new Date().toISOString().replace(/[:.]/g, "-")}.${programmingLanguages[language] || language}` + document.body.appendChild(a) + a.click() + document.body.removeChild(a) + window.URL.revokeObjectURL(url) + } + return ( <>
{language} -
- {language.toLowerCase() === "html" && ( - - - - )} +
+ + +
diff --git a/src/components/Option/Playground/PlaygroundChat.tsx b/src/components/Option/Playground/PlaygroundChat.tsx index 0049fba..4a2795b 100644 --- a/src/components/Option/Playground/PlaygroundChat.tsx +++ b/src/components/Option/Playground/PlaygroundChat.tsx @@ -61,10 +61,10 @@ export const PlaygroundChat = () => { )}
{!isAtBottom && ( -
+
diff --git a/src/hooks/useMessageOption.tsx b/src/hooks/useMessageOption.tsx index 3b38353..c7a2edb 100644 --- a/src/hooks/useMessageOption.tsx +++ b/src/hooks/useMessageOption.tsx @@ -8,7 +8,7 @@ import { systemPromptForNonRagOption } from "~/services/ollama" import { type ChatHistory, type Message } from "~/store/option" -import { HumanMessage, SystemMessage } from "@langchain/core/messages" +import { SystemMessage } from "@langchain/core/messages" import { useStoreMessageOption } from "~/store/option" import { deleteChatForEdit, diff --git a/src/utils/langauge-extension.ts b/src/utils/langauge-extension.ts new file mode 100644 index 0000000..e8f8ea2 --- /dev/null +++ b/src/utils/langauge-extension.ts @@ -0,0 +1,29 @@ +export const programmingLanguages = { + html: "html", + javascript: "js", + typescript: "ts", + python: "py", + java: "java", + cpp: "cpp", + c: "c", + csharp: "cs", + ruby: "rb", + php: "php", + swift: "swift", + go: "go", + rust: "rs", + kotlin: "kt", + sql: "sql", + shell: "sh", + markdown: "md", + json: "json", + yaml: "yml", + xml: "xml", + css: "css", + scss: "scss", + jsx: "jsx", + tsx: "tsx", + vue: "vue", + dart: "dart", + lua: "lua" +} \ No newline at end of file