import { Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

import { ClientProxy } from '@nestjs/microservices';
import { firstValueFrom } from 'rxjs';

@Injectable()
export class RagService {
  constructor(@Inject('RAG') private client: ClientProxy) {}

  async getAnswerRag(transcript: string, chat_history?:string) {
    try {
      let response = await firstValueFrom(
        this.client.send('get-answer', { content: transcript, chat_history:chat_history })
      );
      // console.log('response', response);
      return response;
    } catch (error) {
      throw error;
    }
  }

  async chatSummrize(chat: string) {
    try {
      let response = await firstValueFrom(
        this.client.send('chat-summrize', { chat: chat })
      );
      // console.log('response', response);
      return response;
    } catch (error) {
      throw error;
    }
  }
  
}
