Skip to content

Commit

Permalink
added cache_threshold flagsmith variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Amruth-Vamshi committed Nov 9, 2023
1 parent 049ddec commit 6e122b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
15 changes: 15 additions & 0 deletions src/modules/prompt-history/prompt-history.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Body, Controller, Post, Get, HttpException, HttpStatus, Param, Delete, NotFoundException } from "@nestjs/common";
import { PromptHistoryService } from "./prompt-history.service";
import { document as Document, Prisma } from "@prisma/client";
import { SearchPromptHistoryDto } from "./prompt.dto";

@Controller("history")
export class PromptHistoryController {
constructor(private readonly promptHistoryService: PromptHistoryService) {}
@Post("/searchSimilar")
async findByCriteria(
@Body() searchQueryDto: SearchPromptHistoryDto
): Promise<Document[]> {
return this.promptHistoryService.findByCriteria(searchQueryDto);
}
}
5 changes: 0 additions & 5 deletions src/modules/prompt-history/prompt.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ export class SearchPromptHistoryDto {
@IsDefined({ message: "Query needs to be defined to search documents" })
query: string;

@IsDefined({
message: "Unique Identifier for PDF",
})
pdfIds: Array<string>;

@IsDefined({ message: "Similarity Threashold needs to be defined" })
similarityThreshold: number;

Expand Down
16 changes: 8 additions & 8 deletions src/xstate/prompt/prompt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ export const promptServices = {
},

findSimilarQuestion: async (context) => {
let pdfIds = context.prompt.input.pdfId ?
[context.prompt.input.pdfId] :
context.prompt.input.pdfIds && context.prompt.input.pdfIds.length ?
context.prompt.input.pdfIds :
JSON.parse(configService.get('DEFAULT_PDFS'))
const flags = await flagsmith.getIdentityFlags(context.prompt.input.userId);

let similarityThreshold = flags.getFeatureValue('cache_threshold');
if(similarityThreshold) similarityThreshold = parseFloat(similarityThreshold)
else similarityThreshold = 0.95

const olderSimilarQuestion =
await promptHistoryService.findByCriteria({
query: context.prompt.neuralCoreference,
pdfIds,
similarityThreshold: 0.97,
query: context.prompt.input.body,
similarityThreshold,
matchCount: 1,
});
return olderSimilarQuestion
Expand Down

0 comments on commit 6e122b2

Please sign in to comment.