@@ -25,6 +25,27 @@ function getBuildEnvironment() {
2525 return { } ;
2626}
2727
28+ async function importQnAFromUrl ( builder : any , url : string , subscriptionKey : string ) {
29+ url = url . trim ( ) ;
30+ let onlineQnAContent = '' ;
31+ if ( DOC_EXTENSIONS . some ( ( e ) => url . endsWith ( e ) ) ) {
32+ const index = url . lastIndexOf ( '.' ) ;
33+ const extension = url . substring ( index ) ;
34+ onlineQnAContent = await builder . importFileReference (
35+ `onlineFile${ extension } ` ,
36+ url ,
37+ subscriptionKey ,
38+ COGNITIVE_SERVICES_ENDPOINTS ,
39+ uuid ( )
40+ ) ;
41+ } else {
42+ onlineQnAContent = await builder . importUrlReference ( url , subscriptionKey , COGNITIVE_SERVICES_ENDPOINTS , uuid ( ) ) ;
43+ }
44+ return onlineQnAContent ;
45+ }
46+
47+ //https://azure.microsoft.com/en-us/pricing/details/cognitive-services/qna-maker/
48+ //limited to 3 transactions per second
2849export async function parseQnAContent ( urls : string [ ] ) {
2950 const builder = new qnaBuild . Builder ( ( message : string ) => debug ( message ) ) ;
3051
@@ -36,27 +57,20 @@ export async function parseQnAContent(urls: string[]) {
3657 throw new Error ( 'Missing subscription key for QnAMaker' ) ;
3758 }
3859
39- const contents = await Promise . all (
40- urls . map ( async ( url ) => {
41- url = url . trim ( ) ;
42- if ( DOC_EXTENSIONS . some ( ( e ) => url . endsWith ( e ) ) ) {
43- const index = url . lastIndexOf ( '.' ) ;
44- const extension = url . substring ( index ) ;
45- return await builder . importFileReference (
46- `onlineFile${ extension } ` ,
47- url ,
48- subscriptionKey ,
49- COGNITIVE_SERVICES_ENDPOINTS ,
50- uuid ( )
51- ) ;
52- } else {
53- return await builder . importUrlReference ( url , subscriptionKey , COGNITIVE_SERVICES_ENDPOINTS , uuid ( ) ) ;
54- }
55- } )
56- ) ;
57-
58- contents . forEach ( ( content ) => {
59- qnaContent += content ;
60- } ) ;
60+ const limitedNumInBatch = 3 ;
61+ let i = 0 ;
62+
63+ while ( i < urls . length ) {
64+ const batchUrls = urls . slice ( i , i + limitedNumInBatch ) ;
65+ const contents = await Promise . all (
66+ batchUrls . map ( async ( url ) => {
67+ return await importQnAFromUrl ( builder , url , subscriptionKey ) ;
68+ } )
69+ ) ;
70+ contents . forEach ( ( content ) => {
71+ qnaContent += content ;
72+ } ) ;
73+ i = i + limitedNumInBatch ;
74+ }
6175 return qnaContent ;
6276}
0 commit comments