diff --git a/src/app/[locale]/doc/page.tsx b/src/app/[locale]/doc/page.tsx index 07319d2..9e61d42 100644 --- a/src/app/[locale]/doc/page.tsx +++ b/src/app/[locale]/doc/page.tsx @@ -1,243 +1,66 @@ -// 'use client' +"use client"; -// import { useEffect, useState } from 'react' +import { useState } from "react"; +import { useSession } from "next-auth/react"; -// export default function AboutPage() { -// const [data, setData] = useState(null) -// const [loading, setLoading] = useState(true) +export default function GenerateKeyButton() { + const [loading, setLoading] = useState(false); + const [result, setResult] = useState(null); -// useEffect(() => { -// fetch((process.env.NEXT_PUBLIC_API_URL as string) + "/docs.json") -// .then((res) => res.json()) -// .then((result) => { -// setData(result) -// setLoading(false) -// }) -// .catch((err) => { -// console.error(err) -// setLoading(false) -// }) -// }, []) + const { data: session, status } = useSession(); -// return ( -//
+ async function handleGenerate() { + setLoading(true); + setResult(null); -// {loading &&

Loading...

} + try { + const res = await fetch("http://localhost:3001/v1/keys/generate", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${session?.accessToken}`, + // "x-api-key": "Q67lQp7NZY2f2Zy6DXYbFoauDMjw79FBD8LPn9ee6OM" + }, + body: JSON.stringify({ + name: "my-api-key", + scopes: ["read", "write"], + }), + }); -// {!loading && data && ( -//
{JSON.stringify(data, null, 2)}
-// )} -//
-// ) -// } + if (!res.ok) { + const errText = await res.text(); + throw new Error(errText); + } -// 'use client'; - -// import { useEffect, useState } from 'react'; -// import Spinner from '@/components/spinner'; - -// export default function AboutPage() { -// const [data, setData] = useState(null); -// const [loading, setLoading] = useState(true); - -// useEffect(() => { -// fetch((process.env.NEXT_PUBLIC_API_URL as string) + '/docs.json') -// .then((res) => res.json()) -// .then((result) => { -// setData(result); -// setLoading(false); -// }) -// .catch(() => { -// setLoading(false); -// }); -// }, []); - -// if (loading) { -// return ( -//
-//
-//
-// ); -// } - -// return ( -//
-// -//
-// ); -// } - -'use client'; - -import Sidebar from '@/components/Sidebar'; -import { SidebarPanel } from '@/components/Sidebar'; -import { - Slider, - NumberInput, - TextInput, - Toggle, -} from '../../../components/Inputs'; - -type PanelProps = { - settings: Settings; - setSettings: React.Dispatch>; -}; - -export type Settings = { - temp: number; - topP: number; - topK: number | undefined; - maxTokens: number | undefined; - numCtx: number | undefined; - stop: string[] | undefined; - repeatPenalty: number; - seed: number | undefined; - stream: boolean; - keepAlive: string | undefined; -}; - -function SettingsPanel({ settings, setSettings }: PanelProps) { - const set = - (key: K) => - (val: Settings[K]) => - setSettings((prev) => ({ ...prev, [key]: val })); - - const sections = [ - { - title: 'Sampling', - fields: (s: any, set: any) => ( - <> - - - - - ), - }, - { - title: 'Generation', - fields: (s: any, set: any) => ( - <> - - - - set('stop')(val ? val.split(',').map((s) => s.trim()) : undefined) - } - placeholder="Comma separated" - /> - - ), - }, - { - title: 'Control', - fields: (s: any, set: any) => ( - <> - - - - ), - }, - { - title: 'System', - fields: (s: any, set: any) => ( - <> - - - - ), - }, - ]; + const data = await res.json(); + setResult(JSON.stringify(data, null, 2)); + } catch (err: any) { + setResult(err.message); + } finally { + setLoading(false); + } + } return ( -
- {sections.map((section) => ( -
-

- {section.title} -

+
+ - {section.fields(settings, set)} -
- ))} + {result && ( +
+          {result}
+        
+ )}
); -} - -export const SIDEBAR_PANELS = ({ - settings, - setSettings, -}: PanelProps): SidebarPanel[] => [ - { - id: 'settings', - label: 'Settings', - icon: ( - - - - ), - component: , - }, -]; - -import { useState } from 'react'; - -export default function DocPage() { - const [settings, setSettings] = useState({ - temp: 0.7, - topP: 0.9, - topK: 40, - maxTokens: 1000, - numCtx: 128000, - stop: [''], - repeatPenalty: 1.1, - seed: 0, - stream: true, - keepAlive: '5m', - }); - - return ( -
- -
- ); -} +} \ No newline at end of file