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

Add throttling for cosine passage call #118

Merged
merged 1 commit into from
Oct 26, 2023
Merged
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
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