Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:869413421 Ai moive studio MovieCharacterService extract characters from chapter

From Leeroopedia
Knowledge Sources
Domains NLP, Story_Analysis
Last Updated 2026-10-23 12:00 GMT

Overview

Service that extracts structured character profiles from chapter text using an LLM, with smart name normalization and three-view prompt generation.

Description

MovieCharacterService.extract_characters_from_chapter loads chapter content (up to 5000 chars), optionally augments with existing script scenes/shots, and sends it to an LLM with a casting director system prompt. The LLM returns JSON with character profiles including name, era_background, occupation, role_description, visual_traits, key_visual_traits, and dialogue_traits.

The service performs smart name matching: it normalizes names by removing parenthetical aliases (e.g., "阿尔德里克 (Aldric)" → "阿尔德里克") and matches against existing characters to update rather than duplicate. Each new or updated character also gets a generated_prompt (three-view prompt) built by CharacterThreeViewPromptBuilder.

Usage

Import when extracting characters for AI movie generation. Called by the movie generation Celery task at the start of the pipeline.

Code Reference

Source Location

  • Repository: ai-moive-studio
  • File: backend/src/services/movie_character_service.py:L168-300

Signature

class MovieCharacterService(BaseService):
    async def extract_characters_from_chapter(
        self,
        chapter_id: str,
        api_key_id: str,
        model: str = None
    ) -> List[MovieCharacter]:
        """
        Args:
            chapter_id: chapter UUID
            api_key_id: API key UUID
            model: LLM model name

        Returns:
            List of MovieCharacter objects (new + updated)
        """

Import

from src.services.movie_character_service import MovieCharacterService

I/O Contract

Inputs

Name Type Required Description
chapter_id str Yes Chapter UUID
api_key_id str Yes API key UUID
model str No LLM model name

Outputs

Name Type Description
return value List[MovieCharacter] Character objects with name, traits, generated_prompt
DB side effects — Creates or updates MovieCharacter records

Usage Examples

Extracting Characters

from src.services.movie_character_service import MovieCharacterService

service = MovieCharacterService(db_session)
characters = await service.extract_characters_from_chapter(
    chapter_id="chapter-uuid",
    api_key_id="key-uuid",
    model="gpt-4o",
)
for char in characters:
    print(f"{char.name}: {char.key_visual_traits}")

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment