fix: 优化架构
This commit is contained in:
29
engine/adapters/llm/openai_adapter.py
Normal file
29
engine/adapters/llm/openai_adapter.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from engine.config import AppConfig
|
||||
from engine.script_gen import generate_scenes, refine_scene
|
||||
|
||||
from .base import BaseLLM
|
||||
|
||||
|
||||
class OpenAIAdapter(BaseLLM):
|
||||
def __init__(self, cfg: AppConfig):
|
||||
self.cfg = cfg
|
||||
|
||||
def generate_script(self, prompt: str, context: dict[str, Any] | None = None):
|
||||
# Existing script_gen already enforces JSON schema and length constraints.
|
||||
return generate_scenes(prompt, self.cfg)
|
||||
|
||||
def refine_scene(self, scene: Any, context: dict[str, Any] | None = None):
|
||||
if context is None:
|
||||
context = {}
|
||||
# Context carries needed values to call refine_scene in script_gen.
|
||||
scenes = context.get("scenes")
|
||||
prompt2 = context.get("prompt")
|
||||
target_index = context.get("target_index")
|
||||
if scenes is None or prompt2 is None or target_index is None:
|
||||
raise ValueError("OpenAIAdapter.refine_scene missing context: scenes/prompt/target_index")
|
||||
return refine_scene(prompt=prompt2, scenes=scenes, target_index=int(target_index), cfg=self.cfg)
|
||||
|
||||
Reference in New Issue
Block a user