feature/worker #111

Merged
primakov merged 190 commits from feature/worker into master 2025-12-05 16:59:42 +03:00
4 changed files with 20 additions and 13 deletions
Showing only changes of commit a3ea53c2f0 - Show all commits

View File

@@ -67,7 +67,8 @@ const getRagSupabaseUrl = async () => {
module.exports = {
getSupabaseUrl,
getSupabaseKey,
getSupabaseServiceKey
getSupabaseServiceKey,
getGigaAuth
};
// IIFE для установки переменных окружения

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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);