Skip to content

Commit 78c94c3

Browse files
authored
Merge pull request #24 from AgrI-Mitra/fix/repeated-responses
2 parents 0526f1c + 6eff6d9 commit 78c94c3

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/app.controller.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,15 @@ export class AppController {
194194
configid
195195
)
196196

197+
console.log("fetched conversation: ", conversation)
197198
//handle text and audio
198199
if(promptDto.text){
199200
type = "Text"
200201
let detectLanguageStartTime = Date.now();
201202
if(/^\d+$/.test(userInput)){
202203
prompt.inputLanguage = Language.en
203204
} else {
205+
console.log("IN ELSE....")
204206
try {
205207
let response = await this.aiToolsService.detectLanguage(userInput)
206208
prompt.inputLanguage = response["language"] as Language
@@ -239,12 +241,14 @@ export class AppController {
239241
tags: ['bot','detect_language','error']
240242
})
241243
}
244+
console.log("LANGUAGE DETECTED...")
242245
//@ts-ignore
243246
if(prompt.inputLanguage == 'unk'){
244247
prompt.inputLanguage = prompt.input.inputLanguage as Language
245248
}
246249
// verboseLogger("Detected Language =", prompt.inputLanguage)
247250
}
251+
console.log("TELEMETRYYYYY")
248252
await this.telemetryService.capture({
249253
eventName: "Detect language",
250254
eventType: "DETECT_LANGUAGE",
@@ -375,7 +379,7 @@ export class AppController {
375379
}
376380

377381
conversation.inputType = type;
378-
382+
console.log("CP 1...")
379383
//get flow
380384
let botFlowMachine;
381385
switch(configid){
@@ -411,6 +415,7 @@ export class AppController {
411415
}
412416
})
413417
}else {
418+
console.log("creating a new message in Message table...")
414419
await this.prismaService.message.create({
415420
data:{
416421
text: type=="Text"?promptDto.text:null,
@@ -505,6 +510,7 @@ export class AppController {
505510
return res
506511
} else {
507512
//translate to english
513+
console.log("Translating to English...")
508514
let translateStartTime = Date.now();
509515
if(userInput == 'resend OTP'){
510516
this.monitoringService.incrementResentOTPCount()
@@ -1101,7 +1107,7 @@ export class AppController {
11011107
result['audio'] = {text: "",error: error.message}
11021108
}
11031109
}
1104-
1110+
console.log("Saving conversation..")
11051111
conversation = await this.conversationService.saveConversation(
11061112
sessionId,
11071113
userId,

src/modules/aiTools/ai-tools.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class AiToolsService {
1919
@Inject(CACHE_MANAGER) private readonly cacheManager: Cache,
2020
) {}
2121
async detectLanguage(text: string): Promise<any> {
22+
console.log("DETECTING LANGUAGE....")
2223
var myHeaders = new Headers();
2324
myHeaders.append("Content-Type", "application/json");
2425

src/modules/conversation/conversation.service.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ export class ConversationService {
5858
}
5959
})
6060
}
61+
62+
if(conversation.state == "Done") {
63+
conversation = await this.prisma.conversation.update({
64+
where: {
65+
id: sessionId
66+
},
67+
data: {
68+
context: defaultContext,
69+
state: "onGoing"
70+
}
71+
})
72+
73+
conversation = await this.prisma.conversation.findFirst({
74+
where: {
75+
id: sessionId
76+
}
77+
})
78+
}
6179

6280
return conversation?.context ? {...conversation.context, id:conversation.id} : null;
6381
}

src/xstate/prompt/prompt.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class PromptServices {
3333
}
3434

3535
async questionClassifier (context) {
36+
console.log("IN questionclassifier")
3637
try{
3738
let response: any = await this.aiToolsService.getResponseViaWadhwani(context.sessionId, context.userId, context.query)
3839
if (response.error) throw new Error(`${response.error}, please try again.`)
@@ -68,6 +69,7 @@ export class PromptServices {
6869
}
6970

7071
async validateAadhaarNumber (context, event) {
72+
console.log("validate aadhar")
7173
try{
7274
const userIdentifier = `${context.userAadhaarNumber}${context.lastAadhaarDigits}`;
7375
let res;
@@ -101,6 +103,7 @@ export class PromptServices {
101103
}
102104

103105
async validateOTP (context, event) {
106+
console.log("Validate OTP")
104107
const userIdentifier = `${context.userAadhaarNumber}${context.lastAadhaarDigits}`;
105108
const otp = context.otp;
106109
let res;
@@ -124,6 +127,7 @@ export class PromptServices {
124127
}
125128

126129
async fetchUserData (context, event) {
130+
console.log("Fetch user data");
127131
const userIdentifier = `${context.userAadhaarNumber}${context.lastAadhaarDigits}`;
128132
let res;
129133
let type='Mobile'
@@ -210,6 +214,7 @@ export class PromptServices {
210214
}
211215

212216
async wadhwaniClassifier (context) {
217+
console.log("Wadhwani Classifierrr")
213218
try{
214219
let response: any = await this.aiToolsService.getResponseViaWadhwani(context.sessionId, context.userId,context.query)
215220
if (response.error) throw new Error(`${response.error}, please try again.`)

0 commit comments

Comments
 (0)