mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-10-19 05:48:15 +00:00
feat(app): lint & beautify
This commit is contained in:
@@ -2,9 +2,7 @@ import { Dialog, DialogPanel } from '@headlessui/react';
|
|||||||
import { Loader2, Trash2 } from 'lucide-react';
|
import { Loader2, Trash2 } from 'lucide-react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { AnimatePresence, motion } from 'framer-motion';
|
import { AnimatePresence, motion } from 'framer-motion';
|
||||||
import {
|
import { ConfigModelProvider } from '@/lib/config/types';
|
||||||
ConfigModelProvider,
|
|
||||||
} from '@/lib/config/types';
|
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
const DeleteProvider = ({
|
const DeleteProvider = ({
|
||||||
@@ -83,8 +81,9 @@ const DeleteProvider = ({
|
|||||||
</div>
|
</div>
|
||||||
<div className="border-t border-light-200 dark:border-dark-200" />
|
<div className="border-t border-light-200 dark:border-dark-200" />
|
||||||
<div className="flex-1 overflow-y-auto px-6 py-4">
|
<div className="flex-1 overflow-y-auto px-6 py-4">
|
||||||
<p className='text-SM text-black/60 dark:text-white/60'>
|
<p className="text-SM text-black/60 dark:text-white/60">
|
||||||
Are you sure you want to delete the provider "{modelProvider.name}"? This action cannot be undone.
|
Are you sure you want to delete the provider "
|
||||||
|
{modelProvider.name}"? This action cannot be undone.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="px-6 py-6 flex justify-end space-x-2">
|
<div className="px-6 py-6 flex justify-end space-x-2">
|
||||||
|
@@ -129,7 +129,11 @@ const ModelProvider = ({
|
|||||||
<div className="flex flex-row items-center gap-2 text-sm text-red-500 dark:text-red-400 rounded-lg bg-red-50 dark:bg-red-950/20 px-3 py-2 border border-red-200 dark:border-red-900/30">
|
<div className="flex flex-row items-center gap-2 text-sm text-red-500 dark:text-red-400 rounded-lg bg-red-50 dark:bg-red-950/20 px-3 py-2 border border-red-200 dark:border-red-900/30">
|
||||||
<AlertCircle size={16} className="shrink-0" />
|
<AlertCircle size={16} className="shrink-0" />
|
||||||
<span className="break-words">
|
<span className="break-words">
|
||||||
{modelProvider.chatModels.find((m) => m.key === 'error')?.name}
|
{
|
||||||
|
modelProvider.chatModels.find(
|
||||||
|
(m) => m.key === 'error',
|
||||||
|
)?.name
|
||||||
|
}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
@@ -167,11 +171,17 @@ const ModelProvider = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
{modelProvider.embeddingModels.some((m) => m.key === 'error') ? (
|
{modelProvider.embeddingModels.some(
|
||||||
|
(m) => m.key === 'error',
|
||||||
|
) ? (
|
||||||
<div className="flex flex-row items-center gap-2 text-sm text-red-500 dark:text-red-400 rounded-lg bg-red-50 dark:bg-red-950/20 px-3 py-2 border border-red-200 dark:border-red-900/30">
|
<div className="flex flex-row items-center gap-2 text-sm text-red-500 dark:text-red-400 rounded-lg bg-red-50 dark:bg-red-950/20 px-3 py-2 border border-red-200 dark:border-red-900/30">
|
||||||
<AlertCircle size={16} className="shrink-0" />
|
<AlertCircle size={16} className="shrink-0" />
|
||||||
<span className="break-words">
|
<span className="break-words">
|
||||||
{modelProvider.embeddingModels.find((m) => m.key === 'error')?.name}
|
{
|
||||||
|
modelProvider.embeddingModels.find(
|
||||||
|
(m) => m.key === 'error',
|
||||||
|
)?.name
|
||||||
|
}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
@@ -11,4 +11,5 @@ export const getConfiguredModelProviderById = (
|
|||||||
return getConfiguredModelProviders().find((p) => p.id === id) ?? undefined;
|
return getConfiguredModelProviders().find((p) => p.id === id) ?? undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSearxngURL = () => configManager.getConfig('search.searxngURL', '')
|
export const getSearxngURL = () =>
|
||||||
|
configManager.getConfig('search.searxngURL', '');
|
||||||
|
@@ -17,7 +17,6 @@ type StringUIConfigField = BaseUIConfigField & {
|
|||||||
|
|
||||||
type SelectUIConfigFieldOptions = {
|
type SelectUIConfigFieldOptions = {
|
||||||
name: string;
|
name: string;
|
||||||
key: string;
|
|
||||||
value: string;
|
value: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -56,8 +55,8 @@ type Config = {
|
|||||||
};
|
};
|
||||||
modelProviders: ConfigModelProvider[];
|
modelProviders: ConfigModelProvider[];
|
||||||
search: {
|
search: {
|
||||||
[key: string]: any
|
[key: string]: any;
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
type EnvMap = {
|
type EnvMap = {
|
||||||
@@ -84,6 +83,8 @@ export type {
|
|||||||
Config,
|
Config,
|
||||||
EnvMap,
|
EnvMap,
|
||||||
UIConfigSections,
|
UIConfigSections,
|
||||||
|
SelectUIConfigField,
|
||||||
|
StringUIConfigField,
|
||||||
ModelProviderUISection,
|
ModelProviderUISection,
|
||||||
ConfigModelProvider,
|
ConfigModelProvider,
|
||||||
};
|
};
|
||||||
|
@@ -5,7 +5,7 @@ import OllamaProvider from './ollama';
|
|||||||
|
|
||||||
export const providers: Record<string, ProviderConstructor<any>> = {
|
export const providers: Record<string, ProviderConstructor<any>> = {
|
||||||
openai: OpenAIProvider,
|
openai: OpenAIProvider,
|
||||||
ollama: OllamaProvider
|
ollama: OllamaProvider,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getModelProvidersUIConfigSection =
|
export const getModelProvidersUIConfigSection =
|
||||||
|
@@ -18,7 +18,9 @@ const providerConfigFields: UIConfigField[] = [
|
|||||||
description: 'The base URL for the Ollama',
|
description: 'The base URL for the Ollama',
|
||||||
required: true,
|
required: true,
|
||||||
placeholder: 'Ollama Base URL',
|
placeholder: 'Ollama Base URL',
|
||||||
default: process.env.DOCKER ? 'http://host.docker.internal:11434' : 'http://localhost:11434',
|
default: process.env.DOCKER
|
||||||
|
? 'http://host.docker.internal:11434'
|
||||||
|
: 'http://localhost:11434',
|
||||||
env: 'OLLAMA_BASE_URL',
|
env: 'OLLAMA_BASE_URL',
|
||||||
scope: 'server',
|
scope: 'server',
|
||||||
},
|
},
|
||||||
@@ -32,20 +34,20 @@ class OllamaProvider extends BaseModelProvider<OllamaConfig> {
|
|||||||
async getDefaultModels(): Promise<ModelList> {
|
async getDefaultModels(): Promise<ModelList> {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${this.config.baseURL}/api/tags`, {
|
const res = await fetch(`${this.config.baseURL}/api/tags`, {
|
||||||
method: "GET",
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-type': 'application/json'
|
'Content-type': 'application/json',
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
const data = await res.json()
|
const data = await res.json();
|
||||||
|
|
||||||
const models: Model[] = data.models.map((m: any) => {
|
const models: Model[] = data.models.map((m: any) => {
|
||||||
return {
|
return {
|
||||||
name: m.name,
|
name: m.name,
|
||||||
key: m.model
|
key: m.model,
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
embedding: models,
|
embedding: models,
|
||||||
@@ -53,7 +55,9 @@ class OllamaProvider extends BaseModelProvider<OllamaConfig> {
|
|||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof TypeError) {
|
if (err instanceof TypeError) {
|
||||||
throw new Error('Error connecting to Ollama API. Please ensure the base URL is correct and the Ollama server is running.');
|
throw new Error(
|
||||||
|
'Error connecting to Ollama API. Please ensure the base URL is correct and the Ollama server is running.',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw err;
|
throw err;
|
||||||
@@ -111,9 +115,7 @@ class OllamaProvider extends BaseModelProvider<OllamaConfig> {
|
|||||||
if (!raw || typeof raw !== 'object')
|
if (!raw || typeof raw !== 'object')
|
||||||
throw new Error('Invalid config provided. Expected object');
|
throw new Error('Invalid config provided. Expected object');
|
||||||
if (!raw.baseURL)
|
if (!raw.baseURL)
|
||||||
throw new Error(
|
throw new Error('Invalid config provided. Base URL must be provided');
|
||||||
'Invalid config provided. Base URL must be provided',
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
baseURL: String(raw.baseURL),
|
baseURL: String(raw.baseURL),
|
||||||
|
@@ -67,7 +67,6 @@ class ModelRegistry {
|
|||||||
chatModels: m.chat,
|
chatModels: m.chat,
|
||||||
embeddingModels: m.embedding,
|
embeddingModels: m.embedding,
|
||||||
});
|
});
|
||||||
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user