Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add name parser to use raw name. #141

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading