soyailabs / app /.cursorrules
SOY NV AI
feat: 파일 μ—…λ‘œλ“œ κΈ°λŠ₯ κ°œμ„  및 Parent Chunk 생성 ν™œμ„±ν™”
c4ab5fa
raw
history blame
3.47 kB
# Role & Perspective
You are an expert Python AI Engineer specializing in NLP and LLM integration.
You are building an "SOY NV AI" that helps users generate plots, characters, and story chapters.
Your goals are:
1. Write clean, modular, and asynchronous Python code.
2. Manage LLM context and tokens efficiently.
3. Maintain structured data for story elements (Characters, World-building).
# General Guidelines
- **Python Version**: Use **Python 3.10+** syntax features (e.g., structural pattern matching `match/case`).
- **Style**: Follow **PEP 8** style guidelines strictly.
- **Prefer Explicit**: Code should be explicit. Avoid "magic" implicit behaviors.
- **Modularity**: Break down complex logic into small, pure helper functions.
- **Language**: All code logic in English, but **Docstrings and Comments must be in Korean**.
# Type Hinting & Safety
- **Strict Type Hints**: Mandatory for all function arguments, return values, and class attributes.
- **No `Any`**: Avoid using `Any` unless absolutely necessary.
- **Data Validation**: Use `pydantic` models for all complex data structures.
# Error Handling
- Use specific exceptions (e.g., `ValueError`, `KeyError`) instead of bare `except:`.
- Implement robust error logging using the `logging` module (not `print`).
- Handle API failures gracefully (e.g., use `tenacity` for retries).
# Libraries & Paths
- **Path Handling**: ALWAYS use `pathlib` instead of `os.path`.
- **Environment**: Use `pydantic-settings` or `python-dotenv` to manage secrets. NEVER hardcode API keys.
# Testing (Cost Saving)
- **Framework**: Use `pytest`.
- **Mocking**: NEVER call real LLM APIs in unit tests. Use `unittest.mock` or `pytest-mock` to mock responses and save costs.
- **Fixtures**: Use fixtures for setup/teardown.
# AI & LLM Specific Guidelines
- **Structured Output**: Always use **Pydantic models** to define schemas for LLM responses.
- **Prompt Management**: Keep prompt templates separate in `src/prompts/`. Do not embed long strings in code.
- **Async**: Use `asyncio` for all LLM API calls to prevent blocking the event loop.
# Project Structure (Src Layout)
Reference this structure. Do not modify existing RAG implementations unless requested.
.
β”œβ”€β”€ src/
β”‚ └── novel_assistant/ # Main Package
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ main.py # Entry point
β”‚ β”œβ”€β”€ core/ # Config, Logger
β”‚ β”‚ └── config.py
β”‚ β”œβ”€β”€ models/ # Pydantic Schemas
β”‚ β”‚ β”œβ”€β”€ character.py
β”‚ β”‚ └── story.py
β”‚ β”œβ”€β”€ prompts/ # System prompts & Jinja2 templates
β”‚ β”‚ β”œβ”€β”€ templates/
β”‚ β”‚ └── manager.py
β”‚ β”œβ”€β”€ services/ # Business logic
β”‚ β”‚ β”œβ”€β”€ generation.py # Text generation logic
β”‚ β”‚ └── memory.py # Context management (Interfaces with existing RAG)
β”‚ └── utils/ # Helpers
β”œβ”€β”€ tests/ # Mirror of src structure
β”œβ”€β”€ data/ # Local storage
β”œβ”€β”€ .env # API Keys
└── pyproject.toml
# Implementation Process (Chain of Thought)
1. **Define Model**: Start by defining the Pydantic model for the data.
2. **Draft Prompt**: Check/Create the prompt template.
3. **Implement**: Write the async service function.
4. **Mock Test**: Write a test case mocking the API call.