session start works

This commit is contained in:
aodulov
2025-10-10 12:48:06 +03:00
parent 556df015e8
commit 3c192b136c
51 changed files with 29002 additions and 46 deletions

View File

@@ -0,0 +1,51 @@
import { GoogleGenerativeAI, GenerativeModel } from '@google/generative-ai';
interface DesireSet {
wants: string[];
accepts: string[];
noGoes: string[];
}
export class LLMService {
private genAI: GoogleGenerativeAI;
private model: GenerativeModel;
constructor(apiKey: string) {
this.genAI = new GoogleGenerativeAI(apiKey);
this.model = this.genAI.getGenerativeModel({ model: "gemini-pro" });
}
async analyzeDesires(desireSets: DesireSet[]): Promise<Record<string, string>> {
const allDesires: string[] = [];
desireSets.forEach(set => {
allDesires.push(...set.wants, ...set.accepts, ...set.noGoes);
});
const uniqueDesires = Array.from(new Set(allDesires.filter(d => d.trim() !== '')));
if (uniqueDesires.length === 0) {
return {};
}
const prompt = `
You are an AI assistant that groups similar desires. Given a list of desires, identify semantically equivalent or very similar items and group them under a single, concise canonical name. Return the output as a JSON object where keys are the original desire strings and values are their canonical group names.
Example:
Input: ["go for a walk", "walking", "stroll in the park", "eat pizza", "pizza for dinner"]
Output: {"go for a walk": "Go for a walk", "walking": "Go for a walk", "stroll in the park": "Go for a walk", "eat pizza": "Eat pizza", "pizza for dinner": "Eat pizza"}
Here is the list of desires to group:
${JSON.stringify(uniqueDesires)}
`;
try {
const result = await this.model.generateContent(prompt);
const response = result.response;
const text = response.text();
return JSON.parse(text);
} catch (error) {
console.error("Error calling Gemini API:", error);
throw error;
}
}
}