diff --git a/server/routers/kfu-m-24-1/sber_mobile/cameras.js b/server/routers/kfu-m-24-1/sber_mobile/cameras.js index a1a1e8e..1425b9f 100644 --- a/server/routers/kfu-m-24-1/sber_mobile/cameras.js +++ b/server/routers/kfu-m-24-1/sber_mobile/cameras.js @@ -11,10 +11,6 @@ router.get('/cameras', async (req, res) => { res.json(data); }); -router.get('/creds', async (req, res) => { - res.json({data: process.env.GIGA_AUTH}); -}); - // Получить все камеры по квартире (через building_id) router.get('/cameras/by-apartment', async (req, res) => { const supabase = getSupabaseClient(); diff --git a/server/routers/kfu-m-24-1/sber_mobile/get-constants.js b/server/routers/kfu-m-24-1/sber_mobile/get-constants.js index 0d7c355..47f34e8 100644 --- a/server/routers/kfu-m-24-1/sber_mobile/get-constants.js +++ b/server/routers/kfu-m-24-1/sber_mobile/get-constants.js @@ -67,7 +67,8 @@ const getRagSupabaseUrl = async () => { module.exports = { getSupabaseUrl, getSupabaseKey, - getSupabaseServiceKey + getSupabaseServiceKey, + getGigaAuth }; // IIFE для установки переменных окружения diff --git a/server/routers/kfu-m-24-1/sber_mobile/support-ai-agent/gigachat.ts b/server/routers/kfu-m-24-1/sber_mobile/support-ai-agent/gigachat.ts index e46c067..ab98ebb 100644 --- a/server/routers/kfu-m-24-1/sber_mobile/support-ai-agent/gigachat.ts +++ b/server/routers/kfu-m-24-1/sber_mobile/support-ai-agent/gigachat.ts @@ -1,18 +1,20 @@ import { Agent } from 'node:https'; import { GigaChat } from 'langchain-gigachat'; +import { getGigaAuth } from '../get-constants'; const httpsAgent = new Agent({ rejectUnauthorized: false, }); // Получаем GIGA_AUTH из переменной окружения (устанавливается в get-constants.js) -export const gigachat = new GigaChat({ - model: 'GigaChat-2', - temperature: 0.7, - scope: 'GIGACHAT_API_PERS', - streaming: false, - credentials: process.env.GIGA_AUTH, - httpsAgent -}); +export const gigachat = (GIGA_AUTH) => + new GigaChat({ + model: 'GigaChat-2', + temperature: 0.7, + scope: 'GIGACHAT_API_PERS', + streaming: false, + credentials: GIGA_AUTH, + httpsAgent + }); export default gigachat; \ No newline at end of file diff --git a/server/routers/kfu-m-24-1/sber_mobile/support-ai-agent/support-agent.ts b/server/routers/kfu-m-24-1/sber_mobile/support-ai-agent/support-agent.ts index 93816e6..e8c5c68 100644 --- a/server/routers/kfu-m-24-1/sber_mobile/support-ai-agent/support-agent.ts +++ b/server/routers/kfu-m-24-1/sber_mobile/support-ai-agent/support-agent.ts @@ -10,6 +10,7 @@ import { CreateTicketTool } from './create-ticket-tool'; export interface SupportAgentConfig { temperature?: number; threadId?: string; + GIGA_AUTH?: string; } export interface SupportResponse { @@ -34,7 +35,7 @@ export class SupportAgent { this.memorySaver = new MemorySaver(); this.isFirstMessage = true; - this.llm = gigachat; + this.llm = gigachat(config.GIGA_AUTH); if (config.temperature !== undefined) { this.llm.temperature = config.temperature; } diff --git a/server/routers/kfu-m-24-1/sber_mobile/supportApi.js b/server/routers/kfu-m-24-1/sber_mobile/supportApi.js index 1babe43..afb4ea8 100644 --- a/server/routers/kfu-m-24-1/sber_mobile/supportApi.js +++ b/server/routers/kfu-m-24-1/sber_mobile/supportApi.js @@ -1,5 +1,6 @@ const router = require('express').Router(); const { getSupabaseClient } = require('./supabaseClient'); +const { getGigaAuth } = require('./get-constants'); const { SupportAgent } = require('./support-ai-agent/support-agent'); // Хранилище агентов для разных пользователей @@ -8,11 +9,13 @@ const userAgents = new Map(); /** * Получить или создать агента для пользователя */ -function getUserAgent(userId) { +async function getUserAgent(userId) { if (!userAgents.has(userId)) { + const GIGA_AUTH = await getGigaAuth(); const config = { threadId: userId, - temperature: 0.7 + temperature: 0.7, + GIGA_AUTH }; userAgents.set(userId, new SupportAgent(config)); } @@ -74,7 +77,7 @@ router.post('/support', async (req, res) => { } // Получаем агента для пользователя - const agent = getUserAgent(user_id); + const agent = await getUserAgent(user_id); // Получаем ответ от AI-агента, передавая apartment_id const aiResponse = await agent.processMessage(message, apartment_id);