Skip to content

Commit

Permalink
ui(frontend): show llm config
Browse files Browse the repository at this point in the history
  • Loading branch information
634750802 committed Jul 30, 2024
1 parent f70760a commit 939fcca
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions frontend/app/src/app/(main)/(admin)/llms/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { deleteLlm, getLlm } from '@/api/llms';
import { AdminPageHeading } from '@/components/admin-page-heading';
import { DangerousActionButton } from '@/components/dangerous-action-button';
import { DateFormat } from '@/components/date-format';
import { ConfigViewer } from '@/components/llm/config-viewer';
import { OptionDetail } from '@/components/option-detail';
import { Loader2Icon } from 'lucide-react';
import { useRouter } from 'next/navigation';
Expand All @@ -29,6 +30,7 @@ export default function Page ({ params }: { params: { id: string } }) {
<OptionDetail title="Name" value={data?.name} />
<OptionDetail title="Provider" value={data?.provider} />
<OptionDetail title="Model" value={data?.model} />
<OptionDetail title="Config" value={data?.config && <ConfigViewer value={data.config}></ConfigViewer>} />
<OptionDetail title="Is Default" value={data?.is_default ? 'Yes' : 'No'} valueClassName={data?.is_default ? 'text-green-500' : 'text-muted-foreground'} />
<OptionDetail title="Created At" value={<DateFormat date={data?.created_at} />} />
<OptionDetail title="Updated At" value={<DateFormat date={data?.updated_at} />} />
Expand Down
40 changes: 40 additions & 0 deletions frontend/app/src/components/llm/config-viewer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use client';

import Highlight from 'highlight.js/lib/core';
import json from 'highlight.js/lib/languages/json';
import { useEffect, useState } from 'react';
import '../code-theme.scss';

Highlight.registerLanguage('json', json);

export function ConfigViewer ({ value: propValue }: { value: any }) {
const [value, setValue] = useState(() => {
if (propValue === undefined) {
return '';
}
try {
return JSON.stringify(propValue, undefined, 2);
} catch {
return '/// FAILED TO STRINGIFY JSON';
}
});

useEffect(() => {
if (propValue === undefined) {
return;
}
try {
const string = JSON.stringify(propValue, undefined, 2);
setValue(string);
const { value: result } = Highlight.highlight('json', string);
setValue(result);
} catch {
}
}, [propValue]);

return (
<code className='block p-2 rounded bg-accent'>
<pre className="whitespace-pre-wrap text-xs font-mono" dangerouslySetInnerHTML={{ __html: value }} />
</code>
);
}

0 comments on commit 939fcca

Please sign in to comment.