Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update throttling #123

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/resolvers/data-extraction/data-extraction.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ export class DataExtractionResultResolver {
@Args('questions', {type: () => [DataExtractionQuestionIdInput]}) questions: DataExtractionQuestionIdInput[],
): Promise<DataExtractionResultModel[]> {

return this.service.extractData(customer, questions);
console.log('Extracting data for questions', JSON.stringify({customer, questions}))

const result = await this.service.extractData(customer, questions);

console.log('Got result', {result})

return result;
}

@Query(() => DataExtractionResult)
Expand All @@ -27,7 +33,13 @@ export class DataExtractionResultResolver {
@Args('question', {type: () => DataExtractionQuestionIdInput}) question: DataExtractionQuestionIdInput,
): Promise<DataExtractionResultModel> {

return this.service.extractDataForQuestion(customer, question);
console.log('Extracting data for question', JSON.stringify({customer, question}))

const result = await this.service.extractDataForQuestion(customer, question);

console.log('Got result', {result})

return result
}

@Subscription(() => [DataExtractionResult], {
Expand Down
29 changes: 19 additions & 10 deletions src/services/data-extraction/data-extraction.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {DataExtractionResultModel} from "../../models";
import {first, GenAiModel, GenerativeResponse} from "../../utils";
import PQueue from "../../utils/p-queue";

const queue = new PQueue({concurrency: 1});
const queue = new PQueue({concurrency: 2});

export interface DataExtractionBackendConfig {
identityUrl: string;
Expand Down Expand Up @@ -162,6 +162,8 @@ export class DataExtractionImpl extends DataExtractionCsv<WatsonBackends, Contex
? this.handleDiscoveryPassages(response.result)
: this.handleDiscoveryResult(response.result, customer);

console.log('Finding relevant passages')

const text: string = await this.findRelevantPassages(naturalLanguageQuery, passages)

console.log('1. Text extracted from Discovery:', {naturalLanguageQuery, text})
Expand Down Expand Up @@ -198,15 +200,22 @@ export class DataExtractionImpl extends DataExtractionCsv<WatsonBackends, Contex
const url = process.env.RELEVANT_PASSAGES_URL || 'https://similarity-check.18xu6cedovu0.us-south.codeengine.appdomain.cloud/api/find_relevant_passage'

return await queue
.add(() => axios
.post<{relevant_passage: string}>(url, {question, passages})
.then(response => response.data.relevant_passage)
.catch(err => {
console.error('Error getting relevant passages: ', {err})

return passages.join('\n')
})
) as string
.add(async () => {
console.log('Getting relevant passage')

const relevantPassage = await axios
.post<{relevant_passage: string}>(url, {question, passages})
.then(response => response.data.relevant_passage)
.catch(err => {
console.error('Error getting relevant passages: ', {err})

return passages.join('\n')
})

console.log('Found relevant passage: ', {relevantPassage})

return relevantPassage
}) as string
}

async generateResponse(customer: string, config: DataExtractionConfig, text: string, backends: WatsonBackends): Promise<{watsonxResponse: string, prompt: string}> {
Expand Down
9 changes: 8 additions & 1 deletion src/utils/discovery-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ export const createDiscoveryV2 = async (options: UserOptions): Promise<Discovery
discovery.query = (...args) => {
console.log('Queued discovery query')

return queue.add(() => originalQuery(...args))
return queue.add(async () => {
console.log('Calling query', args)
const result = await originalQuery(...args)

console.log('Query result', {result})

return result;
})
}

return discovery;
Expand Down