chore: Update URL rewrite logic for runtime

This commit is contained in:
n4ze3m
2024-05-12 23:54:48 +05:30
parent 62ffe8346e
commit e94edf5c89
12 changed files with 88 additions and 27 deletions

View File

@@ -5,7 +5,7 @@ import { useTranslation } from "react-i18next"
export const AdvanceOllamaSettings = () => {
const [urlRewriteEnabled, setUrlRewriteEnabled] = useStorage(
"urlRewriteEnabled",
true
false
)
const [rewriteUrl, setRewriteUrl] = useStorage(
@@ -18,7 +18,7 @@ export const AdvanceOllamaSettings = () => {
<div className="space-y-4">
<div className="flex sm:flex-row flex-col space-y-4 sm:space-y-0 sm:justify-between">
<span className="text-gray-500 dark:text-neutral-50 ">
{t("generalSettings.settings.advanced.urlRewriteEnabled.label")}
{t("ollamaSettings.settings.advanced.urlRewriteEnabled.label")}
</span>
<div>
<Switch
@@ -30,15 +30,15 @@ export const AdvanceOllamaSettings = () => {
</div>
<div className="flex flex-col space-y-4 sm:space-y-0 sm:justify-between">
<span className="text-gray-500 dark:text-neutral-50 mb-3">
{t("generalSettings.settings.advanced.urlRewriteEnabled.label")}
{t("ollamaSettings.settings.advanced.rewriteUrl.label")}
</span>
<div>
<Input
className="w-full"
value={rewriteUrl}
disabled={urlRewriteEnabled}
disabled={!urlRewriteEnabled}
placeholder={t(
"generalSettings.settings.advanced.urlRewriteEnabled.placeholder"
"ollamaSettings.settings.advanced.rewriteUrl.placeholder"
)}
onChange={(e) => setRewriteUrl(e.target.value)}
/>

View File

@@ -1,7 +1,8 @@
import { cleanUrl } from "@/libs/clean-url"
import { useQuery } from "@tanstack/react-query"
import { RotateCcw } from "lucide-react"
import { useEffect, useState } from "react"
import { useTranslation } from "react-i18next"
import { Trans, useTranslation } from "react-i18next"
import {
getOllamaURL,
isOllamaRunning,
@@ -79,6 +80,23 @@ export const PlaygroundEmpty = () => {
<RotateCcw className="h-4 w-4 mr-3" />
{t("common:retry")}
</button>
{ollamaURL &&
cleanUrl(ollamaURL) !== "http://127.0.0.1:11434" && (
<p className="text-xs text-gray-500 dark:text-gray-400 mb-4 text-center">
<Trans
i18nKey="playground:ollamaState.connectionError"
components={{
anchor: (
<a
href="https://github.com/n4ze3m/page-assist/blob/main/docs/connection-issue.md"
target="__blank"
className="text-blue-600 dark:text-blue-400"></a>
)
}}
/>
</p>
)}
</div>
)
) : null}

View File

@@ -12,7 +12,7 @@ import {
setOllamaURL as saveOllamaURL
} from "~/services/ollama"
import { SettingPrompt } from "./prompt"
import { useTranslation } from "react-i18next"
import { Trans, useTranslation } from "react-i18next"
import { useStorage } from "@plasmohq/storage/hook"
import { AdvanceOllamaSettings } from "@/components/Common/AdvanceOllamaSettings"
@@ -87,9 +87,24 @@ export const SettingsOllama = () => {
{
key: "1",
label: (
<h2 className="text-base font-semibold leading-7 text-gray-900 dark:text-white">
{t("ollamaSettings.settings.advanced.label")}
</h2>
<div>
<h2 className="text-base font-semibold leading-7 text-gray-900 dark:text-white">
{t("ollamaSettings.settings.advanced.label")}
</h2>
<p className="text-xs text-gray-500 dark:text-gray-400 mb-4">
<Trans
i18nKey="settings:ollamaSettings.settings.advanced.help"
components={{
anchor: (
<a
href="https://github.com/n4ze3m/page-assist/blob/main/docs/connection-issue.md"
target="__blank"
className="text-blue-600 dark:text-blue-400"></a>
)
}}
/>
</p>
</div>
),
children: <AdvanceOllamaSettings />
}

View File

@@ -1,8 +1,9 @@
import { cleanUrl } from "@/libs/clean-url"
import { useQuery, useQueryClient } from "@tanstack/react-query"
import { Select } from "antd"
import { RotateCcw } from "lucide-react"
import { useEffect, useState } from "react"
import { useTranslation } from "react-i18next"
import { Trans, useTranslation } from "react-i18next"
import { useMessage } from "~/hooks/useMessage"
import {
getAllModels,
@@ -91,6 +92,22 @@ export const EmptySidePanel = () => {
<RotateCcw className="h-4 w-4 mr-3" />
{t("common:retry")}
</button>
{ollamaURL &&
cleanUrl(ollamaURL) !== "http://127.0.0.1:11434" && (
<p className="text-xs text-gray-500 dark:text-gray-400 mb-4 text-center">
<Trans
i18nKey="playground:ollamaState.connectionError"
components={{
anchor: (
<a
href="https://github.com/n4ze3m/page-assist/blob/main/docs/connection-issue.md"
target="__blank"
className="text-blue-600 dark:text-blue-400"></a>
)
}}
/>
</p>
)}
</div>
)
) : null}