sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)
This commit is contained in:
1 parent
4f7f07504a
commit
8bc8b0e082
1651 files changed
+278599
-11416
No files matched your search
+120
-3
@@ -3,13 +3,19 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
from typing import Any, cast
|
||||
from uuid import uuid4
|
||||
|
||||
from sqlalchemy import delete, or_, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
||||
|
||||
from deerflow.persistence.llmwiki.base import LlmWikiScope, LlmWikiStore
|
||||
from deerflow.persistence.llmwiki.base import (
|
||||
UNSET,
|
||||
LlmWikiScope,
|
||||
LlmWikiStore,
|
||||
serialize_wiki_directory_paths,
|
||||
serialize_wiki_parent_directories,
|
||||
)
|
||||
from deerflow.persistence.llmwiki.model import LlmWikiConversationDepositRow, LlmWikiKnowledgeBaseRow
|
||||
|
||||
|
||||
@@ -19,6 +25,14 @@ def _now() -> datetime:
|
||||
|
||||
def _to_dict(row: LlmWikiKnowledgeBaseRow | LlmWikiConversationDepositRow) -> dict[str, Any]:
|
||||
data = row.to_dict()
|
||||
if "wiki_parent_directories" in data:
|
||||
data["wiki_parent_directories"] = serialize_wiki_parent_directories(
|
||||
data["wiki_parent_directories"]
|
||||
)
|
||||
if "wiki_directory_paths" in data:
|
||||
data["wiki_directory_paths"] = serialize_wiki_directory_paths(
|
||||
data["wiki_directory_paths"]
|
||||
)
|
||||
for key in ("published_at", "external_search_updated_at", "created_at", "updated_at"):
|
||||
value = data.get(key)
|
||||
if isinstance(value, datetime):
|
||||
@@ -30,13 +44,51 @@ class LlmWikiRepository(LlmWikiStore):
|
||||
def __init__(self, session_factory: async_sessionmaker[AsyncSession]) -> None:
|
||||
self._sf = session_factory
|
||||
|
||||
async def create_mapping(self, *, weknora_id: str, owner_user_id: str, name: str, description: str, kb_type: str) -> dict[str, Any]:
|
||||
async def create_mapping(
|
||||
self,
|
||||
*,
|
||||
weknora_id: str,
|
||||
owner_user_id: str,
|
||||
name: str,
|
||||
description: str,
|
||||
kb_type: str,
|
||||
retrieval_settings: dict[str, Any] | None = None,
|
||||
wiki_parent_directories: list[str] | None = None,
|
||||
wiki_directory_paths: list[list[str]] | None = None,
|
||||
wiki_focus_instructions: str | None = None,
|
||||
wiki_content_instructions_raw: str | None = None,
|
||||
wiki_extraction_instructions_raw: str | None = None,
|
||||
wiki_generation_managed: bool | None = None,
|
||||
wiki_config_schema_version: int | None = None,
|
||||
wiki_config_revision: int | None = None,
|
||||
wiki_config_apply_status: str | None = None,
|
||||
wiki_config_apply_error: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
row = LlmWikiKnowledgeBaseRow(
|
||||
id=str(uuid4()),
|
||||
weknora_id=weknora_id,
|
||||
owner_user_id=owner_user_id,
|
||||
name=name,
|
||||
description=description,
|
||||
retrieval_settings=(
|
||||
dict(retrieval_settings)
|
||||
if retrieval_settings is not None
|
||||
else None
|
||||
),
|
||||
wiki_parent_directories=serialize_wiki_parent_directories(
|
||||
wiki_parent_directories
|
||||
),
|
||||
wiki_directory_paths=serialize_wiki_directory_paths(
|
||||
wiki_directory_paths
|
||||
),
|
||||
wiki_focus_instructions=wiki_focus_instructions,
|
||||
wiki_content_instructions_raw=wiki_content_instructions_raw,
|
||||
wiki_extraction_instructions_raw=wiki_extraction_instructions_raw,
|
||||
wiki_generation_managed=wiki_generation_managed,
|
||||
wiki_config_schema_version=wiki_config_schema_version,
|
||||
wiki_config_revision=wiki_config_revision,
|
||||
wiki_config_apply_status=wiki_config_apply_status,
|
||||
wiki_config_apply_error=wiki_config_apply_error,
|
||||
kb_type=kb_type,
|
||||
publication_status="private",
|
||||
created_at=_now(),
|
||||
@@ -88,8 +140,21 @@ class LlmWikiRepository(LlmWikiStore):
|
||||
*,
|
||||
name: str | None = None,
|
||||
description: str | None = None,
|
||||
test_questions: list[str] | None = None,
|
||||
test_questions_set: bool = False,
|
||||
retrieval_settings: dict[str, Any] | None = None,
|
||||
wiki_index_enabled: bool | None = None,
|
||||
external_search_enabled: bool | None = None,
|
||||
wiki_parent_directories: list[str] | None | object = UNSET,
|
||||
wiki_directory_paths: list[list[str]] | None | object = UNSET,
|
||||
wiki_focus_instructions: str | None | object = UNSET,
|
||||
wiki_content_instructions_raw: str | None | object = UNSET,
|
||||
wiki_extraction_instructions_raw: str | None | object = UNSET,
|
||||
wiki_generation_managed: bool | None | object = UNSET,
|
||||
wiki_config_schema_version: int | None | object = UNSET,
|
||||
wiki_config_revision: int | None | object = UNSET,
|
||||
wiki_config_apply_status: str | None | object = UNSET,
|
||||
wiki_config_apply_error: str | None | object = UNSET,
|
||||
) -> dict[str, Any] | None:
|
||||
async with self._sf() as session:
|
||||
row = await session.get(LlmWikiKnowledgeBaseRow, mapping_id)
|
||||
@@ -99,11 +164,63 @@ class LlmWikiRepository(LlmWikiStore):
|
||||
row.name = name
|
||||
if description is not None:
|
||||
row.description = description
|
||||
if test_questions_set:
|
||||
row.test_questions = list(test_questions or [])
|
||||
if retrieval_settings is not None:
|
||||
row.retrieval_settings = dict(retrieval_settings)
|
||||
if wiki_index_enabled is not None:
|
||||
row.wiki_index_enabled = wiki_index_enabled
|
||||
if external_search_enabled is not None:
|
||||
row.external_search_enabled = external_search_enabled
|
||||
row.external_search_updated_at = _now()
|
||||
if wiki_parent_directories is not UNSET:
|
||||
row.wiki_parent_directories = serialize_wiki_parent_directories(
|
||||
cast(list[str] | None, wiki_parent_directories)
|
||||
)
|
||||
if wiki_directory_paths is not UNSET:
|
||||
row.wiki_directory_paths = serialize_wiki_directory_paths(
|
||||
cast(list[list[str]] | None, wiki_directory_paths)
|
||||
)
|
||||
if wiki_focus_instructions is not UNSET:
|
||||
row.wiki_focus_instructions = cast(
|
||||
str | None,
|
||||
wiki_focus_instructions,
|
||||
)
|
||||
if wiki_content_instructions_raw is not UNSET:
|
||||
row.wiki_content_instructions_raw = cast(
|
||||
str | None,
|
||||
wiki_content_instructions_raw,
|
||||
)
|
||||
if wiki_extraction_instructions_raw is not UNSET:
|
||||
row.wiki_extraction_instructions_raw = cast(
|
||||
str | None,
|
||||
wiki_extraction_instructions_raw,
|
||||
)
|
||||
if wiki_generation_managed is not UNSET:
|
||||
row.wiki_generation_managed = cast(
|
||||
bool | None,
|
||||
wiki_generation_managed,
|
||||
)
|
||||
if wiki_config_schema_version is not UNSET:
|
||||
row.wiki_config_schema_version = cast(
|
||||
int | None,
|
||||
wiki_config_schema_version,
|
||||
)
|
||||
if wiki_config_revision is not UNSET:
|
||||
row.wiki_config_revision = cast(
|
||||
int | None,
|
||||
wiki_config_revision,
|
||||
)
|
||||
if wiki_config_apply_status is not UNSET:
|
||||
row.wiki_config_apply_status = cast(
|
||||
str | None,
|
||||
wiki_config_apply_status,
|
||||
)
|
||||
if wiki_config_apply_error is not UNSET:
|
||||
row.wiki_config_apply_error = cast(
|
||||
str | None,
|
||||
wiki_config_apply_error,
|
||||
)
|
||||
row.updated_at = _now()
|
||||
await session.commit()
|
||||
return _to_dict(row)
|
||||
|
||||
Reference in new issue
Block a user