Skip to content

Commit

Permalink
Include LLM prompt in data extraction result (#51)
Browse files Browse the repository at this point in the history
closes #49

Signed-off-by: Sean Sundberg <[email protected]>
  • Loading branch information
seansund authored Sep 24, 2023
1 parent 0553ed5 commit 2900e84
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type DataExtractionResult {
expectedResponse: String!
id: ID!
inScope: Boolean!
prompt: String!
question: String!
watsonxResponse: String!
}
Expand Down
2 changes: 2 additions & 0 deletions src/graphql-types/data-extraction.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ export class DataExtractionResult implements DataExtractionResultModel {
expectedResponse: string;
@Field()
watsonxResponse: string;
@Field()
prompt: string;
}

1 change: 1 addition & 0 deletions src/models/data-extraction.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface DataExtractionQuestionModel {
}

export interface DataExtractionResultModel extends DataExtractionQuestionModel {
prompt: string;
expectedResponse: string;
watsonxResponse: string;
}
7 changes: 4 additions & 3 deletions src/services/data-extraction/data-extraction.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ export class DataExtractionImpl extends DataExtractionCsv<WatsonBackends> implem

const text = await this.queryDiscovery(customer, config, backends);

const watsonxResponse = await this.generateResponse(customer, config, text, backends);
const {watsonxResponse, prompt} = await this.generateResponse(customer, config, text, backends);

return {
id: config.id,
question: config.question,
inScope: config.inScope,
expectedResponse: config.expectedResponse,
watsonxResponse,
prompt,
}
}

Expand Down Expand Up @@ -140,7 +141,7 @@ export class DataExtractionImpl extends DataExtractionCsv<WatsonBackends> implem
.join(' ')
}

async generateResponse(customer: string, config: DataExtractionConfig, text: string, backends: WatsonBackends): Promise<string> {
async generateResponse(customer: string, config: DataExtractionConfig, text: string, backends: WatsonBackends): Promise<{watsonxResponse: string, prompt: string}> {

const prompt = (config.prompt || `From below text find answer for ${config.question} ${customer}`).replace('#', customer);
// const prompt = (`From below text find answer for ${config.question} ${customer}`).replace('#', customer);
Expand All @@ -160,7 +161,7 @@ export class DataExtractionImpl extends DataExtractionCsv<WatsonBackends> implem

console.log('2. Text generated from watsonx.ai:', {prompt, generatedText: result.generatedText, input})

return result.generatedText;
return {watsonxResponse: result.generatedText, prompt: input};
}

async getBackends(): Promise<WatsonBackends> {
Expand Down

0 comments on commit 2900e84

Please sign in to comment.