Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-python-pg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
7 changes: 0 additions & 7 deletions apps/application/api/application_chat_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions apps/application/flow/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion apps/application/serializers/application_chat_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down
2 changes: 0 additions & 2 deletions apps/application/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
path('workspace/<str:workspace_id>/application/<str:application_id>/chat', views.ApplicationChat.as_view()),
path('workspace/<str:workspace_id>/application/<str:application_id>/chat/export', views.ApplicationChat.Export.as_view()),
path('workspace/<str:workspace_id>/application/<str:application_id>/chat/<int:current_page>/<int:page_size>', views.ApplicationChat.Page.as_view()),
path('workspace/<str:workspace_id>/application/<str:application_id>/chat/<str:chat_id>/share_chat', views.ChatRecordLinkView.as_view()),
path('workspace/<str:workspace_id>/application/<str:application_id>/chat/<str:chat_id>/chat_record', views.ApplicationChatRecord.as_view()),
path('workspace/<str:workspace_id>/application/<str:application_id>/chat/<str:chat_id>/chat_record/<str:chat_record_id>', views.ApplicationChatRecordOperateAPI.as_view()),
path('workspace/<str:workspace_id>/application/<str:application_id>/chat/<str:chat_id>/chat_record/<int:current_page>/<int:page_size>', views.ApplicationChatRecord.Page.as_view()),
Expand All @@ -40,5 +39,4 @@
path('workspace/<str:workspace_id>/application/<str:application_id>/mcp_tools', views.McpServers.as_view()),
path('workspace/<str:workspace_id>/application/<str:application_id>/model/<str:model_id>/prompt_generate', views.PromptGenerateView.as_view()),
path('chat_message/<str:chat_id>', views.ChatView.as_view()),
path('chat/share/<str:link>', views.ChatRecordDetailView.as_view()),
]
3 changes: 1 addition & 2 deletions apps/application/views/application_chat_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion apps/chat/urls.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -24,5 +25,7 @@
path('historical_conversation/clear',views.HistoricalConversationView.BatchDelete.as_view(), name='historical_conversation_clear'),
path('historical_conversation/<str:chat_id>',views.HistoricalConversationView.Operate.as_view(), name='historical_conversation_operate'),
path('historical_conversation_record/<str:chat_id>', views.HistoricalConversationRecordView.as_view(), name='historical_conversation_record'),
path('historical_conversation_record/<str:chat_id>/<int:current_page>/<int:page_size>', views.HistoricalConversationRecordView.PageView.as_view(), name='historical_conversation_record')
path('historical_conversation_record/<str:chat_id>/<int:current_page>/<int:page_size>', views.HistoricalConversationRecordView.PageView.as_view(), name='historical_conversation_record'),
path('share/<str:link>', ChatRecordDetailView.as_view()),
path('<str:application_id>/chat/<str:chat_id>/share_chat', ChatRecordLinkView.as_view()),
]
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
52 changes: 1 addition & 51 deletions apps/models_provider/impl/gemini_model_provider/model/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions installer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion installer/Dockerfile-base
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
33 changes: 17 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Loading