mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
perf: 优化API_KEY调用对话文档 (#532)
This commit is contained in:
parent
efe37083d3
commit
2da31997e5
|
|
@ -5,7 +5,7 @@ from . import views
|
|||
app_name = "application"
|
||||
urlpatterns = [
|
||||
path('application', views.Application.as_view(), name="application"),
|
||||
path('application/profile', views.Application.Profile.as_view()),
|
||||
path('application/profile', views.Application.Profile.as_view(), name='application/profile'),
|
||||
path('application/embed', views.Application.Embed.as_view()),
|
||||
path('application/authentication', views.Application.Authentication.as_view()),
|
||||
path('application/<str:application_id>/edit_icon', views.Application.EditIcon.as_view()),
|
||||
|
|
@ -28,7 +28,7 @@ urlpatterns = [
|
|||
path('application/<str:application_id>/access_token', views.Application.AccessToken.as_view(),
|
||||
name='application/access_token'),
|
||||
path('application/<int:current_page>/<int:page_size>', views.Application.Page.as_view(), name='application_page'),
|
||||
path('application/<str:application_id>/chat/open', views.ChatView.Open.as_view()),
|
||||
path('application/<str:application_id>/chat/open', views.ChatView.Open.as_view(), name='application/open'),
|
||||
path("application/chat/open", views.ChatView.OpenTemp.as_view()),
|
||||
path("application/<str:application_id>/chat/client/<int:current_page>/<int:page_size>",
|
||||
views.ChatView.ClientChatHistoryPage.as_view()),
|
||||
|
|
@ -50,7 +50,7 @@ urlpatterns = [
|
|||
name=''),
|
||||
path('application/<str:application_id>/chat/<chat_id>/chat_record/<str:chat_record_id>/improve',
|
||||
views.ChatView.ChatRecord.ChatRecordImprove.as_view()),
|
||||
path('application/chat_message/<str:chat_id>', views.ChatView.Message.as_view()),
|
||||
path('application/chat_message/<str:chat_id>', views.ChatView.Message.as_view(), name='application/message'),
|
||||
path(
|
||||
'application/<str:application_id>/chat/<chat_id>/chat_record/<str:chat_record_id>/dataset/<str:dataset_id>/document_id/<str:document_id>/improve/<str:paragraph_id>',
|
||||
views.ChatView.ChatRecord.Improve.Operate.as_view(),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,88 @@
|
|||
# coding=utf-8
|
||||
"""
|
||||
@project: maxkb
|
||||
@Author:虎
|
||||
@file: init_doc.py
|
||||
@date:2024/5/24 14:11
|
||||
@desc:
|
||||
"""
|
||||
import hashlib
|
||||
|
||||
from django.urls import re_path, path
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.views import get_schema_view
|
||||
from rest_framework import permissions
|
||||
|
||||
from common.auth import AnonymousAuthentication
|
||||
from smartdoc.const import CONFIG
|
||||
|
||||
|
||||
def init_app_doc(application_urlpatterns):
|
||||
schema_view = get_schema_view(
|
||||
openapi.Info(
|
||||
title="Python API",
|
||||
default_version='v1',
|
||||
description="智能客服平台",
|
||||
),
|
||||
public=True,
|
||||
permission_classes=[permissions.AllowAny],
|
||||
authentication_classes=[AnonymousAuthentication]
|
||||
)
|
||||
application_urlpatterns += [
|
||||
re_path(r'^doc(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0),
|
||||
name='schema-json'), # 导出
|
||||
path('doc/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
||||
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
|
||||
]
|
||||
|
||||
|
||||
def init_chat_doc(application_urlpatterns, patterns):
|
||||
chat_schema_view = get_schema_view(
|
||||
openapi.Info(
|
||||
title="Python API",
|
||||
default_version='/chat',
|
||||
description="智能客服平台",
|
||||
),
|
||||
public=True,
|
||||
permission_classes=[permissions.AllowAny],
|
||||
authentication_classes=[AnonymousAuthentication],
|
||||
patterns=[url for url in patterns if
|
||||
url.name is not None and ['application/message', 'application/open',
|
||||
'application/profile'].__contains__(
|
||||
url.name)]
|
||||
)
|
||||
application_urlpatterns += [
|
||||
path('doc/chat/', chat_schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
||||
path('redoc/chat/', chat_schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
|
||||
]
|
||||
|
||||
|
||||
def encrypt(text):
|
||||
md5 = hashlib.md5()
|
||||
md5.update(text.encode())
|
||||
result = md5.hexdigest()
|
||||
return result
|
||||
|
||||
|
||||
def get_call(application_urlpatterns, patterns, params, func):
|
||||
def run():
|
||||
if params['valid']():
|
||||
func(*params['get_params'](application_urlpatterns, patterns))
|
||||
|
||||
return run
|
||||
|
||||
|
||||
init_list = [(init_app_doc, {'valid': lambda: CONFIG.get('DOC_PASSWORD') is not None and encrypt(
|
||||
CONFIG.get('DOC_PASSWORD')) == '34558ab2851c350e8ff578585135b8c9',
|
||||
'get_call': get_call,
|
||||
'get_params': lambda application_urlpatterns, patterns: (application_urlpatterns,)}),
|
||||
(init_chat_doc, {'valid': lambda: CONFIG.get('DOC_PASSWORD') is not None and encrypt(
|
||||
CONFIG.get('DOC_PASSWORD')) == '34558ab2851c350e8ff578585135b8c9' or True, 'get_call': get_call,
|
||||
'get_params': lambda application_urlpatterns, patterns: (
|
||||
application_urlpatterns, patterns)})]
|
||||
|
||||
|
||||
def init_doc(application_urlpatterns, patterns):
|
||||
for init, params in init_list:
|
||||
if params['valid']():
|
||||
get_call(application_urlpatterns, patterns, params, init)()
|
||||
|
|
@ -19,27 +19,14 @@ import os
|
|||
from django.http import HttpResponse
|
||||
from django.urls import path, re_path, include
|
||||
from django.views import static
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.views import get_schema_view
|
||||
from rest_framework import permissions, status
|
||||
from rest_framework import status
|
||||
|
||||
from common.auth import AnonymousAuthentication
|
||||
from application.urls import urlpatterns as application_urlpatterns
|
||||
from common.init.init_doc import init_doc
|
||||
from common.response.result import Result
|
||||
from smartdoc import settings
|
||||
from smartdoc.conf import PROJECT_DIR
|
||||
|
||||
schema_view = get_schema_view(
|
||||
|
||||
openapi.Info(
|
||||
title="Python API",
|
||||
default_version='v1',
|
||||
description="智能客服平台",
|
||||
),
|
||||
public=True,
|
||||
permission_classes=[permissions.AllowAny],
|
||||
authentication_classes=[AnonymousAuthentication]
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path("api/", include("users.urls")),
|
||||
path("api/", include("dataset.urls")),
|
||||
|
|
@ -83,10 +70,4 @@ def page_not_found(request, exception):
|
|||
|
||||
|
||||
handler404 = page_not_found
|
||||
|
||||
urlpatterns += [
|
||||
re_path(r'^doc(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0),
|
||||
name='schema-json'), # 导出
|
||||
path('doc/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
||||
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
|
||||
]
|
||||
init_doc(urlpatterns, application_urlpatterns)
|
||||
|
|
|
|||
|
|
@ -82,9 +82,9 @@
|
|||
<el-text type="info">API访问凭据</el-text>
|
||||
</div>
|
||||
<div class="mt-4 mb-16 url-height">
|
||||
<span class="vertical-middle lighter break-all">
|
||||
<a target="_blank" :href="apiUrl" class="vertical-middle lighter break-all">
|
||||
{{ apiUrl }}
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<el-button type="primary" text @click="copyClick(apiUrl)">
|
||||
<AppIcon iconName="app-copy"></AppIcon>
|
||||
|
|
@ -149,7 +149,7 @@ const {
|
|||
params: { id }
|
||||
} = route as any
|
||||
|
||||
const apiUrl = window.location.origin + '/doc'
|
||||
const apiUrl = window.location.origin + '/doc/chat'
|
||||
|
||||
const EditAvatarDialogRef = ref()
|
||||
const LimitDialogRef = ref()
|
||||
|
|
|
|||
Loading…
Reference in New Issue