Skip to content

Commit cc16e06

Browse files
committed
refac
1 parent 81f611f commit cc16e06

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

backend/open_webui/tools/knowledge_fs.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ def _get_files_under_dir(tree: dict, dir_id: str) -> list[dict]:
238238

239239

240240
async def _get_accessible_kb_ids(user: dict, model_knowledge: list[dict] | None,
241-
knowledge_id: str | None = None) -> list[tuple[str, str]]:
242-
"""Get list of (kb_id, kb_name) the user can access."""
241+
knowledge_id: str | None = None) -> list[tuple[str, str, str]]:
242+
"""Get list of (kb_id, kb_name, kb_description) the user can access."""
243243
from open_webui.models.access_grants import AccessGrants
244244
from open_webui.models.groups import Groups
245245
from open_webui.models.knowledge import Knowledges
@@ -269,18 +269,18 @@ async def _has_access(kb):
269269
for kb_id in attached_kb_ids:
270270
kb = await Knowledges.get_knowledge_by_id(kb_id)
271271
if kb and await _has_access(kb):
272-
result.append((kb.id, kb.name))
272+
result.append((kb.id, kb.name, kb.description or ''))
273273
elif knowledge_id:
274274
kb = await Knowledges.get_knowledge_by_id(knowledge_id)
275275
if kb and await _has_access(kb):
276-
result.append((kb.id, kb.name))
276+
result.append((kb.id, kb.name, kb.description or ''))
277277
else:
278278
search = await Knowledges.search_knowledge_bases(
279279
user_id, filter={'query': '', 'user_id': user_id, 'group_ids': user_group_ids},
280280
skip=0, limit=50,
281281
)
282282
for kb in search.items:
283-
result.append((kb.id, kb.name))
283+
result.append((kb.id, kb.name, kb.description or ''))
284284

285285
return result
286286

@@ -294,7 +294,7 @@ async def _get_accessible_files(user: dict, model_knowledge: list[dict] | None,
294294
kb_ids = await _get_accessible_kb_ids(user, model_knowledge, knowledge_id)
295295
files = []
296296

297-
for kb_id, kb_name in kb_ids:
297+
for kb_id, kb_name, _ in kb_ids:
298298
kb_files = await Knowledges.get_files_with_directory_ids(kb_id)
299299
for file_model, dir_id in kb_files:
300300
files.append({
@@ -443,22 +443,25 @@ async def _kb_ls(args: list[str], flags: set[str], user: dict,
443443
target_kb_id = None
444444
dir_path = None
445445
if path_arg:
446-
for kb_id, kb_name in kb_ids:
446+
for kb_id, kb_name, _ in kb_ids:
447447
if kb_id == path_arg:
448448
target_kb_id = kb_id
449449
break
450450
if not target_kb_id:
451451
dir_path = path_arg.strip('/')
452452

453453
if target_kb_id:
454-
kb_ids = [(kid, kn) for kid, kn in kb_ids if kid == target_kb_id]
454+
kb_ids = [(kid, kn, kd) for kid, kn, kd in kb_ids if kid == target_kb_id]
455455

456456
if not kb_ids:
457457
return 'No knowledge bases found.'
458458

459459
lines = []
460-
for kb_id, kb_name in kb_ids:
461-
lines.append(f'Knowledge Base: {kb_name} ({kb_id})')
460+
for kb_id, kb_name, kb_desc in kb_ids:
461+
header = f'Knowledge Base: {kb_name} ({kb_id})'
462+
if kb_desc:
463+
header += f'\n {kb_desc}'
464+
lines.append(header)
462465

463466
if flat_mode:
464467
# Flat mode: build full tree (legitimate use)
@@ -921,9 +924,12 @@ async def _kb_tree(args: list[str], flags: set[str], user: dict,
921924
dir_scope = args[0].strip('/') if args else None
922925
output = []
923926

924-
for kb_id, kb_name in kb_ids:
927+
for kb_id, kb_name, kb_desc in kb_ids:
925928
tree = await _build_directory_tree(kb_id)
926-
output.append(f'Knowledge Base: {kb_name} ({kb_id})')
929+
header = f'Knowledge Base: {kb_name} ({kb_id})'
930+
if kb_desc:
931+
header += f'\n {kb_desc}'
932+
output.append(header)
927933

928934
# Find root to start from
929935
root_dir_id = None

0 commit comments

Comments
 (0)