This commit is contained in:
Ivan Rudik
2025-11-09 10:02:56 +00:00
12 changed files with 204 additions and 249 deletions
+20 -6
View File
@@ -50,8 +50,8 @@ export default function MessageWindow({ history, isLoading }: MessageWindowProps
</div>
)}
</div>
);
})}
);
})}
{isLoading && (
<div className="flex justify-start mb-4">
<div className="mr-2">
@@ -67,10 +67,24 @@ export default function MessageWindow({ history, isLoading }: MessageWindowProps
</div>
</div>
)}
{/* Invisible element to help scroll to bottom */}
<div ref={messageEndRef} />
</div>
{isLoading && (
<div className="flex justify-start">
<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" />
</div>
</div>
<div className="px-4 py-2 shadow-sm rounded-lg bg-white text-gray-800 rounded-bl-none max-w-xs sm:max-w-md">
<div className="whitespace-pre-wrap break-words">
<span>Loading...</span>
</div>
</div>
</div>
)}
{/* Invisible element to help scroll to bottom */}
<div ref={messageEndRef} />
</div>
</div>
);
}
+21 -17
View File
@@ -10,21 +10,21 @@ if (!apiKey) {
const genAI = new GoogleGenerativeAI(apiKey);
export async function chatToGemini(
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",
});
const generationConfig: GenerateConfig = {
temperature: settings.temperature || 1,
topP: 0.9,
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",
});
const generationConfig:GenerateConfig = {
temperature : settings.temperature || 1,
topP : 0.9,
responseMimeType: "text/plain",
maxOutputTokens: 1900, // Increased to allow for longer responses
}
const chatSession = model.startChat({
generationConfig,
@@ -35,8 +35,12 @@ export async function chatToGemini(
const result = await chatSession.sendMessage(userMessage);
return result.response.text();
}
catch (error) {
console.error("Gemini API Error:", error);
catch (error: unknown) {
if (error instanceof Error) {
console.error("Error in chatToGemini:", error.name, error.message, error);
} else {
console.error("Unknown error in chatToGemini:", error);
}
throw error;
}
}