This commit is contained in:
Rainyy21
2025-11-09 01:43:33 -05:00
19 changed files with 1460 additions and 525 deletions
+48 -49
View File
@@ -17,8 +17,8 @@ export default function ChatInput({ onSend, onOpenSettings }: ChatInputProps) {
const handleSend = () => {
if (message.trim()) {
onSend(message.trim());
setMessage("");
onSend(message.trim());
setMessage("");
}
};
@@ -34,62 +34,61 @@ export default function ChatInput({ onSend, onOpenSettings }: ChatInputProps) {
return (
<div className="fixed bottom-0 left-0 right-0 flex flex-col max-w-4xl mx-auto w-full">
<div
className={`
<div
className={`
flex items-center border border-black/10 p-3 mx-4 rounded-t-3xl
bg-white
shadow-md transition-all duration-200
`}
>
<div className="relative flex-1 mx-2">
<textarea
className="w-full px-3 py-2 bg-transparent border-none focus:outline-none"
placeholder="Type a message..."
value={message}
onChange={handleChange}
onKeyDown={handleKeyPress}
/>
{message && (
<button
className="absolute right-0 top-1/2 transform -translate-y-1/2 p-1 text-gray-400 hover:text-gray-600 "
onClick={handleClear}
aria-label="Clear input"
>
<X size={16} />
</button>
)}
</div>
<div className="flex items-center">
<button
className="p-2 text-gray-500 hover:text-purple-600 rounded-full hover:bg-gray-100 0 mr-1"
onClick={onOpenSettings}
aria-label="Open settings"
>
<Settings size={20} />
</button>
<button
className={`
<div className="relative flex-1 mx-2">
<textarea
className="w-full px-3 py-2 bg-transparent border-none focus:outline-none"
placeholder="Type a message..."
value={message}
onChange={handleChange}
onKeyDown={handleKeyPress}
/>
{message && (
<button
className="absolute right-0 top-1/2 transform -translate-y-1/2 p-1 text-gray-400 hover:text-gray-600 "
onClick={handleClear}
aria-label="Clear input"
>
<X size={16} />
</button>
)}
</div>
<div className="flex items-center">
<button
className="p-2 text-gray-500 hover:text-purple-600 rounded-full hover:bg-gray-100 0 mr-1"
onClick={onOpenSettings}
aria-label="Open settings"
>
<Settings size={20} />
</button>
<button
className={`
p-2 rounded-full transition-all
${
message.trim()
? "bg-purple-600 text-white hover:bg-purple-700"
: "bg-gray-200 text-gray-400 cursor-not-allowed"
}
${message.trim()
? "bg-purple-600 text-white hover:bg-purple-700"
: "bg-gray-200 text-gray-400 cursor-not-allowed"
}
`}
onClick={handleSend}
disabled={!message.trim()}
aria-label="Send message"
>
<Send size={20} />
</button>
</div>
onClick={handleSend}
disabled={!message.trim()}
aria-label="Send message"
>
<Send size={20} />
</button>
</div>
</div>
</div>
);
+33 -16
View File
@@ -1,8 +1,9 @@
"use client";
import { useRef, useEffect } from "react";
import { ChatHistory } from "@/app/exportType/types";
import {User, Bot} from "lucide-react"
import { User, Bot } from "lucide-react"
<<<<<<< HEAD
interface MessageWindowProps{
history :ChatHistory;
isLoading: boolean;
@@ -10,22 +11,30 @@ interface MessageWindowProps{
export default function MessageWindow({history, isLoading}:MessageWindowProps){
const messageEndRef = useRef<HTMLDivVElement>(null);
=======
interface MessageWindowProps {
history: ChatHistory
}
useEffect(() =>{
messageEndRef.current?.scrollIntoView({behavior:"smooth"});
export default function MessageWindow({ history }: MessageWindowProps) {
const messageEndRef = useRef<HTMLDivElement>(null);
>>>>>>> ce9e6f34ed31b7bff736cc9ba9a1b8dcdec85f3a
useEffect(() => {
messageEndRef.current?.scrollIntoView({ behavior: "smooth" });
}, [history]);
return(
return (
<div className="flex-1 p-3 overflow-y-auto">
<div className="max-w-3xl mx-auto">
{history.map((msg,index)=>{
{history.map((msg, index) => {
const isUser = msg.role === "user"
return (
<div
key={index}
className={`flex ${isUser ? "justify-end" : "justify-start"}`}>
{!isUser &&(
<div
key={index}
className={`flex ${isUser ? "justify-end" : "justify-start"}`}>
{!isUser && (
<div className="mr-2">
<div className="flex items-center justify-center w-8 h-8 rounded-full bg-gray">
<Bot size={15} className="text-gray-700">
@@ -42,14 +51,15 @@ export default function MessageWindow({history, isLoading}:MessageWindowProps){
<span key={idx}>{part.text}</span>))}
</div>
</div>
{isUser && (
<div className="ml-2">
<div className="flex items-center justify-center w-8 h-8 rounded-full bg-purple-500">
<User size={16} className="text-white" />
{isUser && (
<div className="ml-2">
<div className="flex items-center justify-center w-8 h-8 rounded-full bg-purple-500">
<User size={16} className="text-white" />
</div>
</div>
</div>
)}
)}
</div>
<<<<<<< HEAD
);
})}
@@ -69,7 +79,14 @@ export default function MessageWindow({history, isLoading}:MessageWindowProps){
)}
{/* Invisible element to help scroll to bottom */}
<div ref={messageEndRef} />
=======
);
})}
{/* Invisible element to help scroll to bottom */}
<div ref={messageEndRef} />
</div>
>>>>>>> ce9e6f34ed31b7bff736cc9ba9a1b8dcdec85f3a
</div>
</div>
);
}
+33 -15
View File
@@ -1,15 +1,16 @@
import { GoogleGenerativeAI } from "@google/generative-ai";
import { ChatHistory, GenerateConfig,ChatSetting } from "../exportType/types";
import { ChatHistory, GenerateConfig, ChatSetting } from "../exportType/types";
const apiKey = process.env.GEMINI_API_KEY;
if(!apiKey){
if (!apiKey) {
throw new Error("api key not found");
}
const genAI = new GoogleGenerativeAI(apiKey);
export async function chatToGemini(
<<<<<<< HEAD
userMessage:string ,
history:ChatHistory,
settings:ChatSetting
@@ -25,18 +26,35 @@ export async function chatToGemini(
responseMimeType: "text/plain",
maxOutputTokens: 1900, // Increased to allow for longer responses
}
=======
userMessage: string,
history: ChatHistory,
settings: ChatSetting
): Promise<string> {
const model = genAI.getGenerativeModel({
model: settings.model || "gemini-2.5-flash",
systemInstruction: settings.sysTemInstructions || "you are going to create a project idea, explain it in summery first before going to detail",
});
>>>>>>> ce9e6f34ed31b7bff736cc9ba9a1b8dcdec85f3a
const chatSession = model.startChat({
generationConfig,
history
})
const generationConfig: GenerateConfig = {
temperature: settings.temperature || 1,
topP: 0.9,
responseMimeType: "text/plain",
maxOutputTokens: 1900, // Increased to allow for longer responses
}
try {
const result = await chatSession.sendMessage(userMessage);
return result.response.text();
}
catch(error){
console.error(error)
throw error
}
}
const chatSession = model.startChat({
generationConfig,
history
})
try {
const result = await chatSession.sendMessage(userMessage);
return result.response.text();
}
catch (error) {
console.error(error)
throw error
}
}