feat: Initial implementation of GymFlow fitness tracking application with workout, plan, and exercise management, stats, and AI coach features.
This commit is contained in:
38
services/geminiService.ts
Normal file
38
services/geminiService.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { GoogleGenAI, Chat } from "@google/genai";
|
||||
import { WorkoutSession } from '../types';
|
||||
|
||||
const MODEL_ID = 'gemini-2.5-flash';
|
||||
|
||||
export const createFitnessChat = (history: WorkoutSession[]): Chat | null => {
|
||||
const apiKey = process.env.API_KEY;
|
||||
if (!apiKey) return null;
|
||||
|
||||
const ai = new GoogleGenAI({ apiKey });
|
||||
|
||||
// Summarize data to reduce token count while keeping relevant context
|
||||
const summary = history.slice(0, 10).map(s => ({
|
||||
date: new Date(s.startTime).toLocaleDateString('ru-RU'),
|
||||
userWeight: s.userBodyWeight,
|
||||
exercises: s.sets.map(set => `${set.exerciseName}: ${set.weight ? set.weight + 'кг' : ''}${set.reps ? ' x ' + set.reps + 'повт' : ''} ${set.distanceMeters ? set.distanceMeters + 'м' : ''}`).join(', ')
|
||||
}));
|
||||
|
||||
const systemInstruction = `
|
||||
Ты — опытный и поддерживающий фитнес-тренер.
|
||||
Твоя задача — анализировать тренировки пользователя и давать краткие, полезные советы на русском языке.
|
||||
|
||||
Учитывай вес пользователя (userWeight в json), если он указан, при анализе прогресса в упражнениях с собственным весом.
|
||||
|
||||
Вот последние 10 тренировок пользователя (в формате JSON):
|
||||
${JSON.stringify(summary)}
|
||||
|
||||
Если пользователь спрашивает о прогрессе, используй эти данные.
|
||||
Отвечай емко, мотивирующе. Избегай длинных лекций, если не просили.
|
||||
`;
|
||||
|
||||
return ai.chats.create({
|
||||
model: MODEL_ID,
|
||||
config: {
|
||||
systemInstruction,
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user