mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-27 16:04:21 +00:00
fix: show
This commit is contained in:
@@ -194,6 +194,8 @@ class KnowledgeMigrationRouterGroup(group.RouterGroup):
|
|||||||
except Exception:
|
except Exception:
|
||||||
engine_id_set = set()
|
engine_id_set = set()
|
||||||
|
|
||||||
|
task_context.trace(f'Found {len(rows)} external KB(s) to restore. Available engines: {engine_id_set}')
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
row_dict = dict(zip(columns, row))
|
row_dict = dict(zip(columns, row))
|
||||||
kb_uuid = row_dict.get('uuid')
|
kb_uuid = row_dict.get('uuid')
|
||||||
@@ -209,14 +211,10 @@ class KnowledgeMigrationRouterGroup(group.RouterGroup):
|
|||||||
mapped_plugin_name = EXTERNAL_PLUGIN_NAME_MAPPING.get(plugin_name, plugin_name)
|
mapped_plugin_name = EXTERNAL_PLUGIN_NAME_MAPPING.get(plugin_name, plugin_name)
|
||||||
external_plugin_id = f'{plugin_author}/{mapped_plugin_name}'
|
external_plugin_id = f'{plugin_author}/{mapped_plugin_name}'
|
||||||
|
|
||||||
if external_plugin_id not in engine_id_set:
|
task_context.trace(
|
||||||
warning = (
|
f'Processing external KB "{name}" ({kb_uuid}): '
|
||||||
f'External KB "{name}" ({kb_uuid}) uses plugin {external_plugin_id} '
|
f'old_plugin={plugin_author}/{plugin_name}, mapped={external_plugin_id}'
|
||||||
f'which is not available as a Knowledge Engine. Skipped.'
|
)
|
||||||
)
|
|
||||||
warnings.append(warning)
|
|
||||||
task_context.trace(warning)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Parse retriever_config
|
# Parse retriever_config
|
||||||
if isinstance(retriever_config, str):
|
if isinstance(retriever_config, str):
|
||||||
@@ -235,6 +233,14 @@ class KnowledgeMigrationRouterGroup(group.RouterGroup):
|
|||||||
creation_settings_dict = {k: v for k, v in retriever_config.items() if k in creation_fields}
|
creation_settings_dict = {k: v for k, v in retriever_config.items() if k in creation_fields}
|
||||||
retrieval_settings_dict = {k: v for k, v in retriever_config.items() if k not in creation_fields}
|
retrieval_settings_dict = {k: v for k, v in retriever_config.items() if k not in creation_fields}
|
||||||
|
|
||||||
|
task_context.trace(
|
||||||
|
f'Inserting external KB "{name}" into knowledge_bases table '
|
||||||
|
f'(plugin_id={external_plugin_id}, creation_settings={json.dumps(creation_settings_dict)}, '
|
||||||
|
f'retrieval_settings={json.dumps(retrieval_settings_dict)})'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Always insert the KB record so it shows in frontend,
|
||||||
|
# even if the connector plugin is not yet installed.
|
||||||
await self.ap.persistence_mgr.execute_async(
|
await self.ap.persistence_mgr.execute_async(
|
||||||
sqlalchemy.text(
|
sqlalchemy.text(
|
||||||
'INSERT INTO knowledge_bases '
|
'INSERT INTO knowledge_bases '
|
||||||
@@ -256,13 +262,23 @@ class KnowledgeMigrationRouterGroup(group.RouterGroup):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
if external_plugin_id not in engine_id_set:
|
||||||
await self.ap.plugin_connector.rag_on_kb_create(external_plugin_id, kb_uuid, creation_settings_dict)
|
warning = (
|
||||||
task_context.trace(f'Restored external KB: {name} ({kb_uuid})')
|
f'External KB "{name}" ({kb_uuid}) record saved, but plugin {external_plugin_id} '
|
||||||
except Exception as e:
|
f'is not installed yet. Install the connector plugin to use it.'
|
||||||
warning = f'Failed to notify plugin for external KB {name} ({kb_uuid}): {e}'
|
)
|
||||||
warnings.append(warning)
|
warnings.append(warning)
|
||||||
task_context.trace(warning)
|
task_context.trace(warning)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
await self.ap.plugin_connector.rag_on_kb_create(
|
||||||
|
external_plugin_id, kb_uuid, creation_settings_dict
|
||||||
|
)
|
||||||
|
task_context.trace(f'Restored external KB: {name} ({kb_uuid})')
|
||||||
|
except Exception as e:
|
||||||
|
warning = f'Failed to notify plugin for external KB {name} ({kb_uuid}): {e}'
|
||||||
|
warnings.append(warning)
|
||||||
|
task_context.trace(warning)
|
||||||
|
|
||||||
# Reload again after external KBs
|
# Reload again after external KBs
|
||||||
await self.ap.rag_mgr.load_knowledge_bases_from_db()
|
await self.ap.rag_mgr.load_knowledge_bases_from_db()
|
||||||
|
|||||||
Reference in New Issue
Block a user