mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-07-24 07:31:02 +08:00
fix(core): stop blocking the event loop in OpenAI parsing and static routing
OpenAIParser now uses AsyncOpenAI — the previous sync SDK call ran directly on the event loop (submitting to a ThreadPoolExecutor and immediately blocking on .result() serialized it anyway). TitleParser.raw_parser and its callers become async accordingly. The SPA catch-all route listed dist/ on every request; snapshot it once at startup. The module-level bangumi TTL cache is now lock-guarded — it is written from asyncio.to_thread workers in notification paths while the event loop reads it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014w1Z6Nxy6XTRgkFXqPr9Zh
This commit is contained in:
@@ -57,14 +57,14 @@ class TitleParser:
|
||||
logger.warning("Please change bangumi info manually.")
|
||||
|
||||
@staticmethod
|
||||
def raw_parser(raw: str) -> Bangumi | None:
|
||||
async def raw_parser(raw: str) -> Bangumi | None:
|
||||
language = settings.rss_parser.language
|
||||
try:
|
||||
# use OpenAI ChatGPT to parse raw title and get structured data
|
||||
if settings.experimental_openai.enable:
|
||||
kwargs = settings.experimental_openai.dict(exclude={"enable"})
|
||||
gpt = OpenAIParser(**kwargs)
|
||||
episode_dict = gpt.parse(raw, asdict=True)
|
||||
episode_dict = await gpt.parse(raw, asdict=True)
|
||||
episode = Episode(**episode_dict)
|
||||
else:
|
||||
episode = raw_parser(raw)
|
||||
|
||||
Reference in New Issue
Block a user