Browse Source

提交代码,增加新接口。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.3.2^2
zouap 4 years ago
parent
commit
55b0f34dab
10 changed files with 843 additions and 1 deletions
  1. +1
    -1
      models/ai_model_manage.go
  2. +155
    -0
      models/dbsql/dateset_foreigntable_for_es.sql
  3. +0
    -0
      models/dbsql/issue_foreigntable_for_es.sql
  4. +0
    -0
      models/dbsql/pr_foreigntable_for_es.sql
  5. +335
    -0
      models/dbsql/repo_foreigntable_for_es.sql
  6. +282
    -0
      models/dbsql/user_foreigntable_for_es.sql
  7. +2
    -0
      options/locale/locale_en-US.ini
  8. +1
    -0
      options/locale/locale_zh-CN.ini
  9. +66
    -0
      routers/repo/ai_model_manage.go
  10. +1
    -0
      routers/routes/routes.go

+ 1
- 1
models/ai_model_manage.go View File

@@ -135,7 +135,7 @@ func QueryModelByName(name string, repoId int64) []*AiModelManage {
sess := x.NewSession()
defer sess.Close()
sess.Select("*").Table("ai_model_manage").
Where("name='" + name + "' and repo_id=" + fmt.Sprint(repoId)).OrderBy("version desc")
Where("name='" + name + "' and repo_id=" + fmt.Sprint(repoId)).OrderBy("created_unix desc")
aiModelManageList := make([]*AiModelManage, 0)
sess.Find(&aiModelManageList)
return aiModelManageList


+ 155
- 0
models/dbsql/dateset_foreigntable_for_es.sql View File

@@ -0,0 +1,155 @@
CREATE FOREIGN TABLE public."dataset_es"
(
id bigint NOT NULL,
title character varying(255),
status integer,
category character varying(255),
description text,
download_times bigint,
license character varying(255),
task character varying(255),
release_id bigint,
user_id bigint,
repo_id bigint,
created_unix bigint,
updated_unix bigint,
file_name text
)SERVER multicorn_es
OPTIONS
(
host '192.168.207.94',
port '9200',
index 'user_es-index',
rowid_column 'id'
)
;

CREATE OR REPLACE FUNCTION public.insert_dataset_data() RETURNS trigger AS
$def$
BEGIN
INSERT INTO public.dataset(
id,
title,
status,
category,
description,
download_times,
license, task,
release_id,
user_id,
repo_id,
created_unix,
updated_unix)
VALUES (
NEW.id,
NEW.title,
NEW.status,
NEW.category,
NEW.description,
NEW.download_times,
NEW.license,
NEW.task,
NEW.release_id,
NEW.user_id,
NEW.repo_id,
NEW.created_unix,
NEW.updated_unix
);
RETURN NEW;
END;
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_insert_dataset on public.dataset;

CREATE TRIGGER es_insert_dataset
AFTER INSERT ON public.dataset
FOR EACH ROW EXECUTE PROCEDURE insert_dataset_data();

CREATE OR REPLACE FUNCTION public.udpate_dataset_file_name() RETURNS trigger AS
$def$
BEGIN
if (TG_OP = 'DELETE') then
update public.dataset_es SET file_name=(select string_agg(name, ',') from public.attachment where dataset_id=OLD.dataset_id order by created_unix desc) where id=OLD.dataset_id;
elsif (TG_OP = 'INSERT') then
update public.dataset_es SET file_name=(select string_agg(name, ',') from public.attachment where dataset_id=NEW.dataset_id order by created_unix desc) where id=NEW.dataset_id;
end if;
return null;
END;
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_udpate_dataset_file_name on public.attachment;
CREATE TRIGGER es_udpate_dataset_file_name
AFTER INSERT OR DELETE ON public.attachment
FOR EACH ROW EXECUTE PROCEDURE udpate_dataset_file_name();


CREATE OR REPLACE FUNCTION public.update_dataset_description() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.dataset_es SET description=NEW.description where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_dataset_description on public.dataset;

CREATE TRIGGER es_update_dataset_description
AFTER UPDATE OF "description" ON public.dataset
FOR EACH ROW EXECUTE PROCEDURE update_dataset_description();


CREATE OR REPLACE FUNCTION public.update_dataset_title() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.dataset_es SET title=NEW.title where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_dataset_title on public.dataset;

CREATE TRIGGER es_update_dataset_title
AFTER UPDATE OF "title" ON public.dataset
FOR EACH ROW EXECUTE PROCEDURE update_dataset_title();


CREATE OR REPLACE FUNCTION public.update_dataset_category() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.dataset_es SET category=NEW.category where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_dataset_category on public.dataset;

CREATE TRIGGER es_update_dataset_category
AFTER UPDATE OF "category" ON public.dataset
FOR EACH ROW EXECUTE PROCEDURE update_dataset_category();


CREATE OR REPLACE FUNCTION public.delete_dataset() RETURNS trigger AS
$def$
declare
BEGIN
DELETE FROM public.dataset_es where id=OLD.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_delete_dataset on public.dataset;
CREATE TRIGGER es_delete_dataset
AFTER DELETE ON public.dataset
FOR EACH ROW EXECUTE PROCEDURE delete_dataset();



+ 0
- 0
models/dbsql/issue_foreigntable_for_es.sql View File


+ 0
- 0
models/dbsql/pr_foreigntable_for_es.sql View File


+ 335
- 0
models/dbsql/repo_foreigntable_for_es.sql View File

@@ -0,0 +1,335 @@
CREATE FOREIGN TABLE public.repository_es (
id bigint NOT NULL,
owner_id bigint,
owner_name character varying(255),
lower_name character varying(255) NOT NULL,
name character varying(255) NOT NULL,
description text,
website character varying(2048),
original_service_type integer,
original_url character varying(2048),
default_branch character varying(255),
num_watches integer,
num_stars integer,
num_forks integer,
num_issues integer,
num_closed_issues integer,
num_pulls integer,
num_closed_pulls integer,
num_milestones integer DEFAULT 0 NOT NULL,
num_closed_milestones integer DEFAULT 0 NOT NULL,
is_private boolean,
is_empty boolean,
is_archived boolean,
is_mirror boolean,
status integer DEFAULT 0 NOT NULL,
is_fork boolean DEFAULT false NOT NULL,
fork_id bigint,
is_template boolean DEFAULT false NOT NULL,
template_id bigint,
size bigint DEFAULT 0 NOT NULL,
is_fsck_enabled boolean DEFAULT true NOT NULL,
close_issues_via_commit_in_any_branch boolean DEFAULT false NOT NULL,
topics json,
avatar character varying(64),
created_unix bigint,
updated_unix bigint,
contract_address character varying(255),
block_chain_status integer DEFAULT 0 NOT NULL,
balance character varying(255) DEFAULT '0'::character varying NOT NULL,
clone_cnt bigint DEFAULT 0 NOT NULL,
license character varying(100),
download_cnt bigint DEFAULT 0 NOT NULL,
num_commit bigint DEFAULT 0 NOT NULL,
git_clone_cnt bigint DEFAULT 0 NOT NULL,
lang character varying(2048)
) SERVER multicorn_es
OPTIONS
(
host '192.168.207.94',
port '9200',
index 'repository-es-index',
rowid_column 'id'
)
;

CREATE OR REPLACE FUNCTION public.insert_repository_data() RETURNS trigger AS
$def$
BEGIN
INSERT INTO public.repository_es (id,
owner_id,
owner_name,
lower_name,
name,
description,
website,
original_service_type,
original_url,
default_branch,
num_watches,
num_stars,
num_forks,
num_issues,
num_closed_issues,
num_pulls,
num_closed_pulls,
num_milestones,
num_closed_milestones,
is_private,
is_empty,
is_archived,
is_mirror,
status,
is_fork,
fork_id,
is_template,
template_id,
size,
is_fsck_enabled,
close_issues_via_commit_in_any_branch,
topics,
avatar,
created_unix,
updated_unix,
contract_address,
block_chain_status,
balance,
clone_cnt,
num_commit,
git_clone_cnt) VALUES
(NEW.id,
NEW.owner_id,
NEW.owner_name,
NEW.lower_name,
NEW.name,
NEW.description,
NEW.website,
NEW.original_service_type,
NEW.original_url,
NEW.default_branch,
NEW.num_watches,
NEW.num_stars,
NEW.num_forks,
NEW.num_issues,
NEW.num_closed_issues,
NEW.num_pulls,
NEW.num_closed_pulls,
NEW.num_milestones,
NEW.num_closed_milestones,
NEW.is_private,
NEW.is_empty,
NEW.is_archived,
NEW.is_mirror,
NEW.status,
NEW.is_fork,
NEW.fork_id,
NEW.is_template,
NEW.template_id,
NEW.size,
NEW.is_fsck_enabled,
NEW.close_issues_via_commit_in_any_branch,
NEW.topics,
NEW.avatar,
NEW.created_unix,
NEW.updated_unix,
NEW.contract_address,
NEW.block_chain_status,
NEW.balance,
NEW.clone_cnt,
NEW.num_commit,
NEW.git_clone_cnt);
RETURN NEW;
END;
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_insert_repository on public.repository;

CREATE TRIGGER es_insert_repository
AFTER INSERT ON public.repository
FOR EACH ROW EXECUTE PROCEDURE insert_repository_data();


CREATE OR REPLACE FUNCTION public.update_repository_description() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.repository_es SET description=NEW.description where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_repository_description on public.repository;

CREATE TRIGGER es_update_repository_description
AFTER UPDATE OF "description" ON public.repository
FOR EACH ROW EXECUTE PROCEDURE update_repository_description();


CREATE OR REPLACE FUNCTION public.update_repository_name() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.repository_es SET name=NEW.name,lower_name=NEW.lower_name where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_repository_name on public.repository;
CREATE TRIGGER es_update_repository_name
AFTER UPDATE OF "name","lower_name" ON public.repository
FOR EACH ROW EXECUTE PROCEDURE update_repository_name();


CREATE OR REPLACE FUNCTION public.update_repository_ownername() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.repository_es SET owner_name=NEW.owner_name where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_repository_ownername on public.repository;
CREATE TRIGGER es_update_repository_ownername
AFTER UPDATE OF "owner_name" ON public.repository
FOR EACH ROW EXECUTE PROCEDURE update_repository_ownername();
CREATE OR REPLACE FUNCTION public.update_repository_website() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.repository_es SET website=NEW.website where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_repository_website on public.repository;
CREATE TRIGGER es_update_repository_website
AFTER UPDATE OF "website" ON public.repository
FOR EACH ROW EXECUTE PROCEDURE update_repository_website();

CREATE OR REPLACE FUNCTION public.update_repository_topics() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.repository_es SET topics=NEW.topics where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_repository_topics on public.repository;
CREATE TRIGGER es_update_repository_topics
AFTER UPDATE OF "topics" ON public.repository
FOR EACH ROW EXECUTE PROCEDURE update_repository_topics();



CREATE OR REPLACE FUNCTION public.update_repository_updated_unix() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.repository_es SET updated_unix=NEW.updated_unix where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_repository_updated_unix on public.repository;
CREATE TRIGGER es_update_repository_updated_unix
AFTER UPDATE OF "updated_unix" ON public.repository
FOR EACH ROW EXECUTE PROCEDURE update_repository_updated_unix();


CREATE OR REPLACE FUNCTION public.update_repository_num_watches() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.repository_es SET num_watches=NEW.num_watches where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_repository_num_watches on public.repository;
CREATE TRIGGER es_update_repository_num_watches
AFTER UPDATE OF "num_watches" ON public.repository
FOR EACH ROW EXECUTE PROCEDURE update_repository_num_watches();


CREATE OR REPLACE FUNCTION public.update_repository_num_stars() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.repository_es SET num_stars=NEW.num_stars where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_repository_num_stars on public.repository;
CREATE TRIGGER es_update_repository_num_stars
AFTER UPDATE OF "num_stars" ON public.repository
FOR EACH ROW EXECUTE PROCEDURE update_repository_num_stars();



CREATE OR REPLACE FUNCTION public.update_repository_num_forks() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.repository_es SET num_forks=NEW.num_forks where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;


DROP TRIGGER IF EXISTS es_update_repository_num_forks on public.repository;
CREATE TRIGGER es_update_repository_num_forks
AFTER UPDATE OF "num_forks" ON public.repository
FOR EACH ROW EXECUTE PROCEDURE update_repository_num_forks();

CREATE OR REPLACE FUNCTION public.delete_repository() RETURNS trigger AS
$def$
declare
BEGIN
DELETE FROM public.repository_es where id=OLD.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_delete_repository on public.repository;
CREATE TRIGGER es_delete_repository
AFTER DELETE ON public.repository
FOR EACH ROW EXECUTE PROCEDURE delete_repository();


CREATE OR REPLACE FUNCTION public.udpate_repository_lang() RETURNS trigger AS
$def$
BEGIN
if (TG_OP = 'DELETE') then
update public.repository_es SET lang=(select string_agg(language, ',') from public.language_stat where repo_id=OLD.repo_id) where id=OLD.repo_id;
elsif (TG_OP = 'UPDATE') then
update public.repository_es SET lang=(select string_agg(language, ',') from public.language_stat where repo_id=NEW.repo_id) where id=NEW.repo_id;
elsif (TG_OP = 'INSERT') then
update public.repository_es SET lang=(select string_agg(language, ',') from public.language_stat where repo_id=NEW.repo_id) where id=NEW.repo_id;
end if;
return null;
END;
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_udpate_repository_lang on public.language_stat;
CREATE TRIGGER es_udpate_repository_lang
AFTER INSERT OR UPDATE OR DELETE ON public.language_stat
FOR EACH ROW EXECUTE PROCEDURE udpate_repository_lang();

+ 282
- 0
models/dbsql/user_foreigntable_for_es.sql View File

@@ -0,0 +1,282 @@
CREATE FOREIGN TABLE public."user_es"
(
id bigint NOT NULL ,
lower_name character varying(255) NULL,
name character varying(255) NULL,
full_name character varying(255),
email character varying(255),
keep_email_private boolean,
email_notifications_preference character varying(20) ,
passwd character varying(255) ,
passwd_hash_algo character varying(255) ,
must_change_password boolean NOT NULL DEFAULT false,
login_type integer,
login_source bigint NOT NULL DEFAULT 0,
login_name character varying(255) ,
type integer,
location character varying(255),
website character varying(255),
rands character varying(10),
salt character varying(10),
language character varying(5),
description character varying(255),
created_unix bigint,
updated_unix bigint,
last_login_unix bigint,
last_repo_visibility boolean,
max_repo_creation integer,
is_active boolean,
is_admin boolean,
is_restricted boolean NOT NULL DEFAULT false,
allow_git_hook boolean,
allow_import_local boolean,
allow_create_organization boolean DEFAULT true,
prohibit_login boolean NOT NULL DEFAULT false,
avatar character varying(2048) ,
avatar_email character varying(255),
use_custom_avatar boolean,
num_followers integer,
num_following integer NOT NULL DEFAULT 0,
num_stars integer,
num_repos integer,
num_teams integer,
num_members integer,
visibility integer NOT NULL DEFAULT 0,
repo_admin_change_team_access boolean NOT NULL DEFAULT false,
diff_view_style character varying(255),
theme character varying(255),
token character varying(1024) ,
public_key character varying(255),
private_key character varying(255),
is_operator boolean NOT NULL DEFAULT false
) SERVER multicorn_es
OPTIONS
(
host '192.168.207.94',
port '9200',
index 'user_es-index',
rowid_column 'id'
)
;

CREATE OR REPLACE FUNCTION public.insert_user_data() RETURNS trigger AS
$def$
BEGIN
INSERT INTO public."user_es"(
id,
lower_name,
name,
full_name,
email,
keep_email_private,
email_notifications_preference,
must_change_password,
login_type,
login_source,
login_name,
type,
location,
website,
rands,
language,
description,
created_unix,
updated_unix,
last_login_unix,
last_repo_visibility,
max_repo_creation,
is_active,
is_restricted,
allow_git_hook,
allow_import_local,
allow_create_organization,
prohibit_login,
avatar,
avatar_email,
use_custom_avatar,
num_followers,
num_following,
num_stars,
num_repos,
num_teams,
num_members,
visibility,
repo_admin_change_team_access,
diff_view_style,
theme,
is_operator)
VALUES (
NEW.id,
NEW.lower_name,
NEW.name,
NEW.full_name,
NEW.email,
NEW.keep_email_private,
NEW.email_notifications_preference,
NEW.must_change_password,
NEW.login_type,
NEW.login_source,
NEW.login_name,
NEW.type,
NEW.location,
NEW.website,
NEW.rands,
NEW.language,
NEW.description,
NEW.created_unix,
NEW.updated_unix,
NEW.last_login_unix,
NEW.last_repo_visibility,
NEW.max_repo_creation,
NEW.is_active,
NEW.is_restricted,
NEW.allow_git_hook,
NEW.allow_import_local,
NEW.allow_create_organization,
NEW.prohibit_login,
NEW.avatar,
NEW.avatar_email,
NEW.use_custom_avatar,
NEW.num_followers,
NEW.num_following,
NEW.num_stars,
NEW.num_repos,
NEW.num_teams,
NEW.num_members,
NEW.visibility,
NEW.repo_admin_change_team_access,
NEW.diff_view_style,
NEW.theme,
NEW.is_operator
);

RETURN NEW;
END;
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_insert_user on public.user;

CREATE TRIGGER es_insert_user
AFTER INSERT ON public.user
FOR EACH ROW EXECUTE PROCEDURE insert_user_data();


CREATE OR REPLACE FUNCTION public.update_user_description() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.user_es SET description=NEW.description where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_user_description on public.user;

CREATE TRIGGER es_update_user_description
AFTER UPDATE OF "description" ON public.user
FOR EACH ROW EXECUTE PROCEDURE update_user_description();


CREATE OR REPLACE FUNCTION public.update_user_name() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.user_es SET name=NEW.name where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_user_name on public.user;

CREATE TRIGGER es_update_user_name
AFTER UPDATE OF "name" ON public.user
FOR EACH ROW EXECUTE PROCEDURE update_user_name();


CREATE OR REPLACE FUNCTION public.update_user_full_name() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.user_es SET full_name=NEW.full_name where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_user_full_name on public.user;

CREATE TRIGGER es_update_user_full_name
AFTER UPDATE OF "full_name" ON public.user
FOR EACH ROW EXECUTE PROCEDURE update_user_full_name();



CREATE OR REPLACE FUNCTION public.update_user_location() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.user_es SET location=NEW.location where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_user_location on public.user;

CREATE TRIGGER es_update_user_location
AFTER UPDATE OF "location" ON public.user
FOR EACH ROW EXECUTE PROCEDURE update_user_location();


CREATE OR REPLACE FUNCTION public.update_user_website() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.user_es SET website=NEW.website where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_user_website on public.user;

CREATE TRIGGER es_update_user_website
AFTER UPDATE OF "website" ON public.user
FOR EACH ROW EXECUTE PROCEDURE update_user_website();


CREATE OR REPLACE FUNCTION public.update_user_email() RETURNS trigger AS
$def$
declare
BEGIN
UPDATE public.user_es SET email=NEW.email where id=NEW.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_update_user_email on public.user;

CREATE TRIGGER es_update_user_email
AFTER UPDATE OF "email" ON public.user
FOR EACH ROW EXECUTE PROCEDURE update_user_email();



CREATE OR REPLACE FUNCTION public.delete_user() RETURNS trigger AS
$def$
declare
BEGIN
DELETE FROM public.user_es where id=OLD.id;
return new;
END
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_delete_user on public.user;
CREATE TRIGGER es_delete_user
AFTER DELETE ON public.user
FOR EACH ROW EXECUTE PROCEDURE delete_user();

+ 2
- 0
options/locale/locale_en-US.ini View File

@@ -779,6 +779,8 @@ datasets.desc = Enable Dataset
cloudbrain_helper=Use GPU/NPU resources to open notebooks, model training tasks, etc.

model_manager = Model
model_noright=No right
model_rename=Duplicate model name, please modify model name.

debug=Debug
stop=Stop


+ 1
- 0
options/locale/locale_zh-CN.ini View File

@@ -784,6 +784,7 @@ cloudbrain_helper=使用GPU/NPU资源,开启Notebook、模型训练任务等

model_manager = 模型
model_noright=无权限操作
model_rename=模型名称重复,请修改模型名称

debug=调试
stop=停止


+ 66
- 0
routers/repo/ai_model_manage.go View File

@@ -105,6 +105,22 @@ func saveModelByParameters(jobId string, versionName string, name string, versio
return nil
}

func SaveNewNameModel(ctx *context.Context) {
name := ctx.Query("Name")
if name == "" {
ctx.Error(500, fmt.Sprintf("name or version is null."))
return
}

aimodels := models.QueryModelByName(name, ctx.Repo.Repository.ID)
if len(aimodels) > 0 {
ctx.ServerError("Name error.", errors.New(ctx.Tr("repo.model_noright")))
}
SaveModel(ctx)

log.Info("save model end.")
}

func SaveModel(ctx *context.Context) {
log.Info("save model start.")
JobId := ctx.Query("JobId")
@@ -569,3 +585,53 @@ func ModifyModelInfo(ctx *context.Context) {
}

}

func QueryModelListForPredict(ctx *context.Context) {
repoId := ctx.Repo.Repository.ID
modelResult, count, err := models.QueryModel(&models.AiModelQueryOptions{
ListOptions: models.ListOptions{
Page: -1,
PageSize: -1,
},
RepoID: repoId,
Type: -1,
New: -1,
})
if err != nil {
ctx.ServerError("Cloudbrain", err)
return
}
log.Info("query return count=" + fmt.Sprint(count))

nameList := make([]string, 0)

nameMap := make(map[string][]*models.AiModelManage)
for _, model := range modelResult {
if _, value := nameMap[model.Name]; !value {
models := make([]*models.AiModelManage, 0)
models = append(models, model)
nameMap[model.Name] = models
nameList = append(nameList, model.Name)
} else {
nameMap[model.Name] = append(nameMap[model.Name], model)
}
}

mapInterface := make(map[string]interface{})
mapInterface["nameList"] = nameList
mapInterface["nameMap"] = nameMap
ctx.JSON(http.StatusOK, mapInterface)
}

func QueryModelFileForPredict(ctx *context.Context) {
id := ctx.Query("ID")
model, err := models.QueryModelById(id)
if err != nil {
log.Error("no such model!", err.Error())
ctx.ServerError("no such model:", err)
return
}
prefix := model.Path[len(setting.Bucket)+2:]
fileinfos, err := storage.GetAllObjectByBucketAndPrefix(setting.Bucket, prefix)
ctx.JSON(http.StatusOK, fileinfos)
}

+ 1
- 0
routers/routes/routes.go View File

@@ -975,6 +975,7 @@ func RegisterRoutes(m *macaron.Macaron) {
}, context.RepoRef())
m.Group("/modelmanage", func() {
m.Post("/create_model", reqRepoModelManageWriter, repo.SaveModel)
m.Post("/create_new_model", reqRepoModelManageWriter, repo.SaveNewNameModel)
m.Delete("/delete_model", repo.DeleteModel)
m.Put("/modify_model", repo.ModifyModelInfo)
m.Get("/show_model", reqRepoModelManageReader, repo.ShowModelTemplate)


Loading…
Cancel
Save