4141public final class MindeeHttpApi extends MindeeApi {
4242
4343 private static final ObjectMapper mapper = new ObjectMapper ();
44- private final Function <Endpoint , String > buildBaseUrl = this ::buildProductUrl ;
45- private final Function <String , String > buildWorkflowBaseUrl = this ::buildWorkflowUrl ;
44+ private final Function <Endpoint , String > buildProductPredicBasetUrl = this ::buildProductPredictBaseUrl ;
45+ private final Function <String , String > buildWorkflowPredictBaseUrl = this ::buildWorkflowPredictBaseUrl ;
46+ private final Function <String , String > buildWorkflowExecutionBaseUrl = this ::buildWorkflowExecutionUrl ;
4647 /**
4748 * The MindeeSetting needed to make the api call.
4849 */
@@ -53,24 +54,27 @@ public final class MindeeHttpApi extends MindeeApi {
5354 */
5455 private final HttpClientBuilder httpClientBuilder ;
5556 /**
56- * The function used to generate the API endpoint URL.
57+ * The function used to generate the synchronous API endpoint URL.
5758 * Only needs to be set if the api calls need to be directed through internal URLs.
5859 */
5960 private final Function <Endpoint , String > urlFromEndpoint ;
60-
6161 /**
62- * The function used to generate the API endpoint URL for workflow execution calls .
62+ * The function used to generate the asynchronous API endpoint URL for a product .
6363 * Only needs to be set if the api calls need to be directed through internal URLs.
6464 */
6565 private final Function <Endpoint , String > asyncUrlFromEndpoint ;
66+ /**
67+ * The function used to generate the asynchronous API endpoint URL for a workflow.
68+ * Only needs to be set if the api calls need to be directed through internal URLs.
69+ */
70+ private final Function <String , String > asyncUrlFromWorkflow ;
6671 /**
6772 * The function used to generate the Job status URL for Async calls.
6873 * Only needs to be set if the api calls need to be directed through internal URLs.
6974 */
7075 private final Function <Endpoint , String > documentUrlFromEndpoint ;
71-
7276 /**
73- * The function used to generate the Job status URL for Async calls.
77+ * The function used to generate the Job status URL for workflow execution calls.
7478 * Only needs to be set if the api calls need to be directed through internal URLs.
7579 */
7680 private final Function <String , String > workflowUrlFromId ;
@@ -82,6 +86,7 @@ public MindeeHttpApi(MindeeSettings mindeeSettings) {
8286 null ,
8387 null ,
8488 null ,
89+ null ,
8590 null
8691 );
8792 }
@@ -93,7 +98,8 @@ private MindeeHttpApi(
9398 Function <Endpoint , String > urlFromEndpoint ,
9499 Function <Endpoint , String > asyncUrlFromEndpoint ,
95100 Function <Endpoint , String > documentUrlFromEndpoint ,
96- Function <String , String > workflowUrlFromEndpoint
101+ Function <String , String > workflowUrlFromEndpoint ,
102+ Function <String , String > asyncUrlFromWorkflow
97103 ) {
98104 this .mindeeSettings = mindeeSettings ;
99105
@@ -106,26 +112,35 @@ private MindeeHttpApi(
106112 if (urlFromEndpoint != null ) {
107113 this .urlFromEndpoint = urlFromEndpoint ;
108114 } else {
109- this .urlFromEndpoint = buildBaseUrl .andThen ((url ) -> url .concat ("/predict" ));
115+ this .urlFromEndpoint = buildProductPredicBasetUrl .andThen (
116+ (url ) -> url .concat ("/predict" ));
117+ }
118+
119+ if (asyncUrlFromWorkflow != null ) {
120+ this .asyncUrlFromWorkflow = asyncUrlFromWorkflow ;
121+ } else {
122+ this .asyncUrlFromWorkflow = this .buildWorkflowPredictBaseUrl .andThen (
123+ (url ) -> url .concat ("/predict_async" ));
110124 }
111125
112126 if (asyncUrlFromEndpoint != null ) {
113127 this .asyncUrlFromEndpoint = asyncUrlFromEndpoint ;
114128 } else {
115- this .asyncUrlFromEndpoint = this .urlFromEndpoint .andThen ((url ) -> url .concat ("_async" ));
129+ this .asyncUrlFromEndpoint = this .buildProductPredicBasetUrl .andThen (
130+ (url ) -> url .concat ("/predict_async" ));
116131 }
117132
118133 if (documentUrlFromEndpoint != null ) {
119134 this .documentUrlFromEndpoint = documentUrlFromEndpoint ;
120135 } else {
121- this .documentUrlFromEndpoint = this .buildBaseUrl .andThen (
136+ this .documentUrlFromEndpoint = this .buildProductPredicBasetUrl .andThen (
122137 (url ) -> url .concat ("/documents/queue/" ));
123138 }
124139
125140 if (workflowUrlFromEndpoint != null ) {
126141 this .workflowUrlFromId = workflowUrlFromEndpoint ;
127142 } else {
128- this .workflowUrlFromId = this .buildWorkflowBaseUrl ;
143+ this .workflowUrlFromId = this .buildWorkflowExecutionBaseUrl ;
129144 }
130145 }
131146
@@ -233,7 +248,12 @@ public <DocT extends Inference> AsyncPredictResponse<DocT> predictAsyncPost(
233248 RequestParameters requestParameters
234249 ) throws IOException {
235250
236- String url = asyncUrlFromEndpoint .apply (endpoint );
251+ String url ;
252+ if (requestParameters .getPredictOptions ().getWorkflowId () != null ) {
253+ url = asyncUrlFromWorkflow .apply (requestParameters .getPredictOptions ().getWorkflowId ());
254+ } else {
255+ url = asyncUrlFromEndpoint .apply (endpoint );
256+ }
237257 HttpPost post = buildHttpPost (url , requestParameters );
238258
239259 // required to register jackson date module format to deserialize
@@ -340,7 +360,7 @@ private <ResponseT extends ApiResponse> MindeeHttpException getHttpError(
340360 return new MindeeHttpException (statusCode , message , details , errorCode );
341361 }
342362
343- private String buildProductUrl (Endpoint endpoint ) {
363+ private String buildProductPredictBaseUrl (Endpoint endpoint ) {
344364 return this .mindeeSettings .getBaseUrl ()
345365 + "/products/"
346366 + endpoint .getAccountName ()
@@ -350,7 +370,11 @@ private String buildProductUrl(Endpoint endpoint) {
350370 + endpoint .getVersion ();
351371 }
352372
353- private String buildWorkflowUrl (String workflowId ) {
373+ private String buildWorkflowPredictBaseUrl (String workflowId ) {
374+ return this .mindeeSettings .getBaseUrl () + "/workflows/" + workflowId ;
375+ }
376+
377+ private String buildWorkflowExecutionUrl (String workflowId ) {
354378 return this .mindeeSettings .getBaseUrl () + "/workflows/" + workflowId + "/executions" ;
355379 }
356380
@@ -388,7 +412,9 @@ private List<NameValuePair> buildPostParams(
388412 if (Boolean .TRUE .equals (requestParameters .getPredictOptions ().getFullText ())) {
389413 params .add (new BasicNameValuePair ("full_text_ocr" , "true" ));
390414 }
391- if (Boolean .TRUE .equals (requestParameters .getWorkflowOptions ().getRag ())) {
415+ if (Boolean .TRUE .equals (requestParameters .getWorkflowOptions ().getRag ())
416+ || Boolean .TRUE .equals (requestParameters .getPredictOptions ().getRag ())
417+ ) {
392418 params .add (new BasicNameValuePair ("rag" , "true" ));
393419 }
394420 return params ;
0 commit comments