30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
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)
|
|
|