Skip to content

Commit

Permalink
fix: failing tests on workflow creation
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniAkash committed Mar 27, 2024
1 parent 80c4664 commit 0237542
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 37 deletions.
14 changes: 9 additions & 5 deletions examples/app/createModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Model, App } from "../../src/index";
import { OutputInfo } from "clarifai-nodejs-grpc/proto/clarifai/api/resources_pb";
import {
ModelVersion,
OutputInfo,
} from "clarifai-nodejs-grpc/proto/clarifai/api/resources_pb";
import { Struct } from "google-protobuf/google/protobuf/struct_pb";

const app = new App({
Expand Down Expand Up @@ -33,11 +36,12 @@ const model = new Model({
const outputInfo = new OutputInfo().setParams(
Struct.fromJavaScript({ margin: 1.5 }),
);
// GRPC compatible ModelVersion object with previously created output info config
const modelVersion = new ModelVersion()
.setDescription("Setting output info margin parameters to 1.5")
.setOutputInfo(outputInfo);

// Creating a new version of the model with previously created output info config
const modelObjectWithVersion = await model.createVersion({
description: "Setting output info margin parameters to 1.5",
outputInfo: outputInfo.toObject(),
});
const modelObjectWithVersion = await model.createVersion(modelVersion);

console.log(modelObjectWithVersion);
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"from-protobuf-object": "^1.0.2",
"google-protobuf": "^3.21.2",
"js-yaml": "^4.1.0",
"safe-flat": "^2.1.0",
"uuidv4": "^6.2.13",
"winston": "^3.11.0",
"zod": "^3.22.4"
Expand Down
32 changes: 5 additions & 27 deletions src/client/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
Concept,
Dataset,
WorkflowNode,
ModelVersion,
} from "clarifai-nodejs-grpc/proto/clarifai/api/resources_pb";
import { TRAINABLE_MODEL_TYPES } from "../constants/model";
import { StatusCode } from "clarifai-nodejs-grpc/proto/clarifai/api/status/status_code_pb";
Expand All @@ -46,6 +47,7 @@ import { Model as ModelConstructor } from "./model";
import { uuid } from "uuidv4";
import { fromProtobufObject } from "from-protobuf-object";
import { fromPartialProtobufObject } from "../utils/fromPartialProtobufObject";
import { flatten } from "safe-flat";

export type AppConfig =
| {
Expand Down Expand Up @@ -587,38 +589,14 @@ export class App extends Lister {
userId: this.userAppId.getUserId(),
},
});
const modelWithVersion = await model.createVersion({
outputInfo: outputInfo.toObject(),
});
const modelVersion = new ModelVersion().setOutputInfo(outputInfo);
const modelWithVersion = await model.createVersion(modelVersion);
if (modelWithVersion) {
allModels.push(modelWithVersion);
continue;
}
}
}

// If the model version ID is specified, or if the yaml model is the same as the one in the api
// if (
// (node.model.modelVersionId ?? "") ||
// (modelObject && isSameYamlModel(modelObject, node.model))
// ) {
// allModels.push(modelObject!);
// } else if (modelObject && outputInfo) {
// const model = new ModelConstructor({
// modelId: modelObject.id,
// authConfig: {
// pat: this.pat,
// appId: this.userAppId.getAppId(),
// userId: this.userAppId.getUserId(),
// },
// });
// const modelWithVersion = await model.createVersion({
// outputInfo: outputInfo.toObject(),
// });
// if (modelWithVersion) {
// allModels.push(modelWithVersion);
// }
// }
}

// Convert nodes to resources_pb2.WorkflowNodes.
Expand Down Expand Up @@ -671,7 +649,7 @@ export class App extends Lister {

// Display the workflow nodes tree.
if (display) {
console.table(responseObject.workflowsList?.[0]?.nodesList);
console.table(flatten(responseObject.workflowsList?.[0]?.nodesList));
}
return responseObject.workflowsList?.[0];
}
Expand Down
3 changes: 1 addition & 2 deletions src/client/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export class Model extends Lister {
}

async createVersion(
args: Partial<ModelVersion.AsObject>,
modelVersion: ModelVersion,
): Promise<GrpcModel.AsObject | undefined> {
if (this.modelInfo.getModelTypeId() in TRAINABLE_MODEL_TYPES) {
throw new UserError(
Expand All @@ -365,7 +365,6 @@ export class Model extends Lister {
const request = new PostModelVersionsRequest();
request.setUserAppId(this.userAppId);
request.setModelId(this.id);
const modelVersion = fromPartialProtobufObject(ModelVersion, args);
request.setModelVersionsList([modelVersion]);

const postModelVersions = promisifyGrpcCall(
Expand Down
4 changes: 1 addition & 3 deletions tests/client/workflow/workflowCrud.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ describe("Workflow CRUD", () => {
it(
"should create workflow",
{
timeout: 20000,
timeout: 50000,
},
async () => {
for (let i = 0; i < workflowFixtureFiles.length; i++) {
const file = workflowFixtureFiles[i];
console.log("Testing file: ", file);
// TODO: remove this condition once the test case failure in custom_cropper models are fixed
if (file.includes("custom_cropper")) continue;
const generateNewId = file.endsWith("general.yml") ? false : true;
const workflow = await app.createWorkflow({
configFilePath: file,
Expand Down

0 comments on commit 0237542

Please sign in to comment.