django-bkvision-sdk 1.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_bkvision_sdk-1.2.4/LICENSE +21 -0
- django_bkvision_sdk-1.2.4/PKG-INFO +94 -0
- django_bkvision_sdk-1.2.4/README.md +65 -0
- django_bkvision_sdk-1.2.4/django_bkvision/__init__.py +1 -0
- django_bkvision_sdk-1.2.4/django_bkvision/admin.py +3 -0
- django_bkvision_sdk-1.2.4/django_bkvision/apps.py +6 -0
- django_bkvision_sdk-1.2.4/django_bkvision/migrations/__init__.py +0 -0
- django_bkvision_sdk-1.2.4/django_bkvision/models.py +3 -0
- django_bkvision_sdk-1.2.4/django_bkvision/settings.py +19 -0
- django_bkvision_sdk-1.2.4/django_bkvision/tests.py +3 -0
- django_bkvision_sdk-1.2.4/django_bkvision/urls.py +29 -0
- django_bkvision_sdk-1.2.4/django_bkvision/utils.py +41 -0
- django_bkvision_sdk-1.2.4/django_bkvision/views.py +308 -0
- django_bkvision_sdk-1.2.4/pyproject.toml +38 -0
- django_bkvision_sdk-1.2.4/setup.py +30 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-2026 Tencent BlueKing
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: django-bkvision-sdk
|
|
3
|
+
Version: 1.2.4
|
|
4
|
+
Summary: bkvision's python sdk of django for dashboard embed scene
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: django,bkvision
|
|
7
|
+
Author: Tencent BlueKing
|
|
8
|
+
Author-email: blueking@tencent.com
|
|
9
|
+
Requires-Python: >=3.8,<4.0
|
|
10
|
+
Classifier: Framework :: Django
|
|
11
|
+
Classifier: Framework :: Django :: 2.0
|
|
12
|
+
Classifier: Framework :: Django :: 2.2
|
|
13
|
+
Classifier: Framework :: Django :: 3.2
|
|
14
|
+
Classifier: Framework :: Django :: 4.0
|
|
15
|
+
Classifier: Framework :: Django :: 4.2
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Requires-Dist: Django (>=2.0,<5.0)
|
|
25
|
+
Requires-Dist: blueapps (>=4.0,<5.0)
|
|
26
|
+
Requires-Dist: requests (>=2.20)
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
## 一、快速安装
|
|
30
|
+
|
|
31
|
+
1. 从官方 PyPI 安装
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install django-bkvision-sdk
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
> 发行名为 `django-bkvision-sdk`,import 包名是 `django_bkvision`。
|
|
38
|
+
|
|
39
|
+
2. 添加 `django_bkvision` 到 `INSTALLED_APPS`
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
INSTALLED_APPS = (
|
|
43
|
+
# ...
|
|
44
|
+
'django.contrib.auth',
|
|
45
|
+
'django_bkvision',
|
|
46
|
+
# ...
|
|
47
|
+
)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
3. 添加路由到 `urls.py`
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from django.urls import include, path
|
|
54
|
+
|
|
55
|
+
urlpatterns = [
|
|
56
|
+
path('bkvision/', include('django_bkvision.urls')),
|
|
57
|
+
]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 二、必填配置
|
|
61
|
+
|
|
62
|
+
`BKAPP_BKVISION_APIGW_URL` 是上游 API 网关地址,**必须显式配置**,包内不提供默认地址。
|
|
63
|
+
|
|
64
|
+
方式一,在 `settings.py` 中配置:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
BKAPP_BKVISION_APIGW_URL = 'https://bkvision.example.com/prod'
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
方式二,通过环境变量注入:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
export BKAPP_BKVISION_APIGW_URL=https://bkvision.example.com/prod
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
示例地址是占位,请替换成自己的网关地址。
|
|
77
|
+
|
|
78
|
+
## 三、运行环境与前置条件
|
|
79
|
+
|
|
80
|
+
- Python >= 3.8,Django >= 2.0 且 < 5.0。
|
|
81
|
+
- 依赖 `Django`、`requests`、`blueapps` 会在安装时自动解析。
|
|
82
|
+
- 本包把请求转发到蓝鲸 API 网关并使用网关鉴权,接入方需具备蓝鲸 PaaS 侧的 `APP_CODE` / `SECRET_KEY` 以及 `blueapps` 框架。
|
|
83
|
+
|
|
84
|
+
## 四、可选配置
|
|
85
|
+
|
|
86
|
+
在 `settings.py` 中提供转发前的预处理钩子:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
def my_before_proxy_func(request):
|
|
90
|
+
return request
|
|
91
|
+
|
|
92
|
+
PRE_PROCESS_FUNC = my_before_proxy_func
|
|
93
|
+
```
|
|
94
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
## 一、快速安装
|
|
2
|
+
|
|
3
|
+
1. 从官方 PyPI 安装
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install django-bkvision-sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
> 发行名为 `django-bkvision-sdk`,import 包名是 `django_bkvision`。
|
|
10
|
+
|
|
11
|
+
2. 添加 `django_bkvision` 到 `INSTALLED_APPS`
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
INSTALLED_APPS = (
|
|
15
|
+
# ...
|
|
16
|
+
'django.contrib.auth',
|
|
17
|
+
'django_bkvision',
|
|
18
|
+
# ...
|
|
19
|
+
)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
3. 添加路由到 `urls.py`
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from django.urls import include, path
|
|
26
|
+
|
|
27
|
+
urlpatterns = [
|
|
28
|
+
path('bkvision/', include('django_bkvision.urls')),
|
|
29
|
+
]
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 二、必填配置
|
|
33
|
+
|
|
34
|
+
`BKAPP_BKVISION_APIGW_URL` 是上游 API 网关地址,**必须显式配置**,包内不提供默认地址。
|
|
35
|
+
|
|
36
|
+
方式一,在 `settings.py` 中配置:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
BKAPP_BKVISION_APIGW_URL = 'https://bkvision.example.com/prod'
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
方式二,通过环境变量注入:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
export BKAPP_BKVISION_APIGW_URL=https://bkvision.example.com/prod
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
示例地址是占位,请替换成自己的网关地址。
|
|
49
|
+
|
|
50
|
+
## 三、运行环境与前置条件
|
|
51
|
+
|
|
52
|
+
- Python >= 3.8,Django >= 2.0 且 < 5.0。
|
|
53
|
+
- 依赖 `Django`、`requests`、`blueapps` 会在安装时自动解析。
|
|
54
|
+
- 本包把请求转发到蓝鲸 API 网关并使用网关鉴权,接入方需具备蓝鲸 PaaS 侧的 `APP_CODE` / `SECRET_KEY` 以及 `blueapps` 框架。
|
|
55
|
+
|
|
56
|
+
## 四、可选配置
|
|
57
|
+
|
|
58
|
+
在 `settings.py` 中提供转发前的预处理钩子:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
def my_before_proxy_func(request):
|
|
62
|
+
return request
|
|
63
|
+
|
|
64
|
+
PRE_PROCESS_FUNC = my_before_proxy_func
|
|
65
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '1.2.4'
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from django.conf import settings as django_settings
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def default_before_proxy_func(request):
|
|
8
|
+
"""预留钩子,可修改转发接口的header和body"""
|
|
9
|
+
return request
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# 统一转发前缀
|
|
13
|
+
PREFIX_BKVISION = getattr(django_settings, "PREFIX_BKVISION", "bkvision")
|
|
14
|
+
|
|
15
|
+
# AJAX接口转发前的
|
|
16
|
+
PRE_PROCESS_FUNC = getattr(django_settings, "PRE_PROCESS_FUNC", default_before_proxy_func)
|
|
17
|
+
|
|
18
|
+
# 上游地址由接入方显式配置,不提供内置默认值
|
|
19
|
+
BKVISION_APIGW_URL = getattr(django_settings, "BKAPP_BKVISION_APIGW_URL", "") or os.environ.get("BKAPP_BKVISION_APIGW_URL", "")
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from django.urls import re_path
|
|
4
|
+
|
|
5
|
+
from . import views
|
|
6
|
+
|
|
7
|
+
urlpatterns = (
|
|
8
|
+
re_path(r'^api/v1/datasource/query/$', views.query_datasource),
|
|
9
|
+
re_path(r'^api/v1/dataset/query/$', views.query_dataset),
|
|
10
|
+
re_path(r'^api/v1/field/(?P<uid>\w+)/preview_data/$', views.preview_field_data),
|
|
11
|
+
re_path(r'^api/v1/meta/query/$', views.query_meta),
|
|
12
|
+
re_path(r'^api/v1/variable/query/$', views.query_variable),
|
|
13
|
+
re_path(r'^api/v1/variable/test/$', views.test_variable),
|
|
14
|
+
re_path(r'^api/v1/panel/$', views.get_panel),
|
|
15
|
+
re_path(r'^api/v1/panel/get_child_panels/$', views.get_child_panels),
|
|
16
|
+
re_path(r'^bkcdn/(?P<path>.*)', views.proxy_bkcdn),
|
|
17
|
+
re_path(r'^api/v1/ai/session/batch_delete/$', views.batch_delete_session),
|
|
18
|
+
re_path(r'^api/v1/ai/session/(?P<session_code>[\w-]+)/ai_rename/$', views.rename_session),
|
|
19
|
+
re_path(r'^api/v1/ai/session/(?P<session_code>[\w-]+)/$', views.session_instance_handler),
|
|
20
|
+
re_path(r'^api/v1/ai/session/$', views.session_handler),
|
|
21
|
+
re_path(r'^api/v1/ai/session_content/content/$', views.get_session_content),
|
|
22
|
+
re_path(r'^api/v1/ai/session_content/batch_delete/$', views.batch_delete_session_content),
|
|
23
|
+
re_path(r'^api/v1/ai/session_content/(?P<content_id>\w+)/$', views.session_content_instance_handler),
|
|
24
|
+
re_path(r'^api/v1/ai/session_content/$', views.create_session_content),
|
|
25
|
+
re_path(r'^api/v1/ai/chat_completion/$', views.create_chat_completion),
|
|
26
|
+
re_path(r'^api/v1/ai/agent/info/$', views.get_agent_info),
|
|
27
|
+
re_path(r'^api/v1/linked_view/(?P<uid>\w+)/$', views.get_linked_view_info),
|
|
28
|
+
re_path(r'^api/v1/watermark/effective/$', views.get_effective_watermark),
|
|
29
|
+
)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
#: List containing string constant that are used to represent headers that can
|
|
4
|
+
#: be ignored in the required_header function
|
|
5
|
+
IGNORE_HEADERS = (
|
|
6
|
+
"HTTP_ACCEPT_ENCODING", # We want content to be uncompressed so
|
|
7
|
+
# we remove the Accept-Encoding from
|
|
8
|
+
# original request
|
|
9
|
+
"HTTP_HOST",
|
|
10
|
+
"HTTP_REMOTE_USER",
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def required_header(header):
|
|
15
|
+
"""Function that verify if the header parameter is a essential header
|
|
16
|
+
|
|
17
|
+
:param header: A string represented a header
|
|
18
|
+
:returns: A boolean value that represent if the header is required
|
|
19
|
+
"""
|
|
20
|
+
if header in IGNORE_HEADERS:
|
|
21
|
+
return False
|
|
22
|
+
|
|
23
|
+
if header.startswith("HTTP_") or header == "CONTENT_TYPE":
|
|
24
|
+
return True
|
|
25
|
+
|
|
26
|
+
return False
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def normalize_request_headers(request):
|
|
30
|
+
"""Function used to transform header, replacing 'HTTP_' to ''
|
|
31
|
+
and replace '_' to '-'
|
|
32
|
+
:param request: A HttpRequest that will be transformed
|
|
33
|
+
:returns: A dictionary with the normalized headers
|
|
34
|
+
"""
|
|
35
|
+
norm_headers = {}
|
|
36
|
+
for header, value in request.META.items():
|
|
37
|
+
if required_header(header):
|
|
38
|
+
norm_header = header.replace("HTTP_", "").title().replace("_", "-")
|
|
39
|
+
norm_headers[norm_header] = value
|
|
40
|
+
|
|
41
|
+
return norm_headers
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
# -*- coding:utf-8 -*-
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
import requests
|
|
5
|
+
from blueapps.account.decorators import login_exempt
|
|
6
|
+
from django.conf import settings
|
|
7
|
+
from django.http import JsonResponse, HttpResponse
|
|
8
|
+
from django.views.decorators.csrf import csrf_exempt
|
|
9
|
+
from django.views.decorators.http import require_http_methods
|
|
10
|
+
|
|
11
|
+
from django_bkvision.settings import PRE_PROCESS_FUNC, BKVISION_APIGW_URL
|
|
12
|
+
from django_bkvision.utils import normalize_request_headers
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def build_headers(request):
|
|
16
|
+
request_headers = normalize_request_headers(request)
|
|
17
|
+
request_headers.update({
|
|
18
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
19
|
+
"X-Bkapi-Authorization": json.dumps({
|
|
20
|
+
"bk_app_code": settings.APP_CODE,
|
|
21
|
+
"bk_app_secret": settings.SECRET_KEY,
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
return request_headers
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def proxy_request(request, path):
|
|
28
|
+
headers = build_headers(request)
|
|
29
|
+
params = request.GET.copy()
|
|
30
|
+
proxy_response = requests.request(
|
|
31
|
+
method=request.method,
|
|
32
|
+
url=f"{BKVISION_APIGW_URL}{path}",
|
|
33
|
+
params=params,
|
|
34
|
+
data=request.body,
|
|
35
|
+
headers=headers,
|
|
36
|
+
verify=False
|
|
37
|
+
)
|
|
38
|
+
return HttpResponse(
|
|
39
|
+
proxy_response.content,
|
|
40
|
+
status=proxy_response.status_code,
|
|
41
|
+
content_type=proxy_response.headers.get('Content-Type')
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@login_exempt
|
|
46
|
+
@csrf_exempt
|
|
47
|
+
@require_http_methods(["POST"])
|
|
48
|
+
def query_variable(request):
|
|
49
|
+
"""获取变量数据"""
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
return proxy_request(request, '/api/v1/variable/query/')
|
|
53
|
+
except Exception as e:
|
|
54
|
+
return JsonResponse({"result": False, "message": "query_variable exception: {}".format(e), "code": 400})
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@login_exempt
|
|
58
|
+
@csrf_exempt
|
|
59
|
+
@require_http_methods(["POST"])
|
|
60
|
+
def test_variable(request):
|
|
61
|
+
"""测试变量数据"""
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
return proxy_request(request, '/api/v1/variable/test/')
|
|
65
|
+
except Exception as e:
|
|
66
|
+
return JsonResponse({"result": False, "message": "query_variable exception: {}".format(e), "code": 400})
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@login_exempt
|
|
70
|
+
@csrf_exempt
|
|
71
|
+
@require_http_methods(["POST"])
|
|
72
|
+
def preview_field_data(request, uid):
|
|
73
|
+
"""获取字段数据"""
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
return proxy_request(request, f'/api/v1/field/{uid}/preview_data/')
|
|
77
|
+
except Exception as e:
|
|
78
|
+
return JsonResponse({"result": False, "message": "query_variable exception: {}".format(e), "code": 400})
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@login_exempt
|
|
82
|
+
@csrf_exempt
|
|
83
|
+
@require_http_methods(["POST"])
|
|
84
|
+
def query_datasource(request):
|
|
85
|
+
"""查询数据源数据"""
|
|
86
|
+
|
|
87
|
+
try:
|
|
88
|
+
# 转发前的预处理hook
|
|
89
|
+
request = PRE_PROCESS_FUNC(request)
|
|
90
|
+
return proxy_request(request, '/api/v1/datasource/query/')
|
|
91
|
+
except Exception as e:
|
|
92
|
+
return JsonResponse({"result": False, "message": "query_datasource exception: {}".format(e), "code": 400})
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@login_exempt
|
|
96
|
+
@csrf_exempt
|
|
97
|
+
@require_http_methods(["POST"])
|
|
98
|
+
def query_dataset(request):
|
|
99
|
+
"""查询数据集数据"""
|
|
100
|
+
|
|
101
|
+
try:
|
|
102
|
+
# 转发前的预处理hook
|
|
103
|
+
request = PRE_PROCESS_FUNC(request)
|
|
104
|
+
return proxy_request(request, '/api/v1/dataset/query/')
|
|
105
|
+
except Exception as e:
|
|
106
|
+
return JsonResponse({"result": False, "message": "query_dataset exception: {}".format(e), "code": 400})
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@login_exempt
|
|
110
|
+
@require_http_methods(["GET"])
|
|
111
|
+
def query_meta(request):
|
|
112
|
+
"""
|
|
113
|
+
获取配置
|
|
114
|
+
curl -X GET -H 'content-type: application/json' \
|
|
115
|
+
'http://127.0.0.1:8001/bkvision/api/v1/meta/query/?share_uid=<share_uid>'
|
|
116
|
+
"""
|
|
117
|
+
try:
|
|
118
|
+
return proxy_request(request, '/api/v1/meta/query/')
|
|
119
|
+
except Exception as e:
|
|
120
|
+
return JsonResponse({"result": False, "message": "query_meta exception: {}".format(e), "code": 400})
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@login_exempt
|
|
124
|
+
@csrf_exempt
|
|
125
|
+
@require_http_methods(["GET"])
|
|
126
|
+
def get_panel(request):
|
|
127
|
+
"""获取图表配置"""
|
|
128
|
+
|
|
129
|
+
try:
|
|
130
|
+
return proxy_request(request, '/api/v1/panel/')
|
|
131
|
+
except Exception as e:
|
|
132
|
+
return JsonResponse({"result": False, "message": "get_panel exception: {}".format(e), "code": 400})
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@login_exempt
|
|
136
|
+
@csrf_exempt
|
|
137
|
+
@require_http_methods(["GET"])
|
|
138
|
+
def get_child_panels(request):
|
|
139
|
+
"""获取子图列表"""
|
|
140
|
+
|
|
141
|
+
try:
|
|
142
|
+
return proxy_request(request, '/api/v1/panel/get_child_panels/')
|
|
143
|
+
except Exception as e:
|
|
144
|
+
return JsonResponse({"result": False, "message": "get_child_panels exception: {}".format(e), "code": 400})
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
@login_exempt
|
|
148
|
+
@csrf_exempt
|
|
149
|
+
@require_http_methods(["GET"])
|
|
150
|
+
def proxy_bkcdn(request, path):
|
|
151
|
+
"""转发bkcdn"""
|
|
152
|
+
|
|
153
|
+
try:
|
|
154
|
+
return proxy_request(request, f'/bkcdn/{path}')
|
|
155
|
+
except Exception as e:
|
|
156
|
+
return JsonResponse({"result": False, "message": "proxy_bkcdn exception: {}".format(e), "code": 400})
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
@login_exempt
|
|
160
|
+
@csrf_exempt
|
|
161
|
+
@require_http_methods(["GET", "POST"])
|
|
162
|
+
def session_handler(request):
|
|
163
|
+
"""会话请求处理"""
|
|
164
|
+
try:
|
|
165
|
+
return proxy_request(request, '/api/v1/ai/session/')
|
|
166
|
+
except Exception as e:
|
|
167
|
+
if request.method == "POST":
|
|
168
|
+
return JsonResponse({"result": False, "message": "create_session exception: {}".format(e), "code": 400})
|
|
169
|
+
else:
|
|
170
|
+
return JsonResponse({"result": False, "message": "get_session_list exception: {}".format(e), "code": 400})
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
@login_exempt
|
|
174
|
+
@csrf_exempt
|
|
175
|
+
@require_http_methods(["PUT", "GET", "DELETE"])
|
|
176
|
+
def session_instance_handler(request, session_code):
|
|
177
|
+
"""会话实例请求处理"""
|
|
178
|
+
try:
|
|
179
|
+
return proxy_request(request, f'/api/v1/ai/session/{session_code}/')
|
|
180
|
+
except Exception as e:
|
|
181
|
+
if request.method == "PUT":
|
|
182
|
+
return JsonResponse({"result": False, "message": "update_session exception: {}".format(e), "code": 400})
|
|
183
|
+
elif request.method == "GET":
|
|
184
|
+
return JsonResponse({"result": False, "message": "get_session exception: {}".format(e), "code": 400})
|
|
185
|
+
else:
|
|
186
|
+
return JsonResponse({"result": False, "message": "delete_session exception: {}".format(e), "code": 400})
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@login_exempt
|
|
190
|
+
@csrf_exempt
|
|
191
|
+
@require_http_methods(["POST"])
|
|
192
|
+
def batch_delete_session(request):
|
|
193
|
+
"""批量删除会话"""
|
|
194
|
+
|
|
195
|
+
try:
|
|
196
|
+
return proxy_request(request, '/api/v1/ai/session/batch_delete/')
|
|
197
|
+
except Exception as e:
|
|
198
|
+
return JsonResponse({"result": False, "message": "batch_delete_session exception: {}".format(e), "code": 400})
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
@login_exempt
|
|
202
|
+
@csrf_exempt
|
|
203
|
+
@require_http_methods(["POST"])
|
|
204
|
+
def rename_session(request, session_code):
|
|
205
|
+
"""重命名会话"""
|
|
206
|
+
|
|
207
|
+
try:
|
|
208
|
+
return proxy_request(request, f'/api/v1/ai/session/{session_code}/ai_rename/')
|
|
209
|
+
except Exception as e:
|
|
210
|
+
return JsonResponse({"result": False, "message": "rename_session exception: {}".format(e), "code": 400})
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
@login_exempt
|
|
214
|
+
@csrf_exempt
|
|
215
|
+
@require_http_methods(["PUT", "DELETE"])
|
|
216
|
+
def session_content_instance_handler(request, content_id):
|
|
217
|
+
try:
|
|
218
|
+
return proxy_request(request, f'/api/v1/ai/session_content/{content_id}/')
|
|
219
|
+
except Exception as e:
|
|
220
|
+
if request.method == "PUT":
|
|
221
|
+
return JsonResponse(
|
|
222
|
+
{"result": False, "message": "update_session_content exception: {}".format(e), "code": 400})
|
|
223
|
+
else:
|
|
224
|
+
return JsonResponse({"result": False, "message": "delete_session_content exception: {}".format(e), "code": 400})
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
@login_exempt
|
|
228
|
+
@csrf_exempt
|
|
229
|
+
@require_http_methods(["POST"])
|
|
230
|
+
def create_session_content(request):
|
|
231
|
+
"""创建会话内容"""
|
|
232
|
+
|
|
233
|
+
try:
|
|
234
|
+
return proxy_request(request, '/api/v1/ai/session_content/')
|
|
235
|
+
except Exception as e:
|
|
236
|
+
return JsonResponse({"result": False, "message": "create_session_content exception: {}".format(e), "code": 400})
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
@login_exempt
|
|
240
|
+
@csrf_exempt
|
|
241
|
+
@require_http_methods(["GET"])
|
|
242
|
+
def get_session_content(request):
|
|
243
|
+
"""获取会话内容"""
|
|
244
|
+
|
|
245
|
+
try:
|
|
246
|
+
return proxy_request(request, '/api/v1/ai/session_content/content/')
|
|
247
|
+
except Exception as e:
|
|
248
|
+
return JsonResponse({"result": False, "message": "get_session_content exception: {}".format(e), "code": 400})
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
@login_exempt
|
|
252
|
+
@csrf_exempt
|
|
253
|
+
@require_http_methods(["POST"])
|
|
254
|
+
def batch_delete_session_content(request):
|
|
255
|
+
"""批量删除会话内容"""
|
|
256
|
+
|
|
257
|
+
try:
|
|
258
|
+
return proxy_request(request, '/api/v1/ai/session_content/batch_delete/')
|
|
259
|
+
except Exception as e:
|
|
260
|
+
return JsonResponse({"result": False, "message": "batch_delete_session_content exception: {}".format(e), "code": 400})
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
@login_exempt
|
|
264
|
+
@csrf_exempt
|
|
265
|
+
@require_http_methods(["POST"])
|
|
266
|
+
def create_chat_completion(request):
|
|
267
|
+
"""创建聊天结束"""
|
|
268
|
+
|
|
269
|
+
try:
|
|
270
|
+
return proxy_request(request, '/api/v1/ai/chat_completion/')
|
|
271
|
+
except Exception as e:
|
|
272
|
+
return JsonResponse({"result": False, "message": "create_chat_completion exception: {}".format(e), "code": 400})
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
@login_exempt
|
|
276
|
+
@csrf_exempt
|
|
277
|
+
@require_http_methods(["GET"])
|
|
278
|
+
def get_agent_info(request):
|
|
279
|
+
"""获取智能体信息"""
|
|
280
|
+
|
|
281
|
+
try:
|
|
282
|
+
return proxy_request(request, '/api/v1/ai/agent/info/')
|
|
283
|
+
except Exception as e:
|
|
284
|
+
return JsonResponse({"result": False, "message": "get_agent_info exception: {}".format(e), "code": 400})
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
@login_exempt
|
|
288
|
+
@csrf_exempt
|
|
289
|
+
@require_http_methods(["GET"])
|
|
290
|
+
def get_linked_view_info(request, uid):
|
|
291
|
+
"""获取关联视图信息"""
|
|
292
|
+
|
|
293
|
+
try:
|
|
294
|
+
return proxy_request(request, f'/api/v1/linked_view/{uid}/')
|
|
295
|
+
except Exception as e:
|
|
296
|
+
return JsonResponse({"result": False, "message": "get_linked_view_info exception: {}".format(e), "code": 400})
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
@login_exempt
|
|
300
|
+
@csrf_exempt
|
|
301
|
+
@require_http_methods(["POST"])
|
|
302
|
+
def get_effective_watermark(request):
|
|
303
|
+
"""获取有效水印"""
|
|
304
|
+
|
|
305
|
+
try:
|
|
306
|
+
return proxy_request(request, '/api/v1/watermark/effective/')
|
|
307
|
+
except Exception as e:
|
|
308
|
+
return JsonResponse({"result": False, "message": "get_effective_watermark exception: {}".format(e), "code": 400})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "django_bkvision_sdk"
|
|
3
|
+
version = "1.2.4"
|
|
4
|
+
packages = [{ include = "django_bkvision" }]
|
|
5
|
+
description = "bkvision's python sdk of django for dashboard embed scene"
|
|
6
|
+
authors = ["Tencent BlueKing <blueking@tencent.com>"]
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
license = "MIT"
|
|
9
|
+
keywords = ["django", "bkvision"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Framework :: Django",
|
|
12
|
+
"Framework :: Django :: 2.0",
|
|
13
|
+
"Framework :: Django :: 2.2",
|
|
14
|
+
"Framework :: Django :: 3.2",
|
|
15
|
+
"Framework :: Django :: 4.0",
|
|
16
|
+
"Framework :: Django :: 4.2",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.8",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[tool.poetry.dependencies]
|
|
28
|
+
python = ">=3.8,<4.0"
|
|
29
|
+
Django = ">=2.0,<5.0"
|
|
30
|
+
requests = ">=2.20"
|
|
31
|
+
blueapps = ">=4.0,<5.0"
|
|
32
|
+
|
|
33
|
+
[tool.poetry.dev-dependencies]
|
|
34
|
+
pytest = "^5.2"
|
|
35
|
+
|
|
36
|
+
[build-system]
|
|
37
|
+
requires = ["poetry-core>=1.0.0"]
|
|
38
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from setuptools import setup
|
|
3
|
+
|
|
4
|
+
packages = \
|
|
5
|
+
['django_bkvision', 'django_bkvision.migrations']
|
|
6
|
+
|
|
7
|
+
package_data = \
|
|
8
|
+
{'': ['*']}
|
|
9
|
+
|
|
10
|
+
install_requires = \
|
|
11
|
+
['Django>=2.0,<5.0', 'blueapps>=4.0,<5.0', 'requests>=2.20']
|
|
12
|
+
|
|
13
|
+
setup_kwargs = {
|
|
14
|
+
'name': 'django-bkvision-sdk',
|
|
15
|
+
'version': '1.2.4',
|
|
16
|
+
'description': "bkvision's python sdk of django for dashboard embed scene",
|
|
17
|
+
'long_description': "## 一、快速安装\n\n1. 从官方 PyPI 安装\n\n```bash\npip install django-bkvision-sdk\n```\n\n> 发行名为 `django-bkvision-sdk`,import 包名是 `django_bkvision`。\n\n2. 添加 `django_bkvision` 到 `INSTALLED_APPS`\n\n```python\nINSTALLED_APPS = (\n # ...\n 'django.contrib.auth',\n 'django_bkvision',\n # ...\n)\n```\n\n3. 添加路由到 `urls.py`\n\n```python\nfrom django.urls import include, path\n\nurlpatterns = [\n path('bkvision/', include('django_bkvision.urls')),\n]\n```\n\n## 二、必填配置\n\n`BKAPP_BKVISION_APIGW_URL` 是上游 API 网关地址,**必须显式配置**,包内不提供默认地址。\n\n方式一,在 `settings.py` 中配置:\n\n```python\nBKAPP_BKVISION_APIGW_URL = 'https://bkvision.example.com/prod'\n```\n\n方式二,通过环境变量注入:\n\n```bash\nexport BKAPP_BKVISION_APIGW_URL=https://bkvision.example.com/prod\n```\n\n示例地址是占位,请替换成自己的网关地址。\n\n## 三、运行环境与前置条件\n\n- Python >= 3.8,Django >= 2.0 且 < 5.0。\n- 依赖 `Django`、`requests`、`blueapps` 会在安装时自动解析。\n- 本包把请求转发到蓝鲸 API 网关并使用网关鉴权,接入方需具备蓝鲸 PaaS 侧的 `APP_CODE` / `SECRET_KEY` 以及 `blueapps` 框架。\n\n## 四、可选配置\n\n在 `settings.py` 中提供转发前的预处理钩子:\n\n```python\ndef my_before_proxy_func(request):\n return request\n\nPRE_PROCESS_FUNC = my_before_proxy_func\n```\n",
|
|
18
|
+
'author': 'Tencent BlueKing',
|
|
19
|
+
'author_email': 'blueking@tencent.com',
|
|
20
|
+
'maintainer': None,
|
|
21
|
+
'maintainer_email': None,
|
|
22
|
+
'url': None,
|
|
23
|
+
'packages': packages,
|
|
24
|
+
'package_data': package_data,
|
|
25
|
+
'install_requires': install_requires,
|
|
26
|
+
'python_requires': '>=3.8,<4.0',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
setup(**setup_kwargs)
|