I'll help you create a modern chat interface with those specifications. Let's break this down into components and build it step by step.
// types.ts
interface ChatConfig {
mode: 'text' | 'voice';
model: 'openai' | 'anthropic' | 'gemini';
apiKey: string;
}
interface Message {
id: string;
role: 'user' | 'assistant';
content: string;
timestamp: Date;
type: 'text' | 'voice';
}
// config/ai-config.ts
import { Configuration } from 'ai-sdk';
export const modelConfigs = {
openai: {
models: ['gpt-4', 'gpt-3.5-turbo'],
baseURL: 'https://api.openai.com/v1'
},
anthropic: {
models: ['claude-3-opus', 'claude-3-sonnet'],
baseURL: 'https://api.anthropic.com/v1'
},
gemini: {
models: ['gemini-pro'],
baseURL: 'https://generativelanguage.googleapis.com/v1'
}
};
// components/ChatInterface.tsx
import { useState, useEffect } from 'react';
import { Card, Button, Input } from '@/components/ui';
import { cn } from '@/lib/utils';
export const ChatInterface = () => {
const [mode, setMode] = useState<'text' | 'voice'>('text');
const [messages, setMessages] = useState<Message[]>([]);
return (
<div className="flex flex-col h-screen bg-background/80 backdrop-blur-xl">
<Card className="flex-1 m-4 p-6 border-0 bg-background/40
backdrop-blur-md rounded-xl shadow-glass">
<div className="flex gap-2 mb-4">
<Button
variant={mode === 'text' ? 'default' : 'ghost'}
onClick={() => setMode('text')}
className="rounded-full"
>
Text
</Button>
<Button
variant={mode === 'voice' ? 'default' : 'ghost'}
onClick={() => setMode('voice')}
className="rounded-full"
>
Voice
</Button>
</div>
<div className="flex-1 overflow-y-auto space-y-4 mb-4">
{messages.map((message) => (
<MessageBubble key={message.id} message={message} />
))}
</div>
<InputArea mode={mode} onSend={handleSend} />
</Card>
</div>
);
};
// components/MessageBubble.tsx
import { motion } from 'framer-motion';
export const MessageBubble = ({ message }: { message: Message }) => {
const isUser = message.role === 'user';
return (
<motion.div
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
className={cn(
"flex",
isUser ? "justify-end" : "justify-start"
)}
>
<div className={cn(
"max-w-[80%] rounded-2xl p-4",
isUser ? "bg-primary text-primary-foreground" :
"bg-muted/50 backdrop-blur-sm"
)}>
{message.content}
</div>
</motion.div>
);
};
// styles/globals.css
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--background: 224 71% 4%;
--foreground: 213 31% 91%;
--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 1.2%;
--glass: rgba(255, 255, 255, 0.05);
--glass-stroke: rgba(255, 255, 255, 0.1);
}
}
.shadow-glass {
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
border: 1px solid var(--glass-stroke);
}
Here's what this implementation provides:
- A modern glassmorphic UI with liquid glass effects
- Dark mode by default with accessibility considerations
- Support for both text and voice modes
- Integration with multiple AI providers
- Responsive and animated message bubbles
- Type-safe implementation using TypeScript
To complete the implementation, you'll need to:
- Add voice recording functionality using the Web Audio API
- Implement the AI provider connections using the AI SDK
- Add loading states and error handling
- Create settings panel for API keys
- Add message streaming support
Would you like me to elaborate on any of these aspects or show the implementation of additional components?