Backend is here. Default admin is created if needed.

This commit is contained in:
aodulov
2025-11-19 10:48:37 +02:00
parent 10819cc6f5
commit bb705c8a63
25 changed files with 3662 additions and 944 deletions

View File

@@ -1,14 +1,12 @@
import { GoogleGenAI, Chat } from "@google/genai";
import { WorkoutSession } from '../types';
import { api } from './api';
const MODEL_ID = 'gemini-2.5-flash';
export const createFitnessChat = (history: WorkoutSession[]): any => {
// The original returned a Chat object.
// Now we need to return something that behaves like it or refactor the UI.
// The UI likely calls `chat.sendMessage(msg)`.
// So we return an object with `sendMessage`.
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'),
@@ -29,10 +27,17 @@ export const createFitnessChat = (history: WorkoutSession[]): Chat | null => {
Отвечай емко, мотивирующе. Избегай длинных лекций, если не просили.
`;
return ai.chats.create({
model: MODEL_ID,
config: {
systemInstruction,
},
});
return {
sendMessage: async (userMessage: string) => {
const res = await api.post('/ai/chat', {
systemInstruction,
userMessage
});
return {
response: {
text: () => res.response
}
};
}
};
};