This commit is contained in:
Rainyy21
2025-11-09 01:43:33 -05:00
19 changed files with 1460 additions and 525 deletions
+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
}
}