feat: 添加日志记录功能,输出至 app.log 文件
This commit is contained in:
@@ -12,3 +12,5 @@ config_test.json
|
|||||||
/novel_generator/__pycache__
|
/novel_generator/__pycache__
|
||||||
/ui/__pycache__
|
/ui/__pycache__
|
||||||
.idea/
|
.idea/
|
||||||
|
/novel
|
||||||
|
app.log
|
||||||
@@ -16,6 +16,13 @@ from prompt_definitions import (
|
|||||||
plot_architecture_prompt,
|
plot_architecture_prompt,
|
||||||
create_character_state_prompt
|
create_character_state_prompt
|
||||||
)
|
)
|
||||||
|
logging.basicConfig(
|
||||||
|
filename='app.log', # 日志文件名
|
||||||
|
filemode='a', # 追加模式('w' 会覆盖)
|
||||||
|
level=logging.INFO, # 记录 INFO 及以上级别的日志
|
||||||
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
|
datefmt='%Y-%m-%d %H:%M:%S'
|
||||||
|
)
|
||||||
from utils import clear_file_content, save_string_to_txt
|
from utils import clear_file_content, save_string_to_txt
|
||||||
|
|
||||||
def load_partial_architecture_data(filepath: str) -> dict:
|
def load_partial_architecture_data(filepath: str) -> dict:
|
||||||
|
|||||||
@@ -10,7 +10,13 @@ from novel_generator.common import invoke_with_cleaning
|
|||||||
from llm_adapters import create_llm_adapter
|
from llm_adapters import create_llm_adapter
|
||||||
from prompt_definitions import chapter_blueprint_prompt, chunked_chapter_blueprint_prompt
|
from prompt_definitions import chapter_blueprint_prompt, chunked_chapter_blueprint_prompt
|
||||||
from utils import read_file, clear_file_content, save_string_to_txt
|
from utils import read_file, clear_file_content, save_string_to_txt
|
||||||
|
logging.basicConfig(
|
||||||
|
filename='app.log', # 日志文件名
|
||||||
|
filemode='a', # 追加模式('w' 会覆盖)
|
||||||
|
level=logging.INFO, # 记录 INFO 及以上级别的日志
|
||||||
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
|
datefmt='%Y-%m-%d %H:%M:%S'
|
||||||
|
)
|
||||||
def compute_chunk_size(number_of_chapters: int, max_tokens: int) -> int:
|
def compute_chunk_size(number_of_chapters: int, max_tokens: int) -> int:
|
||||||
"""
|
"""
|
||||||
基于“每章约100 tokens”的粗略估算,
|
基于“每章约100 tokens”的粗略估算,
|
||||||
@@ -18,7 +24,7 @@ def compute_chunk_size(number_of_chapters: int, max_tokens: int) -> int:
|
|||||||
chunk_size = (floor(max_tokens/100/10)*10) - 10
|
chunk_size = (floor(max_tokens/100/10)*10) - 10
|
||||||
并确保 chunk_size 不会小于1或大于实际章节数。
|
并确保 chunk_size 不会小于1或大于实际章节数。
|
||||||
"""
|
"""
|
||||||
tokens_per_chapter = 100.0
|
tokens_per_chapter = 200.0
|
||||||
ratio = max_tokens / tokens_per_chapter
|
ratio = max_tokens / tokens_per_chapter
|
||||||
ratio_rounded_to_10 = int(ratio // 10) * 10
|
ratio_rounded_to_10 = int(ratio // 10) * 10
|
||||||
chunk_size = ratio_rounded_to_10 - 10
|
chunk_size = ratio_rounded_to_10 - 10
|
||||||
|
|||||||
@@ -22,6 +22,13 @@ from novel_generator.vectorstore_utils import (
|
|||||||
get_relevant_context_from_vector_store,
|
get_relevant_context_from_vector_store,
|
||||||
load_vector_store # 添加导入
|
load_vector_store # 添加导入
|
||||||
)
|
)
|
||||||
|
logging.basicConfig(
|
||||||
|
filename='app.log', # 日志文件名
|
||||||
|
filemode='a', # 追加模式('w' 会覆盖)
|
||||||
|
level=logging.INFO, # 记录 INFO 及以上级别的日志
|
||||||
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
|
datefmt='%Y-%m-%d %H:%M:%S'
|
||||||
|
)
|
||||||
|
|
||||||
def get_last_n_chapters_text(chapters_dir: str, current_chapter_num: int, n: int = 3) -> list:
|
def get_last_n_chapters_text(chapters_dir: str, current_chapter_num: int, n: int = 3) -> list:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -7,7 +7,13 @@ import logging
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
logging.basicConfig(
|
||||||
|
filename='app.log', # 日志文件名
|
||||||
|
filemode='a', # 追加模式('w' 会覆盖)
|
||||||
|
level=logging.INFO, # 记录 INFO 及以上级别的日志
|
||||||
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
|
datefmt='%Y-%m-%d %H:%M:%S'
|
||||||
|
)
|
||||||
def call_with_retry(func, max_retries=3, sleep_time=2, fallback_return=None, **kwargs):
|
def call_with_retry(func, max_retries=3, sleep_time=2, fallback_return=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
通用的重试机制封装。
|
通用的重试机制封装。
|
||||||
|
|||||||
@@ -11,7 +11,13 @@ from prompt_definitions import summary_prompt, update_character_state_prompt
|
|||||||
from novel_generator.common import invoke_with_cleaning
|
from novel_generator.common import invoke_with_cleaning
|
||||||
from utils import read_file, clear_file_content, save_string_to_txt
|
from utils import read_file, clear_file_content, save_string_to_txt
|
||||||
from novel_generator.vectorstore_utils import update_vector_store
|
from novel_generator.vectorstore_utils import update_vector_store
|
||||||
|
logging.basicConfig(
|
||||||
|
filename='app.log', # 日志文件名
|
||||||
|
filemode='a', # 追加模式('w' 会覆盖)
|
||||||
|
level=logging.INFO, # 记录 INFO 及以上级别的日志
|
||||||
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
|
datefmt='%Y-%m-%d %H:%M:%S'
|
||||||
|
)
|
||||||
def finalize_chapter(
|
def finalize_chapter(
|
||||||
novel_number: int,
|
novel_number: int,
|
||||||
word_number: int,
|
word_number: int,
|
||||||
|
|||||||
@@ -16,11 +16,17 @@ from langchain.docstore.document import Document
|
|||||||
# 禁用特定的Torch警告
|
# 禁用特定的Torch警告
|
||||||
warnings.filterwarnings('ignore', message='.*Torch was not compiled with flash attention.*')
|
warnings.filterwarnings('ignore', message='.*Torch was not compiled with flash attention.*')
|
||||||
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
||||||
|
logging.basicConfig(
|
||||||
|
filename='app.log', # 日志文件名
|
||||||
|
filemode='a', # 追加模式('w' 会覆盖)
|
||||||
|
level=logging.INFO, # 记录 INFO 及以上级别的日志
|
||||||
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
|
datefmt='%Y-%m-%d %H:%M:%S'
|
||||||
|
)
|
||||||
def advanced_split_content(content: str, similarity_threshold: float = 0.7, max_length: int = 500) -> list:
|
def advanced_split_content(content: str, similarity_threshold: float = 0.7, max_length: int = 500) -> list:
|
||||||
"""使用基本分段策略"""
|
"""使用基本分段策略"""
|
||||||
nltk.download('punkt', quiet=True)
|
# nltk.download('punkt', quiet=True)
|
||||||
nltk.download('punkt_tab', quiet=True)
|
# nltk.download('punkt_tab', quiet=True)
|
||||||
sentences = nltk.sent_tokenize(content)
|
sentences = nltk.sent_tokenize(content)
|
||||||
if not sentences:
|
if not sentences:
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -13,7 +13,13 @@ import ssl
|
|||||||
import requests
|
import requests
|
||||||
import warnings
|
import warnings
|
||||||
from langchain_chroma import Chroma
|
from langchain_chroma import Chroma
|
||||||
|
logging.basicConfig(
|
||||||
|
filename='app.log', # 日志文件名
|
||||||
|
filemode='a', # 追加模式('w' 会覆盖)
|
||||||
|
level=logging.INFO, # 记录 INFO 及以上级别的日志
|
||||||
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
|
datefmt='%Y-%m-%d %H:%M:%S'
|
||||||
|
)
|
||||||
# 禁用特定的Torch警告
|
# 禁用特定的Torch警告
|
||||||
warnings.filterwarnings('ignore', message='.*Torch was not compiled with flash attention.*')
|
warnings.filterwarnings('ignore', message='.*Torch was not compiled with flash attention.*')
|
||||||
os.environ["TOKENIZERS_PARALLELISM"] = "false" # 禁用tokenizer并行警告
|
os.environ["TOKENIZERS_PARALLELISM"] = "false" # 禁用tokenizer并行警告
|
||||||
@@ -146,8 +152,8 @@ def split_text_for_vectorstore(chapter_text: str, max_length: int = 500, similar
|
|||||||
if not chapter_text.strip():
|
if not chapter_text.strip():
|
||||||
return []
|
return []
|
||||||
|
|
||||||
nltk.download('punkt', quiet=True)
|
# nltk.download('punkt', quiet=True)
|
||||||
nltk.download('punkt_tab', quiet=True)
|
# nltk.download('punkt_tab', quiet=True)
|
||||||
sentences = nltk.sent_tokenize(chapter_text)
|
sentences = nltk.sent_tokenize(chapter_text)
|
||||||
if not sentences:
|
if not sentences:
|
||||||
return []
|
return []
|
||||||
|
|||||||
Reference in New Issue
Block a user