feat: Add user group information in global field

This commit is contained in:
zhangzhanwei 2025-12-29 17:33:05 +08:00 committed by zhanweizhang7
parent 7230daa5ec
commit 60bece585c
8 changed files with 27 additions and 2 deletions

View File

@ -34,7 +34,9 @@ def get_global_variable(node):
'history_context': history_context, 'chat_id': str(chat_id), **node.workflow_manage.form_data,
'chat_user_id': body.get('chat_user_id'),
'chat_user_type': body.get('chat_user_type'),
'chat_user': body.get('chat_user')}
'chat_user': body.get('chat_user'),
'chat_user_group': body.get('chat_user_group')
}
class BaseStartStepNode(IStarNode):

View File

@ -22,6 +22,7 @@ from common.exception.app_exception import ChatException
from knowledge.models import Document
from models_provider.models import Model
from models_provider.tools import get_model_credential
from system_manage.models import UserGroupRelation
class ChatInfo:
@ -114,6 +115,21 @@ class ChatInfo:
self.chat_user = {'username': '游客'}
return self.chat_user
def get_chat_user_group(self, asker=None):
chat_user = self.get_chat_user(asker=asker)
chat_user_id = chat_user.get('id')
if not chat_user_id:
return []
user_group_relation_model = DatabaseModelManage.get_model("user_group_relation")
if user_group_relation_model:
return [{
'id': user_group_relation.group_id,
'name': user_group_relation.group.name
} for user_group_relation in QuerySet(user_group_relation_model).select_related('group').filter(user_id=chat_user_id)]
return []
def to_base_pipeline_manage_params(self):
self.get_application()
self.get_chat_user()

View File

@ -403,6 +403,7 @@ class ChatSerializers(serializers.Serializer):
'workspace_id': workspace_id,
'debug': debug,
'chat_user': chat_info.get_chat_user(),
'chat_user_group': chat_info.get_chat_user_group(),
'application_id': str(chat_info.application_id)},
WorkFlowPostHandler(chat_info),
base_to_response, form_data, image_list, document_list, audio_list,

View File

@ -5,7 +5,6 @@ import type { Dict, pageRequest } from '@/api/type/common'
import type { knowledgeData } from '@/api/type/knowledge'
import useStore from '@/stores'
import knowledge from '../system-shared/knowledge'
const prefix: any = { _value: '/workspace/' }
Object.defineProperty(prefix, 'value', {
get: function () {

View File

@ -15,6 +15,7 @@ export default {
chatId: 'Chat ID',
chatUserId: 'Chat User ID',
chatUserType: 'Chat User Type',
chatUserGroup: 'Chat User Group',
userInput: 'User Input',
quote: 'Quote',
download: 'Click to Download',

View File

@ -15,6 +15,7 @@ export default {
chatId: '对话 ID',
chatUserId: '对话用户 ID',
chatUserType: '对话用户类型',
chatUserGroup: '对话用户组',
userInput: '用户输入',
quote: '引用',
download: '点击下载文件',

View File

@ -15,6 +15,7 @@ export default {
chatId: '對話 ID',
chatUserId: '對話用戶 ID',
chatUserType: '對話用戶類型',
chatUserGroup: '聊天使用者群組',
userInput: '用戶輸入',
quote: '引用',
download: '點擊下載文件',

View File

@ -68,6 +68,10 @@ const globalFields = [
label: t('chat.chatUserType'),
value: 'chat_user_type',
},
{
label: t('chat.chatUserGroup'),
value: 'chat_user_group',
},
{
label: t('views.chatUser.title'),
value: 'chat_user',