-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
90 lines (82 loc) · 2.75 KB
/
page.tsx
File metadata and controls
90 lines (82 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { getLogtoContext } from '@logto/next/server-actions';
import { redirect } from 'next/navigation';
import { validateOllamaHost } from '@/actions/ollama';
import { ModelCard } from '@/components/modelCard';
import { OllamaModelList } from '@/components/OllamaModelList';
import { OpenRouterBadge } from '@/components/OpenRouterConfigButton';
import { OpenRouterModelList } from '@/components/OpenRouterModelList';
import models from '@/consts/models.json' with { type: 'json' };
import { logtoConfig } from '@/lib/auth';
import { prisma } from '@/lib/prisma';
//@ts-expect-error
interface OllamaModelWithStatus extends prisma.customProvider {
isAvailable: boolean;
endpoint: string;
modelCount: number;
id: string;
}
export default async function Home() {
const { claims } = await getLogtoContext(logtoConfig);
if (!claims) {
await redirect('/login');
}
const userKeys = await prisma.apiKey.findMany({
where: {
userId: claims?.sub,
},
});
const userOllamaModels = (await prisma.customProvider.findMany({
where: {
userId: claims?.sub,
type: 'ollama',
},
})) as unknown as OllamaModelWithStatus[];
const userOpenRouterModels = await prisma.customProvider.findMany({
where: {
userId: claims?.sub,
type: 'openrouter',
},
});
for (const model of userOllamaModels) {
try {
const hostInfo = await validateOllamaHost(model.endpoint);
model.isAvailable = hostInfo.isValid;
model.modelCount = hostInfo.modelCount;
} catch (error) {
model.isAvailable = false;
}
}
return (
<div className="container mx-auto p-4">
<h1 className={'text-4xl text-base-content'}>Model Settings</h1>
<h2 className={'mt-5 mb-2 text-base-content text-xl'}>Model Providers</h2>
<div className="grid space-y-2">
{Object.entries(models).map(([providerKey, provider]) => (
<ModelCard
configured={userKeys.some((key) => key.providerId === providerKey)}
description={provider.description}
icon={provider.icon}
id={providerKey}
key={provider.name}
name={provider.name}
/>
))}
</div>
<div className={'mt-5 mb-2 flex flex-row gap-2'}>
<h2 className={'text-base-content text-xl'}>OpenRouter</h2>
<OpenRouterBadge
configured={userKeys.some((key) => key.providerId === 'openrouter')}
/>
</div>
<div className="grid space-y-2">
<OpenRouterModelList models={userOpenRouterModels} />
</div>
<h2 className={'mt-5 mb-2 text-base-content text-xl'}>
Custom Providers (Ollama)
</h2>
<div className="grid space-y-2">
<OllamaModelList models={userOllamaModels} />
</div>
</div>
);
}