From b786ee4a367c3c5eca6092ade5f095cd868f2e73 Mon Sep 17 00:00:00 2001 From: lidongjie Date: Mon, 14 Oct 2024 17:51:28 +0800 Subject: [PATCH 01/23] =?UTF-8?q?add:=E6=B7=BB=E5=8A=A0GroqCloud=E4=BE=9B?= =?UTF-8?q?=E5=BA=94=E5=95=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai-provider/model-runtime/model-providers/groq/groq.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai-provider/model-runtime/model-providers/groq/groq.yaml b/ai-provider/model-runtime/model-providers/groq/groq.yaml index 3c707267..b2ce06f8 100644 --- a/ai-provider/model-runtime/model-providers/groq/groq.yaml +++ b/ai-provider/model-runtime/model-providers/groq/groq.yaml @@ -30,4 +30,4 @@ provider_credential_schema: placeholder: zh_Hans: 在此输入您的 API Key en_US: Enter your API Key -address: https://api.openai.com \ No newline at end of file +address: https://api.groq.com \ No newline at end of file From 306da2fcc5d57b9917696d9f990f780a038dbc7f Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 16:16:46 +0800 Subject: [PATCH 02/23] test frontend dir change --- frontend/frontend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/frontend.go b/frontend/frontend.go index fb85f8ce..56541905 100644 --- a/frontend/frontend.go +++ b/frontend/frontend.go @@ -29,7 +29,7 @@ var ( indexHtml []byte ) var ( - expires = time.Hour * 24 * 7 + expires = time.Hour * 24 * 3 cacheControl = fmt.Sprintf("public, max-age=%d", 3600*24*7) ) From 3431805088ee7eb36cedec1ef32a7f2afd5ec72f Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 16:58:17 +0800 Subject: [PATCH 03/23] Gitlab automatically compiles and submits --- .gitlab-ci.yml | 88 ++++++++++++++++++++++++++++++++++++++++++++ frontend/frontend.go | 2 +- 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..36e7b488 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,88 @@ +variables: + PATH: /opt/go-1.21/go/bin/:/opt/node/node/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin + GOROOT: /opt/go-1.21/go + GOPROXY: https://goproxy.cn + VERSION: $CI_COMMIT_SHORT_SHA + APP: apipark + APP_PRE: ${APP}_${VERSION} + BUILD_DIR: ${APP}-build + DEPLOY_DESC: "DEV 环境" + VIEW_ADDR: http://172.18.166.219:8288 + SAVE_DIR: /opt/${APP} + NODE_OPTIONS: --max_old_space_size=8192 + +stages: + - notice + - prefix + - build + - publish + - webhook + +feishu-informer: # 飞书回调 + stage: notice + variables: + DIFF_URL: "$CI_MERGE_REQUEST_PROJECT_URL/-/merge_requests/$CI_MERGE_REQUEST_IID/diffs" + rules: + - if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH =~ "main" + script: + - echo "merge request" + - | + curl -X POST -H "Content-Type: application/json" \ + -d "{\"msg_type\":\"text\",\"content\":{\"text\":\"项目:${CI_PROJECT_NAME}\\n提交人:${GITLAB_USER_NAME}\\n提交信息:${CI_MERGE_REQUEST_TITLE}\\n合并分支信息:${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} -> ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}\\n差异性地址:${DIFF_URL}\\n请及时review代码\"}}" \ + https://open.feishu.cn/open-apis/bot/v2/hook/1c334752-2874-41a1-8f1b-3060f2d46b6c + +prebuild: + stage: prefix + rules: + - if: $CI_COMMIT_BRANCH =~ "main" + script: + - echo "prebuild" + - chmod +x ./scripts/prefix.sh + - ./scripts/prefix.sh + +builder: + stage: build + rules: + - if: $CI_COMMIT_BRANCH =~ "main" + script: + - go mod tidy + - mv ../artifacts/dist frontend/dist + - | + if [ -n "$(git diff --name-status HEAD~1 HEAD -- frontend)" ]; then + ./scripts/build.sh $BUILD_DIR ${VERSION} all "" + rm -rf ../artifacts/dist + cp -r frontend/dist ../artifacts/dist + else + ./scripts/build.sh $BUILD_DIR ${VERSION} + fi + cp $BUILD_DIR/${APP_PRE}_linux_amd64.tar.gz ${SAVE_DIR} + +deployer: + stage: deploy + variables: + APIPARK_GUEST_MODE: allow + APIPARK_GUEST_ID: dklejrfbhjqwdh + script: + - cp artifacts/${APP_PRE}_linux_amd64.tar.gz ${SAVE_DIR} + - cd ${SAVE_DIR};mkdir -p ${APP_PRE};tar -zxvf ${APP_PRE}_linux_amd64.tar.gz -C ${APP_PRE};cd ${APP_PRE};./install.sh ${SAVE_DIR};./run.sh restart;cd ${SAVE_DIR} && ./clean.sh ${APP_PRE} + when: on_success +success: + stage: webhook + rules: + - if: $CI_COMMIT_BRANCH =~ "main" + script: + - | + curl -X POST -H "Content-Type: application/json" \ + -d "{\"msg_type\":\"text\",\"content\":{\"text\":\"最近一次提交:${CI_COMMIT_TITLE}\\n提交人:${GITLAB_USER_NAME}\\n项目:${CI_PROJECT_NAME}\\n环境:${DEPLOY_DESC}\\n更新部署完成.\\n访问地址:${VIEW_ADDR}\\n工作流地址:${CI_PIPELINE_URL}\"}}" \ + https://open.feishu.cn/open-apis/bot/v2/hook/c3672932-4dfa-4989-8023-0128bae59338 + when: on_success +failure: + stage: webhook + rules: + - if: $CI_COMMIT_BRANCH =~ "main" + script: + - | + curl -X POST -H "Content-Type: application/json" \ + -d "{\"msg_type\":\"text\",\"content\":{\"text\":\"最近一次提交:${CI_COMMIT_TITLE}\\n提交人:${GITLAB_USER_NAME}\\n项目:${CI_PROJECT_NAME}\\n环境:${DEPLOY_DESC}\\n更新部署失败,请及时到gitlab上查看\\n工作流地址:${CI_PIPELINE_URL}\"}}" \ + https://open.feishu.cn/open-apis/bot/v2/hook/c3672932-4dfa-4989-8023-0128bae59338 + when: on_failure diff --git a/frontend/frontend.go b/frontend/frontend.go index 56541905..fb85f8ce 100644 --- a/frontend/frontend.go +++ b/frontend/frontend.go @@ -29,7 +29,7 @@ var ( indexHtml []byte ) var ( - expires = time.Hour * 24 * 3 + expires = time.Hour * 24 * 7 cacheControl = fmt.Sprintf("public, max-age=%d", 3600*24*7) ) From 2702b71cc6a30edd9284ecdfc035271bf9de2240 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 17:04:57 +0800 Subject: [PATCH 04/23] update stage --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 36e7b488..358bdbe4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,7 +15,7 @@ stages: - notice - prefix - build - - publish + - deploy - webhook feishu-informer: # 飞书回调 From 19fc1b6958059ae519552e1fbba6173f7087100f Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 17:06:52 +0800 Subject: [PATCH 05/23] update run auto deploy condition --- .gitlab-ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 358bdbe4..9b2d0afe 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -59,6 +59,8 @@ builder: deployer: stage: deploy + rules: + - if: $CI_COMMIT_BRANCH =~ "main" variables: APIPARK_GUEST_MODE: allow APIPARK_GUEST_ID: dklejrfbhjqwdh @@ -69,7 +71,7 @@ deployer: success: stage: webhook rules: - - if: $CI_COMMIT_BRANCH =~ "main" + - if: $CI_COMMIT_BRANCH =~ "main" script: - | curl -X POST -H "Content-Type: application/json" \ @@ -79,7 +81,7 @@ success: failure: stage: webhook rules: - - if: $CI_COMMIT_BRANCH =~ "main" + - if: $CI_COMMIT_BRANCH =~ "main" script: - | curl -X POST -H "Content-Type: application/json" \ From 0b4b183ba7097ad1087666dfe5e9eef187569192 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 17:46:26 +0800 Subject: [PATCH 06/23] =?UTF-8?q?=E6=96=B0=E5=BB=BAprefix.sh=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/prefix.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 scripts/prefix.sh diff --git a/scripts/prefix.sh b/scripts/prefix.sh new file mode 100755 index 00000000..800e9117 --- /dev/null +++ b/scripts/prefix.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# =========================================================================== +# File: build.sh +# Description: usage: ./prefix.sh +# =========================================================================== +cd "$(dirname "$0")" +cd ../../ +BASEPATH="$(pwd)" + +set -e + + +# ========================================================================= +# 更新 aoaccount +# ========================================================================= +echo "更新 eosc" +cd "${BASEPATH}/" +if [ ! -d "./eosc" ]; then + git clone http://gitlab.eolink.com/goku/eosc.git +fi +cd "./eosc" && git pull + +# ========================================================================= +# 更新 aoaccount +# ========================================================================= +echo "更新 aoaccount" +cd "${BASEPATH}/" +if [ ! -d "./aoaccount" ]; then + git clone http://gitlab.eolink.com/apinto/aoaccount.git +fi +cd "./aoaccount" && git pull + From 5b1eac58e4c6d924e6865078b319cbd08adcf320 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 17:56:50 +0800 Subject: [PATCH 07/23] fix builder exec script --- .gitlab-ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9b2d0afe..d6c9eab7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,11 +46,14 @@ builder: - if: $CI_COMMIT_BRANCH =~ "main" script: - go mod tidy - - mv ../artifacts/dist frontend/dist + - | + if [ -d "../artifacts/dist" ]; then + cp -r ../artifacts/dist frontend/dist + fi - | if [ -n "$(git diff --name-status HEAD~1 HEAD -- frontend)" ]; then ./scripts/build.sh $BUILD_DIR ${VERSION} all "" - rm -rf ../artifacts/dist + rm -fr ../artifacts/dist cp -r frontend/dist ../artifacts/dist else ./scripts/build.sh $BUILD_DIR ${VERSION} From 998b5af4ae4b6ade2152abf51c0ecf5a07ebb80b Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 18:00:20 +0800 Subject: [PATCH 08/23] update deploy exec script --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d6c9eab7..2e0de137 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -68,7 +68,6 @@ deployer: APIPARK_GUEST_MODE: allow APIPARK_GUEST_ID: dklejrfbhjqwdh script: - - cp artifacts/${APP_PRE}_linux_amd64.tar.gz ${SAVE_DIR} - cd ${SAVE_DIR};mkdir -p ${APP_PRE};tar -zxvf ${APP_PRE}_linux_amd64.tar.gz -C ${APP_PRE};cd ${APP_PRE};./install.sh ${SAVE_DIR};./run.sh restart;cd ${SAVE_DIR} && ./clean.sh ${APP_PRE} when: on_success success: From 508bfb7891c734c987488b76d640daa8e9d59673 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 18:01:47 +0800 Subject: [PATCH 09/23] update gitlab runner exec rule --- .gitlab-ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2e0de137..4a29bba7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,7 +23,7 @@ feishu-informer: # 飞书回调 variables: DIFF_URL: "$CI_MERGE_REQUEST_PROJECT_URL/-/merge_requests/$CI_MERGE_REQUEST_IID/diffs" rules: - - if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH =~ "main" + - if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH == "main" script: - echo "merge request" - | @@ -34,7 +34,7 @@ feishu-informer: # 飞书回调 prebuild: stage: prefix rules: - - if: $CI_COMMIT_BRANCH =~ "main" + - if: $CI_COMMIT_BRANCH == "main" script: - echo "prebuild" - chmod +x ./scripts/prefix.sh @@ -43,7 +43,7 @@ prebuild: builder: stage: build rules: - - if: $CI_COMMIT_BRANCH =~ "main" + - if: $CI_COMMIT_BRANCH == "main" script: - go mod tidy - | @@ -63,7 +63,7 @@ builder: deployer: stage: deploy rules: - - if: $CI_COMMIT_BRANCH =~ "main" + - if: $CI_COMMIT_BRANCH == "main" variables: APIPARK_GUEST_MODE: allow APIPARK_GUEST_ID: dklejrfbhjqwdh @@ -73,7 +73,7 @@ deployer: success: stage: webhook rules: - - if: $CI_COMMIT_BRANCH =~ "main" + - if: $CI_COMMIT_BRANCH == "main" script: - | curl -X POST -H "Content-Type: application/json" \ @@ -83,7 +83,7 @@ success: failure: stage: webhook rules: - - if: $CI_COMMIT_BRANCH =~ "main" + - if: $CI_COMMIT_BRANCH == "main" script: - | curl -X POST -H "Content-Type: application/json" \ From 86b566a8cd94e800f5a5fffbe1aff5516a4cf3d2 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 18:12:44 +0800 Subject: [PATCH 10/23] update feishu informer rule --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4a29bba7..e7007aba 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,7 +23,7 @@ feishu-informer: # 飞书回调 variables: DIFF_URL: "$CI_MERGE_REQUEST_PROJECT_URL/-/merge_requests/$CI_MERGE_REQUEST_IID/diffs" rules: - - if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH == "main" + - if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH ~= "main" script: - echo "merge request" - | From f64a20fbacbd0014c6847ab82ad02312f568c9c2 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 18:17:11 +0800 Subject: [PATCH 11/23] update feishu informer rule --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e7007aba..7edee971 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,7 +23,7 @@ feishu-informer: # 飞书回调 variables: DIFF_URL: "$CI_MERGE_REQUEST_PROJECT_URL/-/merge_requests/$CI_MERGE_REQUEST_IID/diffs" rules: - - if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH ~= "main" + - if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH ~= "main" script: - echo "merge request" - | From 09ac4cf9700a376771863721df8d8dcd96b89cd4 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 18:19:30 +0800 Subject: [PATCH 12/23] update feishu informer rule --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7edee971..689d28d1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,7 +23,7 @@ feishu-informer: # 飞书回调 variables: DIFF_URL: "$CI_MERGE_REQUEST_PROJECT_URL/-/merge_requests/$CI_MERGE_REQUEST_IID/diffs" rules: - - if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH ~= "main" + - if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH =~ "main" script: - echo "merge request" - | From 5d1a7a7ca49b667cde92e6569f68b0cf3478ce97 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 18:28:26 +0800 Subject: [PATCH 13/23] update builder script --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 689d28d1..a20f1f8a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -47,6 +47,9 @@ builder: script: - go mod tidy - | + if [ -d "../artifacts" ]; then + mkdir -p ../artifacts + fi if [ -d "../artifacts/dist" ]; then cp -r ../artifacts/dist frontend/dist fi From 486bf0edcd07a9a8e991876065dd93903597e5e7 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 18:36:19 +0800 Subject: [PATCH 14/23] update builder script --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a20f1f8a..c5830077 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -45,9 +45,9 @@ builder: rules: - if: $CI_COMMIT_BRANCH == "main" script: - - go mod tidy + - set -e - | - if [ -d "../artifacts" ]; then + if [ ! -d "../artifacts" ]; then mkdir -p ../artifacts fi if [ -d "../artifacts/dist" ]; then From 436ab32937f2ecb8e1b74cc0a40a0fd632e73c10 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 18:43:06 +0800 Subject: [PATCH 15/23] print frontend dir --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c5830077..b65ab85a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -56,8 +56,11 @@ builder: - | if [ -n "$(git diff --name-status HEAD~1 HEAD -- frontend)" ]; then ./scripts/build.sh $BUILD_DIR ${VERSION} all "" + echo "" + ll -a frontend rm -fr ../artifacts/dist cp -r frontend/dist ../artifacts/dist + ll -a ../artifacts else ./scripts/build.sh $BUILD_DIR ${VERSION} fi From 73b2fea954e4f9528b2f34b042121c6d9dc61dee Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 18:47:54 +0800 Subject: [PATCH 16/23] print frontend dir --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b65ab85a..f0a9f42c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -56,10 +56,11 @@ builder: - | if [ -n "$(git diff --name-status HEAD~1 HEAD -- frontend)" ]; then ./scripts/build.sh $BUILD_DIR ${VERSION} all "" - echo "" + echo "print frontend dir file:" ll -a frontend rm -fr ../artifacts/dist cp -r frontend/dist ../artifacts/dist + echo "print artifacts dir file:" ll -a ../artifacts else ./scripts/build.sh $BUILD_DIR ${VERSION} From 84e1528a1dcc0eb8a2b1c8a0d79f435ab3d0aadc Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 18:53:28 +0800 Subject: [PATCH 17/23] copy frontend/dist to artifacts/dist --- .gitlab-ci.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f0a9f42c..df0d9946 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -56,15 +56,14 @@ builder: - | if [ -n "$(git diff --name-status HEAD~1 HEAD -- frontend)" ]; then ./scripts/build.sh $BUILD_DIR ${VERSION} all "" - echo "print frontend dir file:" - ll -a frontend - rm -fr ../artifacts/dist - cp -r frontend/dist ../artifacts/dist - echo "print artifacts dir file:" - ll -a ../artifacts else ./scripts/build.sh $BUILD_DIR ${VERSION} fi + if [ -d "frontend/dist" ]; then + echo "copy frontend/dist to artifacts/dist" + rm -fr ../artifacts/dist + cp -r frontend/dist ../artifacts/dist + fi cp $BUILD_DIR/${APP_PRE}_linux_amd64.tar.gz ${SAVE_DIR} deployer: From 558e8fad61e3a8b6cb363fef93597d191f8f0a34 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 21 Oct 2024 18:59:24 +0800 Subject: [PATCH 18/23] test frontend change --- frontend/frontend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/frontend.go b/frontend/frontend.go index fb85f8ce..56541905 100644 --- a/frontend/frontend.go +++ b/frontend/frontend.go @@ -29,7 +29,7 @@ var ( indexHtml []byte ) var ( - expires = time.Hour * 24 * 7 + expires = time.Hour * 24 * 3 cacheControl = fmt.Sprintf("public, max-age=%d", 3600*24*7) ) From 4d398fd4d57cb0dd0a7f88c318aacb55bafffd57 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Wed, 23 Oct 2024 13:38:16 +0800 Subject: [PATCH 19/23] update providers logo --- ai-provider/model-runtime/provider.go | 10 +++++----- stores/api/model.go | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ai-provider/model-runtime/provider.go b/ai-provider/model-runtime/provider.go index db19f849..226719eb 100644 --- a/ai-provider/model-runtime/provider.go +++ b/ai-provider/model-runtime/provider.go @@ -55,10 +55,10 @@ func NewProvider(providerData string, modelContents map[string]eosc.Untyped[stri } delete(modelContents, DirAssets) - providerLogo, ok := assetsFiles.Get(providerCfg.IconLarge[entity.LanguageEnglish]) - if !ok { - return nil, fmt.Errorf("provider logo not found:%s", providerCfg.Provider) - } + //providerLogo, ok := assetsFiles.Get(providerCfg.IconLarge[entity.LanguageEnglish]) + //if !ok { + // return nil, fmt.Errorf("provider logo not found:%s", providerCfg.Provider) + //} modelLogo, ok := assetsFiles.Get(providerCfg.IconSmall[entity.LanguageEnglish]) if !ok { return nil, fmt.Errorf("model logo not found:%s", providerCfg.Provider) @@ -66,7 +66,7 @@ func NewProvider(providerData string, modelContents map[string]eosc.Untyped[stri provider := &Provider{ id: providerCfg.Provider, name: providerCfg.Label[entity.LanguageEnglish], - logo: providerLogo, + logo: modelLogo, helpUrl: providerCfg.Help.URL[entity.LanguageEnglish], models: eosc.BuildUntyped[string, IModel](), defaultModels: eosc.BuildUntyped[string, IModel](), diff --git a/stores/api/model.go b/stores/api/model.go index 8ad0c610..0c81e9db 100644 --- a/stores/api/model.go +++ b/stores/api/model.go @@ -13,9 +13,9 @@ type API struct { Creator string `gorm:"size:36;not null;column:creator;comment:创建人;index:creator" aovalue:"creator"` // 创建人 CreateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:create_at;comment:创建时间"` IsDelete int `gorm:"type:tinyint(1);not null;column:is_delete;comment:是否删除 0:未删除 1:已删除"` - Method []string `gorm:"size:36;not null;column:method;comment:请求方法;serializer:json"` + Method []string `gorm:"size:255;not null;column:method;comment:请求方法;serializer:json"` Protocol []string `gorm:"type:text;not null;column:protocol;comment:协议;serializer:json"` - Path string `gorm:"size:512;not null;column:path;comment:请求路径"` + Path string `gorm:"size:255;not null;column:path;comment:请求路径"` } type Info struct { Id int64 `gorm:"column:id;type:BIGINT(20);NOT NULL;comment:id;primary_key;comment:主键ID;"` @@ -25,8 +25,8 @@ type Info struct { Service string `gorm:"size:36;not null;column:service;comment:服务;index:service"` Team string `gorm:"size:36;not null;column:team;comment:团队;index:team"` // 团队id Upstream string `gorm:"size:36;not null;column:upstream;comment:上游;index:upstream"` - Method []string `gorm:"size:36;not null;column:method;comment:请求方法;serializer:json" ` - Path string `gorm:"size:512;not null;column:path;comment:请求路径"` + Method []string `gorm:"size:255;not null;column:method;comment:请求方法;serializer:json" ` + Path string `gorm:"size:255;not null;column:path;comment:请求路径"` Protocol []string `gorm:"type:text;null;column:protocol;comment:协议;serializer:json"` Match string `gorm:"type:text;null;column:match;comment:匹配规则"` Creator string `gorm:"size:36;not null;column:creator;comment:创建人;index:creator" aovalue:"creator"` // 创建人 @@ -74,7 +74,7 @@ type AiAPIInfo struct { Uuid string `gorm:"type:varchar(36);not null;column:uuid;uniqueIndex:uuid;comment:UUID"` Name string `gorm:"type:varchar(100);not null;column:name;comment:name"` Service string `gorm:"size:36;not null;column:service;comment:服务;index:service"` - Path string `gorm:"size:512;not null;column:path;comment:请求路径"` + Path string `gorm:"size:255;not null;column:path;comment:请求路径"` Description string `gorm:"size:255;not null;column:description;comment:description"` Timeout int `gorm:"type:int(11);not null;column:timeout;comment:超时时间"` Retry int `gorm:"type:int(11);not null;column:retry;comment:重试次数"` From b9e676d926cf3cab5ee3349fadf0ef1ccaae7dc2 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Wed, 23 Oct 2024 14:22:44 +0800 Subject: [PATCH 20/23] update provider logo --- .../model-providers/deepseek/assets/icon_s_en.svg | 2 +- .../model-providers/fireworks/assets/icon_s_en.svg | 2 +- .../model-providers/mistralai/assets/icon_s_en.svg | 2 +- .../model-providers/moonshot/assets/icon_s_en.svg | 2 +- .../model-providers/novita/assets/icon_s_en.svg | 2 +- .../model-providers/nvidia/assets/icon_s_en.svg | 2 +- .../model-providers/perfxcloud/assets/icon_s_en.svg | 6 +++--- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ai-provider/model-runtime/model-providers/deepseek/assets/icon_s_en.svg b/ai-provider/model-runtime/model-providers/deepseek/assets/icon_s_en.svg index aa854a75..0e099fe1 100644 --- a/ai-provider/model-runtime/model-providers/deepseek/assets/icon_s_en.svg +++ b/ai-provider/model-runtime/model-providers/deepseek/assets/icon_s_en.svg @@ -1,3 +1,3 @@ - + diff --git a/ai-provider/model-runtime/model-providers/fireworks/assets/icon_s_en.svg b/ai-provider/model-runtime/model-providers/fireworks/assets/icon_s_en.svg index 86eeba66..aa695dca 100644 --- a/ai-provider/model-runtime/model-providers/fireworks/assets/icon_s_en.svg +++ b/ai-provider/model-runtime/model-providers/fireworks/assets/icon_s_en.svg @@ -1,4 +1,4 @@ - + diff --git a/ai-provider/model-runtime/model-providers/mistralai/assets/icon_s_en.svg b/ai-provider/model-runtime/model-providers/mistralai/assets/icon_s_en.svg index 7a3feba5..09449f16 100644 --- a/ai-provider/model-runtime/model-providers/mistralai/assets/icon_s_en.svg +++ b/ai-provider/model-runtime/model-providers/mistralai/assets/icon_s_en.svg @@ -1,6 +1,6 @@ - - diff --git a/ai-provider/model-runtime/model-providers/novita/assets/icon_s_en.svg b/ai-provider/model-runtime/model-providers/novita/assets/icon_s_en.svg index 798c1d63..97782cd7 100644 --- a/ai-provider/model-runtime/model-providers/novita/assets/icon_s_en.svg +++ b/ai-provider/model-runtime/model-providers/novita/assets/icon_s_en.svg @@ -1,4 +1,4 @@ - + diff --git a/ai-provider/model-runtime/model-providers/nvidia/assets/icon_s_en.svg b/ai-provider/model-runtime/model-providers/nvidia/assets/icon_s_en.svg index 562ce462..989e2e01 100644 --- a/ai-provider/model-runtime/model-providers/nvidia/assets/icon_s_en.svg +++ b/ai-provider/model-runtime/model-providers/nvidia/assets/icon_s_en.svg @@ -1,3 +1,3 @@ - + diff --git a/ai-provider/model-runtime/model-providers/perfxcloud/assets/icon_s_en.svg b/ai-provider/model-runtime/model-providers/perfxcloud/assets/icon_s_en.svg index be0c2eeb..060d9de3 100644 --- a/ai-provider/model-runtime/model-providers/perfxcloud/assets/icon_s_en.svg +++ b/ai-provider/model-runtime/model-providers/perfxcloud/assets/icon_s_en.svg @@ -1,8 +1,8 @@ - - + + - + From 9a6196bbd7546769017266f736d4824c522e34e4 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Wed, 23 Oct 2024 16:29:18 +0800 Subject: [PATCH 21/23] update ai provider api --- ai-provider/model-runtime/entity/provider.go | 6 ++-- ai-provider/model-runtime/manager.go | 11 ++++++- .../model-providers/authropic/anthropic.yaml | 2 ++ .../model-providers/bedrock/bedrock.yaml | 6 ++-- .../model-providers/google/google.yaml | 6 ++-- .../model-providers/minimax/minimax.yaml | 4 ++- .../model-providers/moonshot/moonshot.yaml | 4 ++- .../model-providers/nvidia/nvidia.yaml | 2 +- .../model-providers/openAI/openai.yaml | 2 ++ .../model-providers/wenxin/wenxin.yaml | 6 ++-- .../zhinao/assets/icon_l_en.svg | 4 +-- .../zhinao/assets/icon_s_en.svg | 4 +-- ai-provider/model-runtime/provider.go | 14 ++++++++ module/ai/dto/input.go | 3 +- module/ai/dto/output.go | 4 ++- module/ai/iml.go | 33 +++++++++++++------ module/service/dto/output.go | 1 + module/service/iml.go | 18 +++++++--- service/application-authorization/iml.go | 20 +++++++---- service/application-authorization/service.go | 3 +- 20 files changed, 113 insertions(+), 40 deletions(-) diff --git a/ai-provider/model-runtime/entity/provider.go b/ai-provider/model-runtime/entity/provider.go index 195da52a..d9014560 100644 --- a/ai-provider/model-runtime/entity/provider.go +++ b/ai-provider/model-runtime/entity/provider.go @@ -21,8 +21,10 @@ type Provider struct { Help Help `json:"help" yaml:"help"` SupportedModelTypes []string `json:"supported_model_types" yaml:"supported_model_types"` ProviderCredentialSchema ProviderCredentialSchema `json:"provider_credential_schema" yaml:"provider_credential_schema"` - Default map[string]string `json:"default"` - Address string `json:"address"` + Default map[string]string `json:"default" yaml:"default"` + Address string `json:"address" yaml:"address"` + Recommend bool `json:"recommend" yaml:"recommend"` + Sort int `json:"sort" yaml:"sort"` } type ProviderCredentialSchema struct { diff --git a/ai-provider/model-runtime/manager.go b/ai-provider/model-runtime/manager.go index 382866e4..dbefea3e 100644 --- a/ai-provider/model-runtime/manager.go +++ b/ai-provider/model-runtime/manager.go @@ -1,6 +1,8 @@ package model_runtime -import "github.com/eolinker/eosc" +import ( + "github.com/eolinker/eosc" +) var ( defaultManager = NewManager() @@ -27,6 +29,13 @@ func (m *Manager) Del(name string) { } func (m *Manager) List() []IProvider { + //list := m.providers.List() + //sort.Slice(list, func(i, j int) bool { + // if list[i].Sort() == list[j].Sort() { + // return list[i].ID() < list[j].ID() + // } + // return list[i].Sort() < list[j].Sort() + //}) return m.providers.List() } diff --git a/ai-provider/model-runtime/model-providers/authropic/anthropic.yaml b/ai-provider/model-runtime/model-providers/authropic/anthropic.yaml index 10cad537..f44d3e18 100644 --- a/ai-provider/model-runtime/model-providers/authropic/anthropic.yaml +++ b/ai-provider/model-runtime/model-providers/authropic/anthropic.yaml @@ -38,3 +38,5 @@ provider_credential_schema: zh_Hans: 在此输入您的 API URL en_US: Enter your API URL address: https://api.anthropic.com +recommend: true +sort: 2 \ No newline at end of file diff --git a/ai-provider/model-runtime/model-providers/bedrock/bedrock.yaml b/ai-provider/model-runtime/model-providers/bedrock/bedrock.yaml index bda4cc38..b9f165c2 100644 --- a/ai-provider/model-runtime/model-providers/bedrock/bedrock.yaml +++ b/ai-provider/model-runtime/model-providers/bedrock/bedrock.yaml @@ -1,6 +1,6 @@ provider: bedrock label: - en_US: AWS + en_US: AWS Bedrock description: en_US: AWS Bedrock's models. icon_small: @@ -87,4 +87,6 @@ provider_credential_schema: placeholder: en_US: A model you have access to (e.g. amazon.titan-text-lite-v1) for validation. zh_Hans: 为了进行验证,请输入一个您可用的模型名称 (例如:amazon.titan-text-lite-v1) -address: https://bedrock-runtime.amazonaws.com \ No newline at end of file +address: https://bedrock-runtime.amazonaws.com +sort: 4 +recommend: true \ No newline at end of file diff --git a/ai-provider/model-runtime/model-providers/google/google.yaml b/ai-provider/model-runtime/model-providers/google/google.yaml index 1d45610f..e54c899f 100644 --- a/ai-provider/model-runtime/model-providers/google/google.yaml +++ b/ai-provider/model-runtime/model-providers/google/google.yaml @@ -1,6 +1,6 @@ provider: google label: - en_US: Google + en_US: Google Gemini description: en_US: Google's Gemini model. zh_Hans: 谷歌提供的 Gemini 模型. @@ -38,4 +38,6 @@ provider_credential_schema: placeholder: zh_Hans: 在此输入您的 API Base, 如:https://api.google.com en_US: Enter your API Base, e.g. https://api.google.com -address: https://generativelanguage.googleapis.com \ No newline at end of file +address: https://generativelanguage.googleapis.com +recommend: true +sort: 3 \ No newline at end of file diff --git a/ai-provider/model-runtime/model-providers/minimax/minimax.yaml b/ai-provider/model-runtime/model-providers/minimax/minimax.yaml index c4ce3c75..d6d82e8a 100644 --- a/ai-provider/model-runtime/model-providers/minimax/minimax.yaml +++ b/ai-provider/model-runtime/model-providers/minimax/minimax.yaml @@ -27,4 +27,6 @@ provider_credential_schema: placeholder: zh_Hans: 在此输入您的 API Key en_US: Enter your API Key -address: https://api.minimax.chat \ No newline at end of file +address: https://api.minimax.chat +recommend: true +sort: 5 \ No newline at end of file diff --git a/ai-provider/model-runtime/model-providers/moonshot/moonshot.yaml b/ai-provider/model-runtime/model-providers/moonshot/moonshot.yaml index 577bf26c..406213b3 100644 --- a/ai-provider/model-runtime/model-providers/moonshot/moonshot.yaml +++ b/ai-provider/model-runtime/model-providers/moonshot/moonshot.yaml @@ -31,4 +31,6 @@ provider_credential_schema: placeholder: zh_Hans: 在此输入您的 API Key en_US: Enter your API Key -address: https://api.moonshot.cn \ No newline at end of file +address: https://api.moonshot.cn +recommend: true +sort: 6 \ No newline at end of file diff --git a/ai-provider/model-runtime/model-providers/nvidia/nvidia.yaml b/ai-provider/model-runtime/model-providers/nvidia/nvidia.yaml index e2fd93c7..c2038512 100644 --- a/ai-provider/model-runtime/model-providers/nvidia/nvidia.yaml +++ b/ai-provider/model-runtime/model-providers/nvidia/nvidia.yaml @@ -1,6 +1,6 @@ provider: nvidia label: - en_US: API Catalog + en_US: Nvidia description: en_US: API Catalog zh_Hans: API Catalog diff --git a/ai-provider/model-runtime/model-providers/openAI/openai.yaml b/ai-provider/model-runtime/model-providers/openAI/openai.yaml index 8b04aaef..475a8700 100644 --- a/ai-provider/model-runtime/model-providers/openAI/openai.yaml +++ b/ai-provider/model-runtime/model-providers/openAI/openai.yaml @@ -88,3 +88,5 @@ provider_credential_schema: zh_Hans: 在此输入您的 API Base, 如:https://api.openai.com en_US: Enter your API Base, e.g. https://api.openai.com address: https://api.openai.com +recommend: true +sort: 1 \ No newline at end of file diff --git a/ai-provider/model-runtime/model-providers/wenxin/wenxin.yaml b/ai-provider/model-runtime/model-providers/wenxin/wenxin.yaml index f4fde100..e429ea11 100644 --- a/ai-provider/model-runtime/model-providers/wenxin/wenxin.yaml +++ b/ai-provider/model-runtime/model-providers/wenxin/wenxin.yaml @@ -1,6 +1,6 @@ provider: wenxin label: - en_US: WenXin + en_US: Wenxin YiYan zh_Hans: 文心一言 icon_small: en_US: icon_s_en.svg @@ -38,4 +38,6 @@ provider_credential_schema: placeholder: zh_Hans: 在此输入您的 Secret Key en_US: Enter your Secret Key -address: https://aip.baidubce.com \ No newline at end of file +address: https://aip.baidubce.com +recommend: true +sort: 7 \ No newline at end of file diff --git a/ai-provider/model-runtime/model-providers/zhinao/assets/icon_l_en.svg b/ai-provider/model-runtime/model-providers/zhinao/assets/icon_l_en.svg index b22b8694..651a133f 100644 --- a/ai-provider/model-runtime/model-providers/zhinao/assets/icon_l_en.svg +++ b/ai-provider/model-runtime/model-providers/zhinao/assets/icon_l_en.svg @@ -1,8 +1,8 @@ - + - + diff --git a/ai-provider/model-runtime/model-providers/zhinao/assets/icon_s_en.svg b/ai-provider/model-runtime/model-providers/zhinao/assets/icon_s_en.svg index 8fe72b7d..2590f3d9 100644 --- a/ai-provider/model-runtime/model-providers/zhinao/assets/icon_s_en.svg +++ b/ai-provider/model-runtime/model-providers/zhinao/assets/icon_s_en.svg @@ -1,8 +1,8 @@ - + - + diff --git a/ai-provider/model-runtime/provider.go b/ai-provider/model-runtime/provider.go index 226719eb..666fc11f 100644 --- a/ai-provider/model-runtime/provider.go +++ b/ai-provider/model-runtime/provider.go @@ -22,6 +22,8 @@ type IProvider interface { ModelsByType(modelType string) ([]IModel, bool) IConfig MaskConfig(cfg string) string + Sort() int + Recommend() bool } type IProviderURI interface { @@ -72,6 +74,8 @@ func NewProvider(providerData string, modelContents map[string]eosc.Untyped[stri defaultModels: eosc.BuildUntyped[string, IModel](), modelsByType: eosc.BuildUntyped[string, []IModel](), maskKeys: make([]string, 0), + recommend: providerCfg.Recommend, + sort: providerCfg.Sort, uri: uri, } defaultCfg := make(map[string]string) @@ -126,9 +130,19 @@ type Provider struct { modelsByType eosc.Untyped[string, []IModel] maskKeys []string uri IProviderURI + sort int + recommend bool IConfig } +func (p *Provider) Sort() int { + return p.sort +} + +func (p *Provider) Recommend() bool { + return p.recommend +} + func (p *Provider) URI() IProviderURI { return p.uri } diff --git a/module/ai/dto/input.go b/module/ai/dto/input.go index 894bfd94..8f1b4c48 100644 --- a/module/ai/dto/input.go +++ b/module/ai/dto/input.go @@ -5,5 +5,6 @@ type UpdateLLM struct { } type UpdateConfig struct { - Config string `json:"config"` + DefaultLLM string `json:"default_llm"` + Config string `json:"config"` } diff --git a/module/ai/dto/output.go b/module/ai/dto/output.go index 9c37fcb5..c21f7ceb 100644 --- a/module/ai/dto/output.go +++ b/module/ai/dto/output.go @@ -7,7 +7,7 @@ type Provider struct { Name string `json:"name"` Config string `json:"config"` GetAPIKeyUrl string `json:"get_apikey_url"` - DefaultLLM string `json:"-"` + DefaultLLM string `json:"defaultLLM"` DefaultLLMConfig string `json:"-"` } @@ -18,6 +18,8 @@ type ProviderItem struct { DefaultLLMLogo string `json:"default_llm_logo"` Logo string `json:"logo"` Configured bool `json:"configured"` + Recommend bool `json:"recommend"` + Sort int `json:"sort"` UpdateTime time.Time `json:"-"` } diff --git a/module/ai/iml.go b/module/ai/iml.go index ba65e8e4..c1547850 100644 --- a/module/ai/iml.go +++ b/module/ai/iml.go @@ -90,9 +90,11 @@ func (i *imlProviderModule) Providers(ctx context.Context) ([]*ai_dto.ProviderIt continue } item := &ai_dto.ProviderItem{ - Id: v.ID(), - Name: v.Name(), - Logo: v.Logo(), + Id: v.ID(), + Name: v.Name(), + Logo: v.Logo(), + Recommend: v.Recommend(), + Sort: v.Sort(), } if info, has := providerMap[v.ID()]; has { item.Configured = true @@ -103,8 +105,19 @@ func (i *imlProviderModule) Providers(ctx context.Context) ([]*ai_dto.ProviderIt items = append(items, item) } sort.Slice(items, func(i, j int) bool { - - return items[i].UpdateTime.After(items[j].UpdateTime) + if items[i].Configured == items[j].Configured && items[i].Configured { + return items[i].Name < items[j].Name + } + if items[i].Sort != items[j].Sort { + if items[i].Sort == 0 { + return false + } + if items[j].Sort == 0 { + return true + } + return items[i].Sort < items[j].Sort + } + return items[i].Name < items[j].Name }) return items, nil } @@ -262,14 +275,14 @@ func (i *imlProviderModule) UpdateProviderConfig(ctx context.Context, id string, if !errors.Is(err, gorm.ErrRecordNotFound) { return err } - defaultLLm, ok := p.DefaultModel(model_runtime.ModelTypeLLM) - if !ok { - return fmt.Errorf("ai provider default llm not found") - } + //defaultLLm, ok := p.DefaultModel(model_runtime.ModelTypeLLM) + //if !ok { + // return fmt.Errorf("ai provider default llm not found") + //} info = &ai.Provider{ Id: id, Name: p.Name(), - DefaultLLM: defaultLLm.ID(), + DefaultLLM: input.DefaultLLM, Config: input.Config, } } diff --git a/module/service/dto/output.go b/module/service/dto/output.go index 55a5c1a0..74b3ac36 100644 --- a/module/service/dto/output.go +++ b/module/service/dto/output.go @@ -24,6 +24,7 @@ type AppItem struct { Team auto.Label `json:"team" aolabel:"team"` SubscribeNum int64 `json:"subscribe_num"` SubscribeVerifyNum int64 `json:"subscribe_verify_num"` + AuthNum int64 `json:"auth_num"` Description string `json:"description"` CreateTime auto.TimeLabel `json:"create_time"` UpdateTime auto.TimeLabel `json:"update_time"` diff --git a/module/service/iml.go b/module/service/iml.go index 075521f0..9f3325ba 100644 --- a/module/service/iml.go +++ b/module/service/iml.go @@ -7,6 +7,8 @@ import ( "sort" "strings" + application_authorization "github.com/APIParkLab/APIPark/service/application-authorization" + api_doc "github.com/APIParkLab/APIPark/service/api-doc" service_tag "github.com/APIParkLab/APIPark/service/service-tag" @@ -532,11 +534,12 @@ var ( ) type imlAppModule struct { - teamService team.ITeamService `autowired:""` - serviceService service.IServiceService `autowired:""` - teamMemberService team_member.ITeamMemberService `autowired:""` - subscribeService subscribe.ISubscribeService `autowired:""` - transaction store.ITransaction `autowired:""` + teamService team.ITeamService `autowired:""` + serviceService service.IServiceService `autowired:""` + teamMemberService team_member.ITeamMemberService `autowired:""` + subscribeService subscribe.ISubscribeService `autowired:""` + authService application_authorization.IAuthorizationService `autowired:""` + transaction store.ITransaction `autowired:""` } func (i *imlAppModule) ExportAll(ctx context.Context) ([]*service_dto.ExportApp, error) { @@ -600,6 +603,10 @@ func (i *imlAppModule) Search(ctx context.Context, teamId string, keyword string } } + appMap, err := i.authService.CountByApp(ctx, serviceIds...) + if err != nil { + return nil, err + } items := make([]*service_dto.AppItem, 0, len(services)) for _, model := range services { subscribeNum := subscribeCount[model.Id] @@ -614,6 +621,7 @@ func (i *imlAppModule) Search(ctx context.Context, teamId string, keyword string SubscribeNum: subscribeNum, SubscribeVerifyNum: verifyNum, CanDelete: subscribeNum == 0, + AuthNum: appMap[model.Id], }) } sort.Slice(items, func(i, j int) bool { diff --git a/service/application-authorization/iml.go b/service/application-authorization/iml.go index 97feab6f..c8b228b8 100644 --- a/service/application-authorization/iml.go +++ b/service/application-authorization/iml.go @@ -3,11 +3,11 @@ package application_authorization import ( "context" "time" - + "github.com/eolinker/go-common/utils" - + "github.com/eolinker/go-common/auto" - + "github.com/APIParkLab/APIPark/service/universally" "github.com/APIParkLab/APIPark/stores/service" ) @@ -24,6 +24,14 @@ type imlAuthorizationService struct { universally.IServiceEdit[Edit] } +func (i *imlAuthorizationService) CountByApp(ctx context.Context, appId ...string) (map[string]int64, error) { + w := map[string]interface{}{} + if len(appId) > 0 { + w["application"] = appId + } + return i.store.CountByGroup(ctx, "", w, "application") +} + func (i *imlAuthorizationService) ListByApp(ctx context.Context, appId ...string) ([]*Authorization, error) { w := map[string]interface{}{} if len(appId) > 0 { @@ -51,11 +59,11 @@ func (i *imlAuthorizationService) GetLabels(ctx context.Context, ids ...string) func (i *imlAuthorizationService) OnComplete() { i.IServiceGet = universally.NewGet[Authorization, service.Authorization](i.store, FromEntity) - + i.IServiceDelete = universally.NewDelete[service.Authorization](i.store) - + i.IServiceCreate = universally.NewCreator[Create, service.Authorization](i.store, "project_authorization", createEntityHandler, uniquestHandler, labelHandler) - + i.IServiceEdit = universally.NewEdit[Edit, service.Authorization](i.store, updateHandler, labelHandler) auto.RegisterService("project_authorization", i) } diff --git a/service/application-authorization/service.go b/service/application-authorization/service.go index cb355bb9..fd0f683f 100644 --- a/service/application-authorization/service.go +++ b/service/application-authorization/service.go @@ -3,7 +3,7 @@ package application_authorization import ( "context" "reflect" - + "github.com/APIParkLab/APIPark/service/universally" "github.com/eolinker/go-common/autowire" ) @@ -14,6 +14,7 @@ type IAuthorizationService interface { universally.IServiceCreate[Create] universally.IServiceEdit[Edit] ListByApp(ctx context.Context, appId ...string) ([]*Authorization, error) + CountByApp(ctx context.Context, appId ...string) (map[string]int64, error) } func init() { From 9d964b572bbadb6475e0999afe277ad161ef7e43 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Wed, 23 Oct 2024 16:42:56 +0800 Subject: [PATCH 22/23] upadte app list api --- module/service/iml.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/module/service/iml.go b/module/service/iml.go index 9f3325ba..04d478a1 100644 --- a/module/service/iml.go +++ b/module/service/iml.go @@ -603,7 +603,7 @@ func (i *imlAppModule) Search(ctx context.Context, teamId string, keyword string } } - appMap, err := i.authService.CountByApp(ctx, serviceIds...) + authMap, err := i.authService.CountByApp(ctx, serviceIds...) if err != nil { return nil, err } @@ -621,7 +621,7 @@ func (i *imlAppModule) Search(ctx context.Context, teamId string, keyword string SubscribeNum: subscribeNum, SubscribeVerifyNum: verifyNum, CanDelete: subscribeNum == 0, - AuthNum: appMap[model.Id], + AuthNum: authMap[model.Id], }) } sort.Slice(items, func(i, j int) bool { @@ -728,6 +728,10 @@ func (i *imlAppModule) SearchMyApps(ctx context.Context, teamId string, keyword if err != nil { return nil, err } + authMap, err := i.authService.CountByApp(ctx, serviceIds...) + if err != nil { + return nil, err + } subscribeCount := map[string]int64{} subscribeVerifyCount := map[string]int64{} @@ -764,6 +768,7 @@ func (i *imlAppModule) SearchMyApps(ctx context.Context, teamId string, keyword SubscribeNum: subscribeNum, SubscribeVerifyNum: verifyNum, CanDelete: subscribeNum == 0, + AuthNum: authMap[model.Id], }) } sort.Slice(items, func(i, j int) bool { From 888eabe15494e3b8b94aeafe60b88e74eeeb37b4 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Thu, 24 Oct 2024 23:30:25 +0800 Subject: [PATCH 23/23] finish fake ai --- .../fakegpt/assets/icon_l_en.svg | 23 +++++++++ .../fakegpt/assets/icon_s_en.svg | 23 +++++++++ .../model-providers/fakegpt/fakegpt.yaml | 30 +++++++++++ .../fakegpt/llm/fakegpt-1.0.yaml | 51 +++++++++++++++++++ .../vertex_ai/llm/gemini-1.0-pro-vision.yaml | 2 +- .../vertex_ai/llm/gemini-1.0-pro.yaml | 2 +- .../vertex_ai/llm/gemini-1.5-flash-001.yaml | 2 +- .../vertex_ai/llm/gemini-1.5-flash-002.yaml | 2 +- .../vertex_ai/llm/gemini-1.5-pro-001.yaml | 2 +- .../vertex_ai/llm/gemini-1.5-pro-002.yaml | 2 +- .../llm/gemini-flash-experimental.yaml | 2 +- .../llm/gemini-pro-experimental.yaml | 2 +- controller/system/iml.go | 8 +-- module/ai/iml.go | 6 ++- 14 files changed, 144 insertions(+), 13 deletions(-) create mode 100644 ai-provider/model-runtime/model-providers/fakegpt/assets/icon_l_en.svg create mode 100644 ai-provider/model-runtime/model-providers/fakegpt/assets/icon_s_en.svg create mode 100644 ai-provider/model-runtime/model-providers/fakegpt/fakegpt.yaml create mode 100644 ai-provider/model-runtime/model-providers/fakegpt/llm/fakegpt-1.0.yaml diff --git a/ai-provider/model-runtime/model-providers/fakegpt/assets/icon_l_en.svg b/ai-provider/model-runtime/model-providers/fakegpt/assets/icon_l_en.svg new file mode 100644 index 00000000..913864bf --- /dev/null +++ b/ai-provider/model-runtime/model-providers/fakegpt/assets/icon_l_en.svg @@ -0,0 +1,23 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ai-provider/model-runtime/model-providers/fakegpt/assets/icon_s_en.svg b/ai-provider/model-runtime/model-providers/fakegpt/assets/icon_s_en.svg new file mode 100644 index 00000000..913864bf --- /dev/null +++ b/ai-provider/model-runtime/model-providers/fakegpt/assets/icon_s_en.svg @@ -0,0 +1,23 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ai-provider/model-runtime/model-providers/fakegpt/fakegpt.yaml b/ai-provider/model-runtime/model-providers/fakegpt/fakegpt.yaml new file mode 100644 index 00000000..26bbd23d --- /dev/null +++ b/ai-provider/model-runtime/model-providers/fakegpt/fakegpt.yaml @@ -0,0 +1,30 @@ +provider: fakegpt +label: + en_US: FakeGPT +description: + en_US: FakeGPT is a fake model provider that does not actually connect to any model service. It is useful for testing and development purposes. +icon_small: + en_US: icon_s_en.svg +icon_large: + en_US: icon_l_en.svg +background: "#FCFDFF" +help: + title: + en_US: Get your Access Details from Google + url: + en_US: https://apipark.com +supported_model_types: + - llm + - text-embedding +configurate_methods: + - predefined-model +provider_credential_schema: + credential_form_schemas: + - variable: apikey + label: + en_US: API Key + type: secret-input + required: true + placeholder: + en_US: Enter your API key +address: https://apipark.com \ No newline at end of file diff --git a/ai-provider/model-runtime/model-providers/fakegpt/llm/fakegpt-1.0.yaml b/ai-provider/model-runtime/model-providers/fakegpt/llm/fakegpt-1.0.yaml new file mode 100644 index 00000000..ebee0690 --- /dev/null +++ b/ai-provider/model-runtime/model-providers/fakegpt/llm/fakegpt-1.0.yaml @@ -0,0 +1,51 @@ +model: fakegpt-1.0 +label: + en_US: FakeGPT 1.0 +model_type: llm +features: + - agent-thought + - vision +model_properties: + mode: chat + context_size: 200000 +parameter_rules: + - name: max_tokens + use_template: max_tokens + required: true + type: int + default: 4096 + min: 1 + max: 4096 + help: + zh_Hans: 停止前生成的最大令牌数。 + en_US: The maximum number of tokens to generate before stopping. + - name: temperature + use_template: temperature + required: false + type: float + default: 1 + min: 0.0 + max: 1.0 + help: + zh_Hans: 生成内容的随机性。 + en_US: The amount of randomness injected into the response. + - name: top_p + required: false + type: float + default: 0.999 + min: 0.000 + max: 1.000 + help: + zh_Hans: 在核采样中,按概率递减顺序计算每个后续标记的所有选项的累积分布,并在达到 top_p 指定的特定概率时将其切断。您应该更改温度或top_p,但不能同时更改两者。 + en_US: In nucleus sampling, computes the cumulative distribution over all the options for each subsequent token in decreasing probability order and cuts it off once it reaches a particular probability specified by top_p. You should alter either temperature or top_p, but not both. + - name: top_k + required: false + type: int + default: 0 + min: 0 + # tip docs from aws has error, max value is 500 + max: 500 + help: + zh_Hans: 对于每个后续标记,仅从前 K 个选项中进行采样。使用 top_k 删除长尾低概率响应。 + en_US: Only sample from the top K options for each subsequent token. Use top_k to remove long tail low probability responses. + diff --git a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.0-pro-vision.yaml b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.0-pro-vision.yaml index ebb276b8..4630f063 100644 --- a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.0-pro-vision.yaml +++ b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.0-pro-vision.yaml @@ -24,7 +24,7 @@ parameter_rules: use_template: presence_penalty - name: frequency_penalty use_template: frequency_penalty - - name: max_output_tokens + - name: max_tokens use_template: max_tokens required: true default: 2048 diff --git a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.0-pro.yaml b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.0-pro.yaml index c3259738..7a50d8c1 100644 --- a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.0-pro.yaml +++ b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.0-pro.yaml @@ -23,7 +23,7 @@ parameter_rules: use_template: presence_penalty - name: frequency_penalty use_template: frequency_penalty - - name: max_output_tokens + - name: max_tokens use_template: max_tokens required: true default: 8192 diff --git a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-flash-001.yaml b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-flash-001.yaml index f5386be0..1d9a0b0c 100644 --- a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-flash-001.yaml +++ b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-flash-001.yaml @@ -24,7 +24,7 @@ parameter_rules: use_template: presence_penalty - name: frequency_penalty use_template: frequency_penalty - - name: max_output_tokens + - name: max_tokens use_template: max_tokens required: true default: 8192 diff --git a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-flash-002.yaml b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-flash-002.yaml index 97bd44f0..066d4ba3 100644 --- a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-flash-002.yaml +++ b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-flash-002.yaml @@ -24,7 +24,7 @@ parameter_rules: use_template: presence_penalty - name: frequency_penalty use_template: frequency_penalty - - name: max_output_tokens + - name: max_tokens use_template: max_tokens required: true default: 8192 diff --git a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-pro-001.yaml b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-pro-001.yaml index 5e08f229..33d2c25a 100644 --- a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-pro-001.yaml +++ b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-pro-001.yaml @@ -24,7 +24,7 @@ parameter_rules: use_template: presence_penalty - name: frequency_penalty use_template: frequency_penalty - - name: max_output_tokens + - name: max_tokens use_template: max_tokens required: true default: 8192 diff --git a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-pro-002.yaml b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-pro-002.yaml index 8f327ea2..8b4c33cc 100644 --- a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-pro-002.yaml +++ b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-1.5-pro-002.yaml @@ -24,7 +24,7 @@ parameter_rules: use_template: presence_penalty - name: frequency_penalty use_template: frequency_penalty - - name: max_output_tokens + - name: max_tokens use_template: max_tokens required: true default: 8192 diff --git a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-flash-experimental.yaml b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-flash-experimental.yaml index 0f5eb34c..ef340372 100644 --- a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-flash-experimental.yaml +++ b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-flash-experimental.yaml @@ -24,7 +24,7 @@ parameter_rules: use_template: presence_penalty - name: frequency_penalty use_template: frequency_penalty - - name: max_output_tokens + - name: max_tokens use_template: max_tokens required: true default: 8192 diff --git a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-pro-experimental.yaml b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-pro-experimental.yaml index fa31cabb..cff10423 100644 --- a/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-pro-experimental.yaml +++ b/ai-provider/model-runtime/model-providers/vertex_ai/llm/gemini-pro-experimental.yaml @@ -24,7 +24,7 @@ parameter_rules: use_template: presence_penalty - name: frequency_penalty use_template: frequency_penalty - - name: max_output_tokens + - name: max_tokens use_template: max_tokens required: true default: 8192 diff --git a/controller/system/iml.go b/controller/system/iml.go index 3739419e..b05cac3c 100644 --- a/controller/system/iml.go +++ b/controller/system/iml.go @@ -319,12 +319,12 @@ func (i *imlInitController) OnInit() { } func (i *imlInitController) createAIService(ctx context.Context, teamID string, input *service_dto.CreateService) error { - providerId := "openai" - err := i.providerModule.UpdateProviderConfig(ctx, "openai", &ai_dto.UpdateConfig{ - Config: "{\n \"openai_api_base\": \"API Base\",\n \"openai_api_key\": \"API Key\",\n \"openai_organization\": \"Organization\"\n}", + providerId := "fakegpt" + err := i.providerModule.UpdateProviderConfig(ctx, providerId, &ai_dto.UpdateConfig{ + Config: "{\n \"apikey\": \"xxx\" \n}", }) if err != nil { - return fmt.Errorf("update openai config error: %v", err) + return fmt.Errorf("update %s config error: %v", providerId, err) } input.Provider = &providerId if input.Id == "" { diff --git a/module/ai/iml.go b/module/ai/iml.go index c1547850..65d17cc5 100644 --- a/module/ai/iml.go +++ b/module/ai/iml.go @@ -147,7 +147,11 @@ func (i *imlProviderModule) Provider(ctx context.Context, id string) (*ai_dto.Pr } defaultLLM, has := p.GetModel(info.DefaultLLM) if !has { - return nil, fmt.Errorf("ai provider llm not found") + model, has := p.DefaultModel(model_runtime.ModelTypeLLM) + if !has { + return nil, fmt.Errorf("ai provider llm not found") + } + defaultLLM = model } return &ai_dto.Provider{ Id: info.Id,