MCPcopy Create free account
hub / github.com/bhaskatripathi/Text2Diagram / APIKeyInput

Function APIKeyInput

components/APIKeyInput.tsx:19–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17import type { OpenAIModel } from "@/types/type";
18
19export const APIKeyInput = () => {
20 const [apiKey, setApiKey] = useAtom(apiKeyAtom);
21 const [model, setModel] = useAtom(modelAtom);
22
23 const handleChange = (e: ChangeEvent<HTMLInputElement>) =>
24 setApiKey(e.target.value);
25
26 const handleModelChange = (value: OpenAIModel) => {
27 setModel(value);
28 };
29
30 const handleSave = () => {
31 localStorage.setItem("apiKey", apiKey);
32 localStorage.setItem("model", model);
33 };
34
35 return (
36 <div className="grid w-full max-w-sm items-center gap-1.5">
37 <div>
38 <Label htmlFor="api-key">OpenAI API key</Label>
39 <Input
40 type="password"
41 id="api-key"
42 placeholder="OpenAI API Key"
43 value={apiKey}
44 onChange={handleChange}
45 className="mt-2"
46 />
47 </div>
48
49 <div className="mb-2">
50 <Label htmlFor="model">OpenAI model</Label>
51 <Select value={model} onValueChange={handleModelChange}>
52 <SelectTrigger className="w-[180px] mt-2">
53 <SelectValue id="model" placeholder="Select model" />
54 </SelectTrigger>
55 <SelectContent>
56 <SelectItem value="gpt-4">gpt-4o</SelectItem>
57 <SelectItem value="gpt-4">gpt-4o-mini</SelectItem>
58 <SelectItem value="gpt-4">gpt-4</SelectItem>
59 <SelectItem value="gpt-3.5-turbo">gpt-3.5-turbo</SelectItem>
60 </SelectContent>
61 </Select>
62 </div>
63 <Button onClick={handleSave}>Save</Button>
64 </div>
65 );
66};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected