diff --git a/app/api/generate-image/route.ts b/app/api/generate-image/route.ts new file mode 100644 index 0000000..4ef5efd --- /dev/null +++ b/app/api/generate-image/route.ts @@ -0,0 +1,27 @@ +import { NextResponse } from 'next/server' +import OpenAI from 'openai' + +const openai = new OpenAI({ + apiKey: process.env.OPENAI_API_KEY, +}) + +export async function POST(req: Request) { + try { + const { prompt } = await req.json() + + const response = await openai.images.generate({ + model: "dall-e-3", + prompt: prompt, + n: 1, + size: "1024x1024", + }) + + return NextResponse.json({ url: response.data[0].url }) + } catch (error) { + console.error('Error generating image:', error) + return NextResponse.json( + { error: 'Failed to generate image' }, + { status: 500 } + ) + } +} diff --git a/components/chat/chat-interface.tsx b/components/chat/chat-interface.tsx index 857c2c0..a46e9ad 100644 --- a/components/chat/chat-interface.tsx +++ b/components/chat/chat-interface.tsx @@ -2,6 +2,7 @@ import { useState } from 'react' import { MessageList } from './message-list' +import { ImageGeneration } from './image-generation' import { Message, Conversation, TokenUsage } from '@/lib/chat' import { Button } from "@/components/ui/button" import { Textarea } from "@/components/ui/textarea" @@ -32,6 +33,7 @@ export function ChatInterface({ conversation, onNewMessage }: ChatInterfaceProps const [topP, setTopP] = useState(1.0) const [frequencyPenalty, setFrequencyPenalty] = useState(0) const [presencePenalty, setPresencePenalty] = useState(0) + const [isImageMode, setIsImageMode] = useState(false); const handleSubmit = async () => { if (!inputMessage.trim() || isLoading) return @@ -108,9 +110,13 @@ export function ChatInterface({ conversation, onNewMessage }: ChatInterfaceProps 💬 Chat - @@ -120,7 +126,9 @@ export function ChatInterface({ conversation, onNewMessage }: ChatInterfaceProps
{/* Top Bar */}
-

Chat

+

+ {isImageMode ? 'Image Generation' : 'Chat'} +

@@ -128,30 +136,33 @@ export function ChatInterface({ conversation, onNewMessage }: ChatInterfaceProps
- {/* Messages Area */} - - - - - {/* Input Area */} -
-
-