updated series_index to float and added UniqueConstraint to audiobook and audiobook_author

This commit is contained in:
2026-06-10 20:07:27 -04:00
parent c25f973d4a
commit 5f08932007
6 changed files with 307 additions and 20 deletions
+10 -7
View File
@@ -19,6 +19,7 @@ from python.tools.audiobook.llm_tool_calling import (
optional_int,
parse_tool_calls,
required_int,
required_series_index,
required_string,
run_tool_calls,
validate_catalog_slug,
@@ -67,7 +68,7 @@ class StandardBookMetadata:
title: str
series_id: int | None
series: str
series_index: int
series_index: float
confidence: float
needs_review: bool
evidence: list[str]
@@ -81,7 +82,7 @@ class FinalMetadataFields:
book_id: int | None
title: str
series_id: int | None
series_index: int
series_index: float
confidence: float
evidence: list[str]
@@ -93,7 +94,7 @@ class ResolvedBookFields:
book_id: int | None
title: str
series_id: int | None
series_index: int
series_index: float
@dataclass(frozen=True)
@@ -283,7 +284,7 @@ class AudiobookMetadataAgent:
"model": self._config.model,
"messages": messages,
"stream": False,
"options": {"temperature": 0},
"options": {"temperature": 0.1},
}
tool_names = []
if tools_enabled:
@@ -403,7 +404,7 @@ class AudiobookMetadataAgent:
series_index=book.series_index,
)
def validate_series(self, author_id: int, series_id: int | None, series_index: int) -> str:
def validate_series(self, author_id: int, series_id: int | None, series_index: float) -> str:
"""Validate final series fields and return the canonical series slug."""
if series_id is None:
if series_index != 0:
@@ -467,7 +468,9 @@ Rules:
- The final JSON object must contain author_id, book_id, title, series_id, series_index, confidence, and evidence.
- title must be a canonical title slug using lower-case words separated by hyphens.
- Use series_id null and series_index 0 for standalone books.
- If you use a series_id, series_index must be an integer greater than or equal to 1.
- If you use a series_id, series_index must be a whole number or .5 value greater than 0.
- Treat series slugs that differ only by underscores as the same series. Prefer the existing catalog row instead of
creating a new series.
- Detect omnibus or box-set editions that contain multiple numbered novels, books, or novellas.
- For an omnibus, make a best-effort range from the filename, tags, and catalog rows. Keep series_index as the
first covered book number and include the range in the title when the source title includes it, for example
@@ -524,7 +527,7 @@ def parse_final_metadata_fields(raw_metadata: object) -> FinalMetadataFields:
book_id=optional_int(data.get("book_id"), "book_id"),
title=required_string(data, "title"),
series_id=optional_int(data.get("series_id"), "series_id"),
series_index=required_int(data, "series_index"),
series_index=required_series_index(data, "series_index"),
confidence=required_float(data, "confidence"),
evidence=required_string_list(data, "evidence"),
)