Skip to content

Commit

Permalink
Merge pull request #141 from ainize-team/feature/yoojin/name_parser
Browse files Browse the repository at this point in the history
Add name parser to use raw name.
  • Loading branch information
yoojinko authored Dec 17, 2024
2 parents 0b81663 + b7745fa commit ec677db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/ainize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Internal from "./internal";
import { Account } from "@ainblockchain/ain-util";
import { AinWalletSigner } from "@ainblockchain/ain-js/lib/signer/ain-wallet-signer";
import { ConnectionCallback, DisconnectionCallback } from "@ainblockchain/ain-js/lib/types";
import { nameParser } from "./utils/appName";

export default class Ainize {
private cache: NodeCache;
Expand Down Expand Up @@ -86,7 +87,8 @@ export default class Ainize {
// TODO(yoojin, woojae): Deploy container, advanced.
async deploy({modelName, billingConfig, modelUrl}: deployConfig): Promise<Model> {
// TODO(yoojin, woojae): Add container deploy logic.
const result = await new Promise(async (resolve, reject) => {
const pasredName = nameParser(modelName);
await new Promise(async (resolve, reject) => {
const deployer = await this.ain.getAddress();
if (!billingConfig) {
billingConfig = {
Expand All @@ -96,15 +98,15 @@ export default class Ainize {
}
// NOTE(yoojin): For test. We make fixed url on model.
if (!modelUrl) {
modelUrl = `https://${modelName}.ainetwork.xyz`;
modelUrl = `https://${pasredName}.ainetwork.xyz`;
}
modelUrl = modelUrl.replace(/\/$/, '');
const modelPath = Path.app(modelName).status();
const modelPath = Path.app(pasredName).status();
await this.handler.subscribe(modelPath, resolve);
await this.appController.createApp({ appName: modelName, modelUrl, billingConfig });
await this.appController.createApp({ appName: pasredName, modelUrl, billingConfig });
});
console.log(`${modelName} deploy success!`);
return this.getModel(modelName);
console.log(`${pasredName} deploy success!`);
return this.getModel(pasredName);
}

/**
Expand All @@ -113,12 +115,13 @@ export default class Ainize {
* @returns {Model} Deployed model object.
*/
async getModel(modelName: string): Promise<Model> {
const modelPath = Path.app(modelName).root();
const parsedName = nameParser(modelName);
const modelPath = Path.app(parsedName).root();
const modelData = await this.ain.getValue(modelPath, { is_shallow: true });
if(!modelData) {
throw new Error("Model not found");
}
return new Model(modelName);
return new Model(parsedName);
}

test() {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/appName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const nameParser = (name: string) => {
return name.replaceAll(/[./-]/g, "_").toLowerCase();
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
"target": "es2016",
"target": "ES2021",
},
"include": [
"src/**/*"
Expand Down

0 comments on commit ec677db

Please sign in to comment.