Skip to content

Commit

Permalink
Add throttling for cosine passage call (#118)
Browse files Browse the repository at this point in the history
- Limit to 4 concurrent calls

Signed-off-by: Sean Sundberg <[email protected]>
  • Loading branch information
seansund authored Oct 26, 2023
1 parent 2d216af commit 12f0cf7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/services/data-extraction/data-extraction.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as process from "process";
import {IamAuthenticator, IamTokenManager} from "ibm-cloud-sdk-core";
import DiscoveryV2 = require("ibm-watson/discovery/v2");
const striptags = require("striptags");
import axios from "axios";

import {DataExtractionApi} from "./data-extraction.api";

Expand All @@ -10,7 +11,10 @@ import {DataExtractionConfig, DataExtractionCsv} from "./data-extraction.csv";
import {kycCaseSummaryApi, KycCaseSummaryApi} from "../kyc-case-summary";
import {DataExtractionResultModel} from "../../models";
import {first, GenAiModel, GenerativeResponse} from "../../utils";
import axios from "axios";
import pQueue from '../../utils/p-queue'
import PQueue from "../../utils/p-queue";

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

export interface DataExtractionBackendConfig {
identityUrl: string;
Expand Down Expand Up @@ -194,9 +198,11 @@ 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'

return axios
.post<{relevant_passage: string}>(url, {question, passages})
.then(response => response.data.relevant_passage)
return await queue
.add(() => axios
.post<{relevant_passage: string}>(url, {question, passages})
.then(response => response.data.relevant_passage)
) as string
}

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

0 comments on commit 12f0cf7

Please sign in to comment.