mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
refactor document pydantic schemas a bit
This commit is contained in:
@@ -57,7 +57,7 @@ async def get_document(
|
||||
"""Get a document by path."""
|
||||
try:
|
||||
document, content = await service.read_document(path)
|
||||
response = DocumentResponse.from_orm(document)
|
||||
response = DocumentResponse.model_validate(document)
|
||||
response.content = content
|
||||
return response
|
||||
except DocumentNotFoundError:
|
||||
@@ -77,7 +77,7 @@ async def update_document(
|
||||
document = await service.update_document(
|
||||
path=path,
|
||||
content=doc.content,
|
||||
metadata=doc.metadata,
|
||||
metadata=doc.doc_metadata,
|
||||
)
|
||||
return DocumentResponse.model_validate(document)
|
||||
except DocumentNotFoundError:
|
||||
@@ -104,7 +104,7 @@ async def patch_document(
|
||||
document = await service.update_document(
|
||||
path=path,
|
||||
content=patch.content,
|
||||
metadata=patch.metadata,
|
||||
metadata=patch.doc_metadata,
|
||||
)
|
||||
return DocumentResponse.from_orm(document)
|
||||
except DocumentNotFoundError:
|
||||
|
||||
@@ -216,14 +216,18 @@ class CreateRelationsRequest(BaseModel):
|
||||
class DocumentCreate(BaseModel):
|
||||
path: str
|
||||
content: str
|
||||
metadata: Optional[Dict[str, Any]] = None
|
||||
doc_metadata: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
class DocumentUpdate(BaseModel):
|
||||
id: int
|
||||
checksum: str
|
||||
content: str
|
||||
metadata: Optional[Dict[str, Any]] = None
|
||||
doc_metadata: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
class DocumentPatch(BaseModel):
|
||||
id: int
|
||||
checksum: str
|
||||
content: Optional[str] = None
|
||||
metadata: Optional[Dict[str, Any]] = None
|
||||
doc_metadata: Optional[Dict[str, Any]] = None
|
||||
|
||||
@@ -11,11 +11,12 @@ Key Features:
|
||||
4. Bulk operations return all affected items
|
||||
"""
|
||||
|
||||
from typing import List, Optional, Dict, Any
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from basic_memory.schemas.base import Observation, EntityId, Relation
|
||||
from basic_memory.schemas.request import DocumentCreate
|
||||
|
||||
|
||||
class SQLAlchemyModel(BaseModel):
|
||||
@@ -326,13 +327,8 @@ class DeleteObservationsResponse(SQLAlchemyModel):
|
||||
deleted: bool
|
||||
|
||||
|
||||
class DocumentResponse(BaseModel):
|
||||
class DocumentResponse(DocumentCreate, SQLAlchemyModel):
|
||||
id: int
|
||||
path: str
|
||||
checksum: str
|
||||
doc_metadata: Optional[Dict[str, Any]] = None
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
Reference in New Issue
Block a user