diff --git a/.github/workflows/build-and-push-python-pg.yml b/.github/workflows/build-and-push-python-pg.yml index 15851e762d3..d86117e8e5b 100644 --- a/.github/workflows/build-and-push-python-pg.yml +++ b/.github/workflows/build-and-push-python-pg.yml @@ -25,7 +25,7 @@ jobs: run: | DOCKER_IMAGE=ghcr.io/1panel-dev/maxkb-base DOCKER_PLATFORMS=${{ github.event.inputs.architecture }} - TAG_NAME=python3.11-pg17.6 + TAG_NAME=python3.11-pg17.7-20260212 DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME}" echo ::set-output name=docker_image::${DOCKER_IMAGE} echo ::set-output name=version::${TAG_NAME} diff --git a/apps/application/api/application_chat_link.py b/apps/application/api/application_chat_link.py index f6e39f17795..e8f349097bf 100644 --- a/apps/application/api/application_chat_link.py +++ b/apps/application/api/application_chat_link.py @@ -26,13 +26,6 @@ def get_request(): @staticmethod def get_parameters(): return [ - OpenApiParameter( - name="workspace_id", - description="工作空间id", - type=OpenApiTypes.STR, - location='path', - required=True, - ), OpenApiParameter( name="application_id", description="Application ID", diff --git a/apps/application/chat_pipeline/step/chat_step/i_chat_step.py b/apps/application/chat_pipeline/step/chat_step/i_chat_step.py index 34af702a8c4..bd79b8a1dda 100644 --- a/apps/application/chat_pipeline/step/chat_step/i_chat_step.py +++ b/apps/application/chat_pipeline/step/chat_step/i_chat_step.py @@ -11,7 +11,7 @@ from django.utils.translation import gettext_lazy as _ from langchain.chat_models.base import BaseChatModel -from langchain.schema import BaseMessage +from langchain_core.messages import BaseMessage from rest_framework import serializers from application.chat_pipeline.I_base_chat_pipeline import IBaseChatPipelineStep, ParagraphPipelineModel diff --git a/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py b/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py index 2048b80805a..25521e422e7 100644 --- a/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py +++ b/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py @@ -16,9 +16,7 @@ from django.http import StreamingHttpResponse from django.utils.translation import gettext as _ from langchain.chat_models.base import BaseChatModel -from langchain.schema import BaseMessage -from langchain.schema.messages import HumanMessage, AIMessage -from langchain_core.messages import AIMessageChunk, SystemMessage +from langchain_core.messages import AIMessageChunk, SystemMessage, BaseMessage, HumanMessage, AIMessage from rest_framework import status from application.chat_pipeline.I_base_chat_pipeline import ParagraphPipelineModel diff --git a/apps/application/chat_pipeline/step/generate_human_message_step/i_generate_human_message_step.py b/apps/application/chat_pipeline/step/generate_human_message_step/i_generate_human_message_step.py index d23d762d825..0d49e9a5e2f 100644 --- a/apps/application/chat_pipeline/step/generate_human_message_step/i_generate_human_message_step.py +++ b/apps/application/chat_pipeline/step/generate_human_message_step/i_generate_human_message_step.py @@ -10,7 +10,7 @@ from typing import Type, List from django.utils.translation import gettext_lazy as _ -from langchain.schema import BaseMessage +from langchain_core.messages import BaseMessage from rest_framework import serializers from application.chat_pipeline.I_base_chat_pipeline import IBaseChatPipelineStep, ParagraphPipelineModel diff --git a/apps/application/chat_pipeline/step/generate_human_message_step/impl/base_generate_human_message_step.py b/apps/application/chat_pipeline/step/generate_human_message_step/impl/base_generate_human_message_step.py index e0fb034147c..2c6afb47e8b 100644 --- a/apps/application/chat_pipeline/step/generate_human_message_step/impl/base_generate_human_message_step.py +++ b/apps/application/chat_pipeline/step/generate_human_message_step/impl/base_generate_human_message_step.py @@ -8,8 +8,7 @@ """ from typing import List, Dict -from langchain.schema import BaseMessage, HumanMessage -from langchain_core.messages import SystemMessage +from langchain_core.messages import SystemMessage, BaseMessage, HumanMessage from application.chat_pipeline.I_base_chat_pipeline import ParagraphPipelineModel from application.chat_pipeline.step.generate_human_message_step.i_generate_human_message_step import \ diff --git a/apps/application/chat_pipeline/step/reset_problem_step/impl/base_reset_problem_step.py b/apps/application/chat_pipeline/step/reset_problem_step/impl/base_reset_problem_step.py index d830a6550ed..47368ae65f5 100644 --- a/apps/application/chat_pipeline/step/reset_problem_step/impl/base_reset_problem_step.py +++ b/apps/application/chat_pipeline/step/reset_problem_step/impl/base_reset_problem_step.py @@ -9,7 +9,7 @@ from typing import List from django.utils.translation import gettext as _ -from langchain.schema import HumanMessage +from langchain_core.messages import HumanMessage from application.chat_pipeline.step.reset_problem_step.i_reset_problem_step import IResetProblemStep from application.models import ChatRecord diff --git a/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py b/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py index d7516c51271..7673e011217 100644 --- a/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py +++ b/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py @@ -14,8 +14,7 @@ from django.db.models import QuerySet from django.utils.translation import gettext as _ -from langchain.schema import HumanMessage, SystemMessage -from langchain_core.messages import BaseMessage, AIMessage +from langchain_core.messages import BaseMessage, AIMessage, HumanMessage, SystemMessage from application.flow.i_step_node import NodeResult, INode from application.flow.step_node.ai_chat_step_node.i_chat_node import IChatNode diff --git a/apps/application/flow/step_node/intent_node/impl/base_intent_node.py b/apps/application/flow/step_node/intent_node/impl/base_intent_node.py index 2258337855c..f3bc38d74e2 100644 --- a/apps/application/flow/step_node/intent_node/impl/base_intent_node.py +++ b/apps/application/flow/step_node/intent_node/impl/base_intent_node.py @@ -6,7 +6,7 @@ from functools import reduce from django.db.models import QuerySet -from langchain.schema import HumanMessage, SystemMessage +from langchain_core.messages import HumanMessage, SystemMessage from application.flow.i_step_node import INode, NodeResult from application.flow.step_node.intent_node.i_intent_node import IIntentNode diff --git a/apps/application/flow/step_node/question_node/impl/base_question_node.py b/apps/application/flow/step_node/question_node/impl/base_question_node.py index 500a6ec3345..ff724e4011c 100644 --- a/apps/application/flow/step_node/question_node/impl/base_question_node.py +++ b/apps/application/flow/step_node/question_node/impl/base_question_node.py @@ -12,8 +12,7 @@ from typing import List, Dict from django.db.models import QuerySet -from langchain.schema import HumanMessage, SystemMessage -from langchain_core.messages import BaseMessage +from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage from application.flow.i_step_node import NodeResult, INode from application.flow.step_node.question_node.i_question_node import IQuestionNode diff --git a/apps/application/flow/tools.py b/apps/application/flow/tools.py index a5fc1ac6ae5..e87c1cf6085 100644 --- a/apps/application/flow/tools.py +++ b/apps/application/flow/tools.py @@ -400,11 +400,23 @@ async def _yield_mcp_response(chat_model, message_list, mcp_servers, mcp_output_ if tool_id in tool_calls_info: tool_info = tool_calls_info[tool_id] try: - tool_result = json.loads(chunk[0].content) - tool_lib_id = tool_result.pop('tool_id') if 'tool_id' in tool_result else None + if isinstance(chunk[0].content, str): + tool_result = json.loads(chunk[0].content) + elif isinstance(chunk[0].content, dict): + tool_result = chunk[0].content + elif isinstance(chunk[0].content, list): + tool_result = chunk[0].content[0] if len(chunk[0].content) > 0 else {} + else: + tool_result = {} + text = tool_result.pop('text') if 'text' in tool_result else None + text_result = json.loads(text) + if text: + tool_lib_id = text_result.pop('tool_id') if 'tool_id' in text_result else None + else: + tool_lib_id = tool_result.pop('tool_id') if 'tool_id' in tool_result else None if tool_lib_id: await save_tool_record(tool_lib_id, tool_info, tool_result, source_id, source_type) - tool_result = json.dumps(tool_result, ensure_ascii=False) + tool_result = json.dumps(text_result, ensure_ascii=False) except Exception as e: tool_result = chunk[0].content content = generate_tool_message_complete( diff --git a/apps/application/serializers/application_chat_link.py b/apps/application/serializers/application_chat_link.py index 2309e8e5249..b97b60b1919 100644 --- a/apps/application/serializers/application_chat_link.py +++ b/apps/application/serializers/application_chat_link.py @@ -35,7 +35,6 @@ def validate(self, attrs): class ChatRecordShareLinkSerializer(serializers.Serializer): chat_id = serializers.UUIDField(required=True, label=_("Conversation ID")) - workspace_id = serializers.CharField(required=False, allow_null=True, allow_blank=True, label=_("Workspace ID")) application_id = serializers.UUIDField(required=True, label=_("Application ID")) user_id = serializers.UUIDField(required=False, label=_("User ID")) diff --git a/apps/application/urls.py b/apps/application/urls.py index a7a683415a7..7e2569076b9 100644 --- a/apps/application/urls.py +++ b/apps/application/urls.py @@ -24,7 +24,6 @@ path('workspace//application//chat', views.ApplicationChat.as_view()), path('workspace//application//chat/export', views.ApplicationChat.Export.as_view()), path('workspace//application//chat//', views.ApplicationChat.Page.as_view()), - path('workspace//application//chat//share_chat', views.ChatRecordLinkView.as_view()), path('workspace//application//chat//chat_record', views.ApplicationChatRecord.as_view()), path('workspace//application//chat//chat_record/', views.ApplicationChatRecordOperateAPI.as_view()), path('workspace//application//chat//chat_record//', views.ApplicationChatRecord.Page.as_view()), @@ -40,5 +39,4 @@ path('workspace//application//mcp_tools', views.McpServers.as_view()), path('workspace//application//model//prompt_generate', views.PromptGenerateView.as_view()), path('chat_message/', views.ChatView.as_view()), - path('chat/share/', views.ChatRecordDetailView.as_view()), ] diff --git a/apps/application/views/application_chat_link.py b/apps/application/views/application_chat_link.py index b96cce5e455..d410ef392a6 100644 --- a/apps/application/views/application_chat_link.py +++ b/apps/application/views/application_chat_link.py @@ -30,9 +30,8 @@ class ChatRecordLinkView(APIView): tags=[_("Chat record link")] # type: ignore ) - def post(self, request: Request, workspace_id: str, application_id: str, chat_id: str): + def post(self, request: Request, application_id: str, chat_id: str): return result.success(ChatRecordShareLinkSerializer(data={ - "workspace_id": workspace_id, "application_id": application_id, "chat_id": chat_id, "user_id": request.auth.chat_user_id diff --git a/apps/chat/urls.py b/apps/chat/urls.py index c85be10130c..7f157737370 100644 --- a/apps/chat/urls.py +++ b/apps/chat/urls.py @@ -1,5 +1,6 @@ from django.urls import path +from application.views import ChatRecordDetailView, ChatRecordLinkView from chat.views.mcp import mcp_view from . import views @@ -24,5 +25,7 @@ path('historical_conversation/clear',views.HistoricalConversationView.BatchDelete.as_view(), name='historical_conversation_clear'), path('historical_conversation/',views.HistoricalConversationView.Operate.as_view(), name='historical_conversation_operate'), path('historical_conversation_record/', views.HistoricalConversationRecordView.as_view(), name='historical_conversation_record'), - path('historical_conversation_record///', views.HistoricalConversationRecordView.PageView.as_view(), name='historical_conversation_record') + path('historical_conversation_record///', views.HistoricalConversationRecordView.PageView.as_view(), name='historical_conversation_record'), + path('share/', ChatRecordDetailView.as_view()), + path('/chat//share_chat', ChatRecordLinkView.as_view()), ] diff --git a/apps/common/management/commands/services/services/gunicorn.py b/apps/common/management/commands/services/services/gunicorn.py index 627af6b78bc..fe884099ffb 100644 --- a/apps/common/management/commands/services/services/gunicorn.py +++ b/apps/common/management/commands/services/services/gunicorn.py @@ -27,7 +27,7 @@ def cmd(self): '-w', str(self.worker), '--max-requests', str(max_requests), '--max-requests-jitter', '2048', - '--timeout', '0', + '--timeout', '30', '--graceful-timeout', '300', '--access-logformat', log_format, '--access-logfile', '/dev/null', diff --git a/apps/common/management/commands/services/services/local_model.py b/apps/common/management/commands/services/services/local_model.py index 93e8bb3635a..5f587a30b64 100644 --- a/apps/common/management/commands/services/services/local_model.py +++ b/apps/common/management/commands/services/services/local_model.py @@ -36,7 +36,7 @@ def cmd(self): '-w', str(worker), '--max-requests', str(max_requests), '--max-requests-jitter', '2048', - '--timeout', '0', + '--timeout', '30', '--graceful-timeout', '300', '--access-logformat', log_format, '--access-logfile', '/dev/null', diff --git a/apps/common/management/commands/services/services/scheduler.py b/apps/common/management/commands/services/services/scheduler.py index 4196d3e055d..81b41cdabea 100644 --- a/apps/common/management/commands/services/services/scheduler.py +++ b/apps/common/management/commands/services/services/scheduler.py @@ -27,7 +27,7 @@ def cmd(self): '-w', str(self.worker), '--max-requests', str(max_requests), '--max-requests-jitter', '2048', - '--timeout', '0', + '--timeout', '30', '--graceful-timeout', '300', '--access-logformat', log_format, '--access-logfile', '/dev/null', diff --git a/apps/models_provider/impl/gemini_model_provider/model/llm.py b/apps/models_provider/impl/gemini_model_provider/model/llm.py index 3629f5372d5..9b316eafd37 100644 --- a/apps/models_provider/impl/gemini_model_provider/model/llm.py +++ b/apps/models_provider/impl/gemini_model_provider/model/llm.py @@ -6,22 +6,10 @@ @Author :Brian Yang @Date :5/13/24 7:40 AM """ -from typing import List, Dict, Optional, Sequence, Union, Any, Iterator, cast +from typing import List, Dict, Optional, Any -from google.ai.generativelanguage_v1 import GenerateContentResponse -from google.ai.generativelanguage_v1beta.types import ( - Tool as GoogleTool, -) -from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.messages import BaseMessage, get_buffer_string -from langchain_core.outputs import ChatGenerationChunk from langchain_google_genai import ChatGoogleGenerativeAI -from langchain_google_genai._function_utils import _ToolConfigDict, _ToolDict -from langchain_google_genai.chat_models import _chat_with_retry, _response_to_result, \ - _FunctionDeclarationType -from langchain_google_genai._common import ( - SafetySettingDict, -) from common.config.tokenizer_manage_config import TokenizerManage from models_provider.base_model_provider import MaxKBBaseModel @@ -60,41 +48,3 @@ def get_num_tokens(self, text: str) -> int: except Exception as e: tokenizer = TokenizerManage.get_tokenizer() return len(tokenizer.encode(text)) - - def _stream( - self, - messages: List[BaseMessage], - stop: Optional[List[str]] = None, - run_manager: Optional[CallbackManagerForLLMRun] = None, - *, - tools: Optional[Sequence[Union[_ToolDict, GoogleTool]]] = None, - functions: Optional[Sequence[_FunctionDeclarationType]] = None, - safety_settings: Optional[SafetySettingDict] = None, - tool_config: Optional[Union[Dict, _ToolConfigDict]] = None, - generation_config: Optional[Dict[str, Any]] = None, - **kwargs: Any, - ) -> Iterator[ChatGenerationChunk]: - request = self._prepare_request( - messages, - stop=stop, - tools=tools, - functions=functions, - safety_settings=safety_settings, - tool_config=tool_config, - generation_config=generation_config, - ) - response: GenerateContentResponse = _chat_with_retry( - request=request, - generation_method=self.client.stream_generate_content, - **kwargs, - metadata=self.default_metadata, - ) - for chunk in response: - _chat_result = _response_to_result(chunk, stream=True) - gen = cast(ChatGenerationChunk, _chat_result.generations[0]) - if gen.message: - token_usage = gen.message.usage_metadata - self.__dict__.setdefault('_last_generation_info', {}).update(token_usage) - if run_manager: - run_manager.on_llm_new_token(gen.text) - yield gen diff --git a/installer/Dockerfile b/installer/Dockerfile index f3dba2bfe4e..c504f365186 100644 --- a/installer/Dockerfile +++ b/installer/Dockerfile @@ -6,7 +6,7 @@ RUN cd ui && ls -la && if [ -d "dist" ]; then exit 0; fi && \ NODE_OPTIONS="--max-old-space-size=4096" npx concurrently "npm run build" "npm run build-chat" && \ find . -maxdepth 1 ! -name '.' ! -name 'dist' ! -name 'public' -exec rm -rf {} + -FROM ghcr.io/1panel-dev/maxkb-base:python3.11-pg17.6 AS stage-build +FROM ghcr.io/1panel-dev/maxkb-base:python3.11-pg17.7-20260212 AS stage-build COPY --chmod=700 . /opt/maxkb-app RUN apt-get update && \ apt-get install -y --no-install-recommends gcc g++ gettext libexpat1-dev libffi-dev && \ @@ -24,7 +24,7 @@ RUN gcc -shared -fPIC -o ${MAXKB_SANDBOX_HOME}/lib/sandbox.so /opt/maxkb-app/ins rm -rf /opt/maxkb-app/installer COPY --from=web-build --chmod=700 ui /opt/maxkb-app/ui -FROM ghcr.io/1panel-dev/maxkb-base:python3.11-pg17.6 +FROM ghcr.io/1panel-dev/maxkb-base:python3.11-pg17.7-20260212 ARG DOCKER_IMAGE_TAG=dev \ BUILD_AT \ GITHUB_COMMIT diff --git a/installer/Dockerfile-base b/installer/Dockerfile-base index ae9d644ed71..9bb4890486a 100644 --- a/installer/Dockerfile-base +++ b/installer/Dockerfile-base @@ -3,7 +3,7 @@ RUN python3 -m venv /opt/py3 FROM ghcr.io/1panel-dev/maxkb-vector-model:v2.0.3 AS vector-model -FROM postgres:17.6-trixie +FROM postgres:17.7-trixie COPY --from=python-stage /usr/local /usr/local COPY --from=python-stage /opt/py3 /opt/py3 COPY --chmod=500 installer/*.sh /usr/bin/ diff --git a/pyproject.toml b/pyproject.toml index b473565c0cd..04813478788 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,40 +6,41 @@ authors = [{ name = "shaohuzhang1", email = "shaohu.zhang@fit2cloud.com" }] requires-python = "~=3.11.0" readme = "README.md" dependencies = [ - "django==5.2.9", + "django==5.2.11", "drf-spectacular[sidecar]==0.28.0", "django-redis==6.0.0", "django-db-connection-pool==1.2.6", "django-mptt==0.17.0", "psycopg[binary]==3.2.9", "python-dotenv==1.1.1", - "uuid-utils==0.11.0", + "uuid-utils==0.14.0", "captcha==0.7.1", "pytz==2025.2", "psutil==7.0.0", "cffi==1.17.1", "beautifulsoup4==4.13.4", "jieba==0.42.1", - "langchain-openai==0.3.35", - "langchain-anthropic==0.3.22", - "langchain-community==0.3.31", - "langchain-deepseek==0.1.4", - "langchain-google-genai==2.1.12", - "langchain-mcp-adapters==0.1.13", - "langchain-huggingface==0.3.1", - "langchain-ollama==0.3.10", - "langchain_core==0.3.81", - "langchain-aws==0.2.28", - "langgraph==0.5.3", + "langchain==1.2.10", + "langchain-openai==1.1.10", + "langchain-anthropic==1.3.3", + "langchain-community==0.4.1", + "langchain-deepseek==1.0.1", + "langchain-google-genai==4.2.1", + "langchain-mcp-adapters==0.2.1", + "langchain-huggingface==1.2.0", + "langchain-ollama==1.0.1", + "langchain-aws==1.3.0", + "langgraph==1.0.8", + "deepagents==0.4.3", "torch==2.8.0", "sentence-transformers==5.0.0", "qianfan==0.4.12.3", "zhipuai==2.1.5.20250708", "volcengine-python-sdk[ark]==4.0.5", - "boto3==1.39.4", + "boto3==1.42.46", "tencentcloud-sdk-python==3.0.1420", "xinference-client==1.7.1.post1", - "anthropic==0.74.1", + "anthropic==0.79.0", "dashscope==1.25.7", "celery[sqlalchemy]==5.5.3", "django-celery-beat==2.8.1", @@ -51,7 +52,7 @@ dependencies = [ "xlrd==2.0.2", "xlwt==1.3.0", "pymupdf==1.26.3", - "pypdf==6.6.2", + "pypdf==6.7.1", "pydub==0.25.1", "pysilk==0.0.1", "gunicorn==23.0.0", diff --git a/ui/src/api/chat/chat.ts b/ui/src/api/chat/chat.ts index 4eb7452306c..667a0e02b51 100644 --- a/ui/src/api/chat/chat.ts +++ b/ui/src/api/chat/chat.ts @@ -1,4 +1,4 @@ -import {Result} from '@/request/Result' +import { Result } from '@/request/Result' import { get, post, @@ -9,17 +9,17 @@ import { download, exportFile, } from '@/request/chat/index' -import {type ChatProfile} from '@/api/type/chat' -import {type Ref} from 'vue' -import type {ResetPasswordRequest} from '@/api/type/user.ts' +import { type ChatProfile } from '@/api/type/chat' +import { type Ref } from 'vue' +import type { ResetPasswordRequest } from '@/api/type/user.ts' import useStore from '@/stores' -import type {LoginRequest} from '@/api/type/user' +import type { LoginRequest } from '@/api/type/user' -const prefix: any = {_value: '/workspace/'} +const prefix: any = { _value: '/workspace/' } Object.defineProperty(prefix, 'value', { get: function () { - const {user} = useStore() + const { user } = useStore() return this._value + user.getWorkspaceId() + '/application' }, }) @@ -51,7 +51,7 @@ const chatProfile: (assessToken: string, loading?: Ref) => Promise { - return get('/profile', {access_token: assessToken}, loading) + return get('/profile', { access_token: assessToken }, loading) } /** * 匿名认证 @@ -63,7 +63,7 @@ const anonymousAuthentication: ( assessToken: string, loading?: Ref, ) => Promise> = (assessToken, loading) => { - return post('/auth/anonymous', {access_token: assessToken}, {}, loading) + return post('/auth/anonymous', { access_token: assessToken }, {}, loading) } /** * 密码认证 @@ -77,7 +77,7 @@ const passwordAuthentication: ( password: string, loading?: Ref, ) => Promise> = (assessToken, password, loading) => { - return post('auth/password', {access_token: assessToken, password: password}, {}, loading) + return post('auth/password', { access_token: assessToken, password: password }, {}, loading) } /** * 获取应用相关信息 @@ -115,8 +115,12 @@ const ldapLogin: ( * @param username * @param loading 接口加载器 */ -const getCaptcha: (username?: string, accessToken?: string, loading?: Ref) => Promise> = (username, accessToken, loading) => { - return get('/captcha', {username: username, accessToken: accessToken}, loading) +const getCaptcha: ( + username?: string, + accessToken?: string, + loading?: Ref, +) => Promise> = (username, accessToken, loading) => { + return get('/captcha', { username: username, accessToken: accessToken }, loading) } /** @@ -130,35 +134,35 @@ const getQrSource: (loading?: Ref) => Promise> = (loading) return get('auth/qr_type/source', undefined, loading) } -const getDingCallback: (code: string, accessToken: string, loading?: Ref) => Promise> = ( - code, - accessToken, - loading, -) => { - return get('auth/dingtalk', {code, accessToken: accessToken}, loading) +const getDingCallback: ( + code: string, + accessToken: string, + loading?: Ref, +) => Promise> = (code, accessToken, loading) => { + return get('auth/dingtalk', { code, accessToken: accessToken }, loading) } -const getDingOauth2Callback: (code: string, accessToken: string, loading?: Ref) => Promise> = ( - code, - accessToken, - loading, -) => { - return get('auth/dingtalk/oauth2', {code, accessToken: accessToken}, loading) +const getDingOauth2Callback: ( + code: string, + accessToken: string, + loading?: Ref, +) => Promise> = (code, accessToken, loading) => { + return get('auth/dingtalk/oauth2', { code, accessToken: accessToken }, loading) } -const getWecomCallback: (code: string, accessToken: string, loading?: Ref) => Promise> = ( - code, - accessToken, - loading, -) => { - return get('auth/wecom', {code, accessToken: accessToken}, loading) +const getWecomCallback: ( + code: string, + accessToken: string, + loading?: Ref, +) => Promise> = (code, accessToken, loading) => { + return get('auth/wecom', { code, accessToken: accessToken }, loading) } -const getLarkCallback: (code: string, accessToken: string, loading?: Ref) => Promise> = ( - code, - accessToken, - loading, -) => { - return get('auth/lark/oauth2', {code, accessToken: accessToken}, loading) +const getLarkCallback: ( + code: string, + accessToken: string, + loading?: Ref, +) => Promise> = (code, accessToken, loading) => { + return get('auth/lark/oauth2', { code, accessToken: accessToken }, loading) } /** @@ -185,19 +189,20 @@ const vote: ( vote_reason?: string, vote_other_content?: string, loading?: Ref, -) => Promise> = (chat_id, chat_record_id, vote_status, vote_reason, vote_other_content, loading) => { - - const data = { +) => Promise> = ( + chat_id, + chat_record_id, vote_status, - ...(vote_reason !== undefined && { vote_reason }), - ...(vote_other_content !== undefined && { vote_other_content }) -} - return put( - `/vote/chat/${chat_id}/chat_record/${chat_record_id}`, - data, - undefined, - loading, - ) + vote_reason, + vote_other_content, + loading, +) => { + const data = { + vote_status, + ...(vote_reason !== undefined && { vote_reason }), + ...(vote_other_content !== undefined && { vote_other_content }), + } + return put(`/vote/chat/${chat_id}/chat_record/${chat_record_id}`, data, undefined, loading) } const pageChat: ( current_page: number, @@ -292,9 +297,7 @@ const deleteChat: (chat_id: string, loading?: Ref) => Promise) => Promise> = ( - loading -) => { +const clearChat: (loading?: Ref) => Promise> = (loading) => { return del(`historical_conversation/clear`, undefined, undefined, loading) } /** @@ -339,9 +342,32 @@ const postUploadFile: ( return post(`/oss/file`, fd, undefined, loading) } -const getFile: (application_id: string, params: any) => Promise> = (application_id, params) => { +const getFile: (application_id: string, params: any) => Promise> = ( + application_id, + params, +) => { return get(`/oss/get_url/${application_id}`, params) } + +/** + * 生成分享链接 + * @param 参数 + * chat_id: string + * data + */ +const postShareChat: ( + application_id: string, + chat_id: string, + data: any, + loading?: Ref, +) => Promise = (application_id, chat_id, data, loading) => { + return post(`/${application_id}/chat/${chat_id}/share_chat`, data, undefined, loading) +} + +const getShareLink: (link: string) => Promise> = (link) => { + return get(`/share/${link}`, undefined) +} + export default { open, chat, @@ -372,5 +398,7 @@ export default { clearChat, modifyChat, postUploadFile, - getFile + getFile, + postShareChat, + getShareLink, } diff --git a/ui/src/api/type/application.ts b/ui/src/api/type/application.ts index 49b7ec91222..b81508204b4 100644 --- a/ui/src/api/type/application.ts +++ b/ui/src/api/type/application.ts @@ -1,5 +1,5 @@ -import {type Dict} from '@/api/type/common' -import {type Ref} from 'vue' +import { type Dict } from '@/api/type/common' +import { type Ref } from 'vue' import bus from '@/bus' interface ApplicationFormType { @@ -168,7 +168,7 @@ export class ChatRecordManage { } } this.chat.answer_text = this.chat.answer_text + chunk_answer - bus.emit('change:answer', {record_id: this.chat.record_id, is_end: false}) + bus.emit('change:answer', { record_id: this.chat.record_id, is_end: false }) } get_current_up_node(run_node: any) { @@ -259,7 +259,7 @@ export class ChatRecordManage { if (this.loading) { this.loading.value = false } - bus.emit('change:answer', {record_id: this.chat.record_id, is_end: true}) + bus.emit('change:answer', { record_id: this.chat.record_id, is_end: true }) if (this.id) { clearInterval(this.id) } @@ -293,21 +293,21 @@ export class ChatRecordManage { } return } - const {current_node, answer_text_list_index} = node_info + const { current_node, answer_text_list_index } = node_info if (current_node.buffer.length > 20) { const context = current_node.is_end ? current_node.buffer.splice(0) : current_node.buffer.splice( - 0, - current_node.is_end ? undefined : current_node.buffer.length - 20, - ) + 0, + current_node.is_end ? undefined : current_node.buffer.length - 20, + ) const reasoning_content = current_node.is_end ? current_node.reasoning_content_buffer.splice(0) : current_node.reasoning_content_buffer.splice( - 0, - current_node.is_end ? undefined : current_node.reasoning_content_buffer.length - 20, - ) + 0, + current_node.is_end ? undefined : current_node.reasoning_content_buffer.length - 20, + ) this.append_answer( context.join(''), reasoning_content.join(''), @@ -392,10 +392,16 @@ export class ChatRecordManage { appendChunk(chunk: Chunk) { let n = this.node_list.find((item) => item.real_node_id == chunk.real_node_id) if (n) { - n.buffer.push(...chunk.content) + for (const ch of chunk.content) { + n.buffer.push(ch) + } + // n.buffer.push(...chunk.content) n.content += chunk.content if (chunk.reasoning_content) { - n.reasoning_content_buffer.push(...chunk.reasoning_content) + for (const ch of chunk.reasoning_content) { + n.reasoning_content_buffer.push(ch) + } + // n.reasoning_content_buffer.push(...chunk.reasoning_content) n.reasoning_content += chunk.reasoning_content } } else { @@ -542,4 +548,4 @@ export class ChatManagement { } } -export type {ApplicationFormType, chatType} +export type { ApplicationFormType, chatType } diff --git a/ui/src/components/ai-chat/component/answer-content/index.vue b/ui/src/components/ai-chat/component/answer-content/index.vue index e2bfe8ad391..d15d945db07 100644 --- a/ui/src/components/ai-chat/component/answer-content/index.vue +++ b/ui/src/components/ai-chat/component/answer-content/index.vue @@ -1,5 +1,5 @@