mirror of
https://github.com/PinkSheep27/SBU-Hackathon.git
synced 2026-10-11 00:40:25 -04:00
formatting
This commit is contained in:
+35
-35
@@ -1,42 +1,42 @@
|
||||
import { GoogleGenerativeAI } from "@google/generative-ai";
|
||||
import { ChatHistory, GenerateConfig,ChatSetting } from "../exportType/types";
|
||||
// import { GoogleGenerativeAI } from "@google/generative-ai";
|
||||
// import { ChatHistory, GenerateConfig,ChatSetting } from "../exportType/types";
|
||||
|
||||
const apiKey = process.env.GEMINI_API_KEY;
|
||||
// const apiKey = process.env.GEMINI_API_KEY;
|
||||
|
||||
if(!apiKey){
|
||||
throw new Error("api key not found");
|
||||
}
|
||||
// if(!apiKey){
|
||||
// throw new Error("api key not found");
|
||||
// }
|
||||
|
||||
const genAI = new GoogleGenerativeAI(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",
|
||||
});
|
||||
// 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
|
||||
}
|
||||
// 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,
|
||||
history
|
||||
})
|
||||
// const chatSession = model.startChat({
|
||||
// generationConfig,
|
||||
// history
|
||||
// })
|
||||
|
||||
try {
|
||||
const result = await chatSession.sendMessage(userMessage);
|
||||
return result.response.text();
|
||||
}
|
||||
catch(error){
|
||||
console.error(error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
// try {
|
||||
// const result = await chatSession.sendMessage(userMessage);
|
||||
// return result.response.text();
|
||||
// }
|
||||
// catch(error){
|
||||
// console.error(error)
|
||||
// throw error
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user