feat: add SQLite write-ahead log and shared memory files.

This commit is contained in:
tinix-ai
2026-04-09 16:19:39 +07:00
parent f12cedf6d0
commit c3a69d145b
68 changed files with 9079 additions and 42 deletions
+3 -3
View File
@@ -15,6 +15,8 @@ from functools import wraps
import logging
from openai import OpenAI, RateLimitError, APIError, AuthenticationError, APIConnectionError
import pickle
import random
import re
from core.config import get_config, Backend
from locales.i18n import t
@@ -296,7 +298,6 @@ class APIClient:
retry_count = 0
base_wait = 1.0
import random
while retry_count < max_retries:
client_info = self._get_next_client(retry_count)
@@ -388,7 +389,6 @@ class APIClient:
response_str = str(response)
# Thử tìm content='...'
import re
content_match = re.search(r"content=(?:'|\")((?:.|\n)*?)(?:'|\"),\s*refusal", response_str)
if content_match:
content = content_match.group(1).replace("\\n", "\n").replace("\\'", "'")
@@ -537,7 +537,7 @@ class APIClient:
retry_count = 0
base_wait = 1.0
import random
while retry_count < max_retries:
client_info = self._get_next_client(retry_count)
+6 -9
View File
@@ -192,7 +192,8 @@ class NovelGenerator:
total_chapters: int,
character_setting: str,
world_setting: str,
plot_idea: str
plot_idea: str,
custom_outline_prompt: str = ""
) -> Tuple[str, str]:
"""
Tạo dàn ý tiểu thuyết
@@ -228,12 +229,15 @@ class NovelGenerator:
sub_genre_details.append(f"- {sg}")
style_desc += f"\n\nCác chủ đề con (Tag) bổ sung:\n" + "\n".join(sub_genre_details) + "\n\nHãy kết hợp chặt chẽ các đặc điểm của những chủ đề này để làm phong phú cấu trúc cốt truyện."
custom_prompt_str = f"Yêu cầu chuyên biệt của tác giả:\n{custom_outline_prompt}\n\n" if custom_outline_prompt.strip() else ""
prompt = t("prompts.outline_user",
genre=genre, title=title,
character_setting=character_setting,
world_setting=world_setting,
plot_idea=plot_idea,
style_desc=style_desc,
custom_prompt=custom_prompt_str,
total_chapters=total_chapters
)
@@ -424,12 +428,8 @@ class NovelGenerator:
if context_summary:
context_prompt = t("prompts.context_prompt", context_summary=context_summary)
# Lấy thông tin thể loại truyện thông qua class properties (cần get từ CSDL dự án hoặc cấu hình, mượn tạm cách try-except)
# Vì hàm `generate_chapter` ko truyền `genre`, ta sẽ thêm tham số hoặc ngầm hiểu thông qua plot/world_setting.
# Tạm thời cứ gán thêm nếu có thể, hoặc yêu cầu truyền thêm `genre` ở hàm gọi. Sẽ cập nhật `system_prompt` chung với outline.
genre_desc_prompt = ""
# TODO: Sắp tới cần update file `app.py` chỗ gọi hàm `generate_chapter` để truyền thêm Genre vào.
prompt = t("prompts.chapter_user",
novel_title=novel_title, chapter_num=chapter_num,
chapter_title=chapter_title, chapter_desc=chapter_desc,
@@ -611,7 +611,6 @@ class NovelGenerator:
# Cơ chế thử lại: thử lại khi nội dung quá ngắn
max_retries = 3
content = ""
success_msg = ""
for attempt in range(max_retries):
logger.debug(f"Rewrite attempt {attempt + 1}/{max_retries}")
@@ -754,7 +753,6 @@ class NovelGenerator:
# Cơ chế thử lại: thử lại khi nội dung quá ngắn
max_retries = 3
content = ""
success_msg = ""
for attempt in range(max_retries):
logger.debug(f"Polish attempt {attempt + 1}/{max_retries}")
@@ -969,7 +967,6 @@ class NovelGenerator:
# Cơ chế thử lại
max_retries = 3
content = ""
success_msg = ""
for attempt in range(max_retries):
logger.debug(f"Continue attempt {attempt + 1}/{max_retries}")
+1 -1
View File
@@ -161,7 +161,7 @@ class ProjectManager:
sg_str = "[]"
try:
sg_list = json.loads(sg_str) if sg_str else []
except:
except (json.JSONDecodeError, TypeError, ValueError):
sg_list = []
# Xây dựng lại dự án