Skip to content

Commit

Permalink
Stew ro/use api version selected in project settings (#678)
Browse files Browse the repository at this point in the history
* refactor: change drawn region icon

* fix: use api version selected in project settings

* fix: change interpolate value for api version
  • Loading branch information
stew-ro authored Nov 3, 2020
1 parent 5614da2 commit bed69a3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const constants = {
convertedImageQuality: 0.7,
convertedThumbnailQuality: 0.2,
recentModelRecordsCount: 5,
apiModelsPath: `/formrecognizer/${apiVersion}/custom/models`,
apiModelsPath: "/formrecognizer/${apiVersion}/custom/models",
autoLabelBatchSizeMax: 10,
autoLabelBatchSizeMin: 3,
showOriginLabelsByDefault: true,
Expand Down
14 changes: 9 additions & 5 deletions src/react/components/pages/modelCompose/modelCompose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,16 @@ export default class ModelComposePage extends React.Component<IModelComposePageP
this.composeModalRef.current.open([], false, false);

if (model.attributes.isComposed) {
const apiVersion = this.props.project?.apiVersion || constants.apiVersion;
const inclModels = model.composedTrainResults ?
model.composedTrainResults
: (await this.getModelByURl(interpolate(constants.apiModelsPath, {apiVersion : (constants.apiVersion || constants.appVersion) }) + "/" + model.modelId)).composedTrainResults;
: (await this.getModelByURl(interpolate(constants.apiModelsPath, {apiVersion}) + "/" + model.modelId)).composedTrainResults;

for (const i of Object.keys(inclModels)) {
let _model: IModel;
let modelInfo: IComposedModelInfo;
try {
_model = await this.getModelByURl(interpolate(constants.apiModelsPath, {apiVersion : (constants.apiVersion || constants.appVersion) }) + "/" + inclModels[i].modelId);
_model = await this.getModelByURl(interpolate(constants.apiModelsPath, {apiVersion}) + "/" + inclModels[i].modelId);
modelInfo = {
id: _model.modelId,
name: _model.modelName,
Expand Down Expand Up @@ -457,8 +458,9 @@ export default class ModelComposePage extends React.Component<IModelComposePageP

private getRecentModels = async ():Promise<IModel[]> => {
const recentModelsList: IModel[] = [];
const apiVersion = (this.props.project?.apiVersion || constants.apiVersion);
const recentModelRequest = await allSettled(this.props.project.recentModelRecords.map(async (model) => {
return this.getModelByURl(interpolate(constants.apiModelsPath, {apiVersion : (constants.apiVersion || constants.appVersion) }) + "/" + model.modelInfo.modelId);
return this.getModelByURl(interpolate(constants.apiModelsPath, {apiVersion}) + "/" + model.modelInfo.modelId);
}))
recentModelRequest.forEach((recentModelRequest) => {
if (recentModelRequest.status === "fulfilled") {
Expand Down Expand Up @@ -521,9 +523,10 @@ export default class ModelComposePage extends React.Component<IModelComposePageP
}

private async getResponse(nextLink?: string) {
const apiVersion = (this.props.project?.apiVersion || constants.apiVersion);
const baseURL = nextLink === undefined ? url.resolve(
this.props.project.apiUriBase,
interpolate(constants.apiModelsPath, {apiVersion : (constants.apiVersion || constants.appVersion) }),
interpolate(constants.apiModelsPath, {apiVersion}),
) : url.resolve(
this.props.project.apiUriBase,
nextLink,
Expand Down Expand Up @@ -729,7 +732,8 @@ export default class ModelComposePage extends React.Component<IModelComposePageP
modelName: name,
};

const link = interpolate(constants.apiModelsPath, {apiVersion : (constants.apiVersion || constants.appVersion) }) + "/compose";
const apiVersion = (this.props.project?.apiVersion || constants.apiVersion);
const link = interpolate(constants.apiModelsPath, {apiVersion}) + "/compose";
const composeRes = await this.post(link, payload);
const composedModel = await this.waitUntilModelIsReady(composeRes["headers"]["location"]);

Expand Down
6 changes: 4 additions & 2 deletions src/react/components/pages/predict/predictPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,10 @@ export default class PredictPage extends React.Component<IPredictPageProps, IPre
strings.errors.predictWithoutTrainForbidden.message,
strings.errors.predictWithoutTrainForbidden.title);
}
const apiVersion = this.props.project?.apiVersion;
const endpointURL = url.resolve(
this.props.project.apiUriBase,
`${interpolate(constants.apiModelsPath, {apiVersion : (constants.apiVersion || constants.appVersion) })}/${modelID}/analyze?includeTextDetails=true`,
`${interpolate(constants.apiModelsPath, {apiVersion})}/${modelID}/analyze?includeTextDetails=true`,
);
let headers;
let body;
Expand Down Expand Up @@ -1166,9 +1167,10 @@ export default class PredictPage extends React.Component<IPredictPageProps, IPre

private async getRecentModelFromPredictModelId(): Promise<any> {
const modelID = this.props.project.predictModelId;
const apiVersion = this.props.project?.apiVersion || constants.apiVersion;
const endpointURL = url.resolve(
this.props.project.apiUriBase,
`${interpolate(constants.apiModelsPath, {apiVersion : (constants.apiVersion || constants.appVersion) })}/${modelID}`,
`${interpolate(constants.apiModelsPath, {apiVersion})}/${modelID}`,
);
let response;
try {
Expand Down
6 changes: 4 additions & 2 deletions src/react/components/pages/train/trainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,10 @@ export default class TrainPage extends React.Component<ITrainPageProps, ITrainPa
}

private async train(): Promise<any> {
const apiVersion = (this.props.project?.apiVersion || constants.apiVersion);
const baseURL = url.resolve(
this.props.project.apiUriBase,
interpolate(constants.apiModelsPath, {apiVersion : (constants.apiVersion || constants.appVersion) }),
interpolate(constants.apiModelsPath, {apiVersion}),
);
const provider = this.props.project.sourceConnection.providerOptions as any;
let trainSourceURL;
Expand Down Expand Up @@ -524,7 +525,8 @@ export default class TrainPage extends React.Component<ITrainPageProps, ITrainPa
}

private async triggerJsonDownload(): Promise<any> {
const currModelUrl = this.props.project.apiUriBase + interpolate(constants.apiModelsPath, {apiVersion : (constants.apiVersion || constants.appVersion) }) + "/" + this.state.currTrainRecord.modelInfo.modelId;
const apiVersion = (this.props.project?.apiVersion || constants.apiVersion);
const currModelUrl = this.props.project.apiUriBase + interpolate(constants.apiModelsPath, {apiVersion}) + "/" + this.state.currTrainRecord.modelInfo.modelId;
const modelUrl = this.state.modelUrl.length ? this.state.modelUrl : currModelUrl;
const modelJSON = await this.getModelsJson(this.props.project, modelUrl);

Expand Down
3 changes: 2 additions & 1 deletion src/services/predictService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export class PredictService {
strings.errors.predictWithoutTrainForbidden.message,
strings.errors.predictWithoutTrainForbidden.title);
}
const apiVersion = this.project?.apiVersion || constants.apiVersion;
const endpointURL = url.resolve(
this.project.apiUriBase,
`${interpolate(constants.apiModelsPath, {apiVersion : (constants.apiVersion || constants.appVersion) })}/${modelID}/analyze?includeTextDetails=true`,
`${interpolate(constants.apiModelsPath, {apiVersion})}/${modelID}/analyze?includeTextDetails=true`,
);

const headers = { "Content-Type": "application/json", "cache-control": "no-cache" };
Expand Down

0 comments on commit bed69a3

Please sign in to comment.