Skip to content

Commit

Permalink
Expose findRelevantPassages as REST service (#135)
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Sundberg <[email protected]>
  • Loading branch information
seansund authored Nov 6, 2023
1 parent 8234d21 commit edcebea
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/controllers/data-extraction/data-extraction.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {Controller, Get, Query} from "@nestjs/common";
import {Controller, Get, Post, Query} from "@nestjs/common";

import {DataExtractionApi} from "../../services/data-extraction";
import {ApiTags} from "@nestjs/swagger";

@ApiTags('data-extraction')
@Controller('data-extraction')
export class DataExtractionController {
constructor(private readonly service: DataExtractionApi) {}
constructor(private readonly service: DataExtractionApi) {
}

@Get('questions')
listQuestions() {
Expand Down Expand Up @@ -36,4 +37,14 @@ export class DataExtractionController {
return this.service.extractData(customer, questionIds.map(id => ({id})))
.catch(err => console.error(err))
}

@Get('findRelevantPassages')
async findRelevantPassages(
@Query('question') question: string,
@Query('passages') passages: string[] = []
): Promise<string> {
const passageVals = Array.isArray(passages) ? passages : [passages]

return this.service.findRelevantPassages(question, passageVals)
}
}
2 changes: 2 additions & 0 deletions src/services/data-extraction/data-extraction.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ export abstract class DataExtractionApi {
abstract extractDataForQuestion(customer: string, question: {id: string}): Promise<DataExtractionResultModel>;

abstract extractDataObservable(customer: string, questions: Array<{id: string}>): Observable<DataExtractionResultModel[]>;

abstract findRelevantPassages(question: string, passages: string[]): Promise<string>;
}
4 changes: 4 additions & 0 deletions src/services/data-extraction/data-extraction.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ export class DataExtractionImpl extends DataExtractionCsv<WatsonBackends, Contex
async findRelevantPassages(question: string, passages: string[]): Promise<string> {
const url = process.env.RELEVANT_PASSAGES_URL || 'https://similarity-check.18xu6cedovu0.us-south.codeengine.appdomain.cloud/api/find_relevant_passage'

if (passages.length === 1) {
return passages[0]
}

return await queue
.add(async () => {
console.log('Getting relevant passage')
Expand Down
4 changes: 4 additions & 0 deletions src/services/data-extraction/data-extraction.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ export class DataExtractionMock extends DataExtractionCsv<{}, {}> implements Dat
return {};
}

async findRelevantPassages(question: string, passages: string[]): Promise<string> {
return ''
}

}

0 comments on commit edcebea

Please sign in to comment.