Skip to content

Commit b99c83c

Browse files
authored
feat: add ai plugin tempate (#2245)
1 parent 7fdc37a commit b99c83c

5 files changed

Lines changed: 73 additions & 11 deletions

File tree

apiserver/Dockerfile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ RUN EDITION=${EDITION} npm run build
2525
FROM python:3.11.10-slim-bullseye
2626
USER root
2727

28-
RUN apt-get update && apt-get install -y gcc subversion ssh default-libmysqlclient-dev pkg-config vim git
28+
RUN apt-get update && apt-get install -y gcc subversion ssh default-libmysqlclient-dev pkg-config vim git gettext
2929

3030
RUN mkdir ~/.pip && printf '[global]\nindex-url = https://mirrors.cloud.tencent.com/pypi/simple/\n' > ~/.pip/pip.conf
3131

@@ -56,11 +56,6 @@ RUN mkdir -p ./public
5656
COPY --from=admin42 /build/paasng/public ./public
5757
ADD ./paasng .
5858

59-
# Add extra files: static assets & I18N .mo translation file.
60-
61-
# "gettext" package is required for running "compilemessages"
62-
RUN apt-get install -y gettext
63-
6459
# the "BKKRILL_ENCRYPT_SECRET_KEY" settings is required for starting the project,
6560
# set it to a non-empty value to run the manage.py command.
6661
RUN export PAAS_BKKRILL_ENCRYPT_SECRET_KEY='none' && \

apiserver/paasng/fixtures/template.yaml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
required_buildpacks: []
109109
processes: {}
110110
tags: []
111-
repo_url: ''
111+
repo_url: 'https://github.com/TencentBlueKing/bk-plugin-framework-python'
112112
runtime_type: buildpack
113113
- model: templates.template
114114
pk: 6
@@ -149,12 +149,11 @@
149149
preset_services_config:
150150
mysql: {}
151151
blob_url: {}
152-
enabled_regions:
153-
- default
152+
enabled_regions: []
154153
required_buildpacks: []
155154
processes: {}
156155
tags: []
157-
repo_url: ''
156+
repo_url: 'https://github.com/TencentBlueKing/bk-apigateway-framework'
158157
- model: templates.template
159158
pk: 8
160159
fields:
@@ -171,9 +170,30 @@
171170
preset_services_config:
172171
mysql: {}
173172
blob_url: {}
173+
enabled_regions: []
174+
required_buildpacks: []
175+
processes: {}
176+
tags: []
177+
repo_url: 'https://github.com/TencentBlueKing/bk-apigateway-framework'
178+
- model: templates.template
179+
pk: 9
180+
fields:
181+
created: !!timestamp '2023-12-26 12:00:00.000000+00:00'
182+
updated: !!timestamp '2023-12-26 12:00:00.000000+00:00'
183+
name: bk-ai-plugin-python
184+
type: 'plugin'
185+
display_name_zh_cn: AI 智能体插件(Python)
186+
display_name_en: AI Agent Plugin (Python)
187+
description_zh_cn: 为开发者提供快速创建 AIDev 智能体的能力,并自动对接 AI 小鲸、API 网关
188+
description_en: Enables developers to quickly create AIDev agents with automatic integration to AI Xiaojing (AI Assistant) and API Gateway.
189+
language: Python
190+
market_ready: False
191+
preset_services_config:
192+
mysql: {}
193+
blob_url: {}
174194
enabled_regions:
175195
- default
176196
required_buildpacks: []
177197
processes: {}
178198
tags: []
179-
repo_url: ''
199+
repo_url: 'https://github.com/TencentBlueKing/bk-aidev-agent'

apiserver/paasng/paasng/platform/modules/urls.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@
8888
views.ModuleDeployConfigViewSet.as_view({"post": "update_procfile"}),
8989
name="api.modules.deploy_config.procfile.update",
9090
),
91+
# 获取应用模块的初始化模板信息
92+
re_path(
93+
r"^api/bkapps/applications/(?P<code>[^/]+)/modules/(?P<module_name>[^/]+)/template/$",
94+
views.ModuleTemplateViewSet.as_view({"get": "retrieve"}),
95+
name="api.modules.template",
96+
),
9197
]
9298

9399
# Multi-editions specific start

apiserver/paasng/paasng/platform/modules/views.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
from paasng.platform.modules.specs import ModuleSpecs
8484
from paasng.platform.templates.constants import TemplateType
8585
from paasng.platform.templates.models import Template
86+
from paasng.platform.templates.serializers import TemplateRenderOutputSLZ
8687
from paasng.utils.api_docs import openapi_empty_response
8788
from paasng.utils.error_codes import error_codes
8889

@@ -627,3 +628,17 @@ def update_procfile(self, request, *args, **kwargs):
627628
}
628629
).data
629630
)
631+
632+
633+
class ModuleTemplateViewSet(viewsets.ViewSet, ApplicationCodeInPathMixin):
634+
permission_classes = [IsAuthenticated, application_perm_class(AppAction.VIEW_BASIC_INFO)]
635+
636+
@swagger_auto_schema(response_serializer=TemplateRenderOutputSLZ)
637+
def retrieve(self, request, code, module_name):
638+
"""获取当前模块的初始化模板信息"""
639+
module = self.get_module_via_path()
640+
641+
# 可能存在远古模版,并不在当前模版配置中
642+
template = get_object_or_404(Template, name=module.source_init_template)
643+
644+
return Response(TemplateRenderOutputSLZ(template).data)

apiserver/paasng/paasng/platform/templates/serializers.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
ImageTagOptionsSLZ,
2424
RuntimeType,
2525
)
26+
from paasng.platform.templates.constants import TemplateType
2627
from paasng.utils.i18n.serializers import TranslatedCharField
2728

2829

@@ -75,3 +76,28 @@ class TemplateDetailSLZ(serializers.Serializer):
7576

7677
slugbuilder = AppSlugBuilderMinimalSLZ(help_text="基础镜像详细信息")
7778
build_config = BuildConfigPreviewSLZ()
79+
80+
81+
class TemplateRenderOutputSLZ(serializers.Serializer):
82+
"""模板渲染信息"""
83+
84+
name = serializers.CharField(help_text="模板名称")
85+
display_name = TranslatedCharField()
86+
description = TranslatedCharField()
87+
repo_url = serializers.CharField(help_text="代码仓库地址")
88+
render_method = serializers.SerializerMethodField(help_text="模版代码渲染方式")
89+
source_dir = serializers.SerializerMethodField(help_text="模板代码所在相对目录")
90+
91+
def get_render_method(self, tmpl):
92+
"""Note: release1.7 版本已经在 Template 表中添加 render_method 字段,release1.7 之前的版本根据插件类型来判断"""
93+
if tmpl.type == TemplateType.PLUGIN:
94+
return "cookiecutter"
95+
else:
96+
return "django_template"
97+
98+
def get_source_dir(self, tmpl):
99+
"""Note: release1.7 版本已经在 Template 表中添加 source_dir 字段,release1.7 之前的版本根据插件类型来判断"""
100+
if tmpl.type == TemplateType.PLUGIN:
101+
return "template"
102+
else:
103+
return ""

0 commit comments

Comments
 (0)