Skip to content

Commit

Permalink
Merge pull request #24 from AgrI-Mitra/fix/repeated-responses
Browse files Browse the repository at this point in the history
  • Loading branch information
kh4l1d64 authored Feb 29, 2024
2 parents 0526f1c + 6eff6d9 commit 78c94c3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,15 @@ export class AppController {
configid
)

console.log("fetched conversation: ", conversation)
//handle text and audio
if(promptDto.text){
type = "Text"
let detectLanguageStartTime = Date.now();
if(/^\d+$/.test(userInput)){
prompt.inputLanguage = Language.en
} else {
console.log("IN ELSE....")
try {
let response = await this.aiToolsService.detectLanguage(userInput)
prompt.inputLanguage = response["language"] as Language
Expand Down Expand Up @@ -239,12 +241,14 @@ export class AppController {
tags: ['bot','detect_language','error']
})
}
console.log("LANGUAGE DETECTED...")
//@ts-ignore
if(prompt.inputLanguage == 'unk'){
prompt.inputLanguage = prompt.input.inputLanguage as Language
}
// verboseLogger("Detected Language =", prompt.inputLanguage)
}
console.log("TELEMETRYYYYY")
await this.telemetryService.capture({
eventName: "Detect language",
eventType: "DETECT_LANGUAGE",
Expand Down Expand Up @@ -375,7 +379,7 @@ export class AppController {
}

conversation.inputType = type;

console.log("CP 1...")
//get flow
let botFlowMachine;
switch(configid){
Expand Down Expand Up @@ -411,6 +415,7 @@ export class AppController {
}
})
}else {
console.log("creating a new message in Message table...")
await this.prismaService.message.create({
data:{
text: type=="Text"?promptDto.text:null,
Expand Down Expand Up @@ -505,6 +510,7 @@ export class AppController {
return res
} else {
//translate to english
console.log("Translating to English...")
let translateStartTime = Date.now();
if(userInput == 'resend OTP'){
this.monitoringService.incrementResentOTPCount()
Expand Down Expand Up @@ -1101,7 +1107,7 @@ export class AppController {
result['audio'] = {text: "",error: error.message}
}
}

console.log("Saving conversation..")
conversation = await this.conversationService.saveConversation(
sessionId,
userId,
Expand Down
1 change: 1 addition & 0 deletions src/modules/aiTools/ai-tools.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class AiToolsService {
@Inject(CACHE_MANAGER) private readonly cacheManager: Cache,
) {}
async detectLanguage(text: string): Promise<any> {
console.log("DETECTING LANGUAGE....")
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");

Expand Down
18 changes: 18 additions & 0 deletions src/modules/conversation/conversation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ export class ConversationService {
}
})
}

if(conversation.state == "Done") {
conversation = await this.prisma.conversation.update({
where: {
id: sessionId
},
data: {
context: defaultContext,
state: "onGoing"
}
})

conversation = await this.prisma.conversation.findFirst({
where: {
id: sessionId
}
})
}

return conversation?.context ? {...conversation.context, id:conversation.id} : null;
}
Expand Down
5 changes: 5 additions & 0 deletions src/xstate/prompt/prompt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class PromptServices {
}

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

async validateAadhaarNumber (context, event) {
console.log("validate aadhar")
try{
const userIdentifier = `${context.userAadhaarNumber}${context.lastAadhaarDigits}`;
let res;
Expand Down Expand Up @@ -101,6 +103,7 @@ export class PromptServices {
}

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

async fetchUserData (context, event) {
console.log("Fetch user data");
const userIdentifier = `${context.userAadhaarNumber}${context.lastAadhaarDigits}`;
let res;
let type='Mobile'
Expand Down Expand Up @@ -210,6 +214,7 @@ export class PromptServices {
}

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

0 comments on commit 78c94c3

Please sign in to comment.