From fa837e71e01575ebfabd268577ef393323612eab Mon Sep 17 00:00:00 2001 From: samlhuillier Date: Wed, 13 Nov 2024 22:40:02 +0000 Subject: [PATCH] initial ai edit button --- src/components/Editor/AIEdit.tsx | 85 +++++++++++++++++++++++++ src/components/Editor/EditorManager.tsx | 3 +- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/components/Editor/AIEdit.tsx diff --git a/src/components/Editor/AIEdit.tsx b/src/components/Editor/AIEdit.tsx new file mode 100644 index 00000000..b55d2eb7 --- /dev/null +++ b/src/components/Editor/AIEdit.tsx @@ -0,0 +1,85 @@ +import React from 'react' +import { useCompletion } from 'ai/react' +import { ArrowUp, Sparkles, ShrinkIcon, ExpandIcon, Play } from 'lucide-react' +import { Button } from '@/components/ui/button' +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' + +interface AiEditMenuProps { + selectedText: string + onEdit: (newText: string) => void +} + +const AiEditMenu = ({ selectedText, onEdit }: AiEditMenuProps) => { + const { complete } = useCompletion({ + api: '/api/generate', + }) + + const handleAction = async (action: string) => { + const prompt = `${action} the following text: ${selectedText}` + const completion = await complete(prompt) + if (completion) { + onEdit(completion) + } + } + + return ( + + +
+ + Ask AI to edit or generate... +
+ +
+ +
+

Edit or review selection

+
+ + + + +
+
+
+

Use AI to do more

+ +
+
+
+ ) +} + +export default AiEditMenu diff --git a/src/components/Editor/EditorManager.tsx b/src/components/Editor/EditorManager.tsx index dc6f0a17..e296761f 100644 --- a/src/components/Editor/EditorManager.tsx +++ b/src/components/Editor/EditorManager.tsx @@ -5,6 +5,7 @@ import EditorContextMenu from './EditorContextMenu' import SearchBar from './Search/SearchBar' import { useFileContext } from '@/contexts/FileContext' import DocumentStats from './DocumentStats' +import AiEditMenu from './AIEdit' const EditorManager: React.FC = () => { const [showSearchBar, setShowSearchBar] = useState(false) @@ -58,7 +59,7 @@ const EditorManager: React.FC = () => { }} > {showAIPopup ? ( -
test hide
+ {}} /> ) : (