# 프롬프트 생성기 개발 V5: 사용자 입력 처리 및 2단계 프롬프트 생성 구현 > 2025년 12월 3일 ## 개발 목표 V4의 성공적인 테스트를 바탕으로, 이제 스크립트를 한 단계 더 발전시킨다. 1. 하드코딩된 입력을 제거하고 실제 사용자로부터 터미널을 통해 문장을 입력받는다. 2. '의도 추론' 결과에 따라, 사용자가 요청한 '상세 프롬프트 문단'을 생성하는 2단계 API 호출을 구현한다. ## 2단계: '상세 프롬프트 문단' 생성을 위한 프롬프트 설계 사용자의 새로운 요구사항에 따라, 1단계에서 '이미지 생성' 의도가 파악되었을 때 2단계에서 사용할 프롬프트를 설계한다. 이 프롬프트는 단순한 문장을 받아 풍부하고 상세한 묘사가 담긴 '문단'을 생성해야 한다. **특화 프롬프트 (이미지 생성용):** ```text You are a creative expert at writing prompts for AI image generators. Based on the user's simple description, create a single, detailed, rich paragraph for a prompt. This paragraph should include several descriptive sentences covering the subject, setting, lighting, mood, and artistic style. Do not just list keywords; weave them into a coherent paragraph. User's simple description: "{{user_input}}" ``` ## `main.py` 업데이트 사용자 입력을 받고, 2단계 API 호출을 수행하도록 `main.py`를 수정한다. ```python import os import sys import google.generativeai as genai from dotenv import load_dotenv def get_intent(model, user_input): """Calls the API to infer the user's intent.""" meta_prompt = """You are an expert at understanding user intent. Analyze the following user request and classify it into one of these categories: [Image Generation], [Text Summarization], [Code Generation], [General Question]. Respond with only the category name in brackets. User Request: "{{user_input}}" """ prompt_for_api = meta_prompt.replace("{{user_input}}", user_input) response = model.generate_content(prompt_for_api) return response.text.strip() def generate_detailed_prompt(model, user_input, intent): """Generates the final detailed prompt based on the intent.""" specialized_prompts = { "[Image Generation]": """You are a creative expert at writing prompts for AI image generators. Based on the user's simple description, create a single, detailed, rich paragraph for a prompt. This paragraph should include several descriptive sentences covering the subject, setting, lighting, mood, and artistic style. Do not just list keywords; weave them into a coherent paragraph. User's simple description: "{{user_input}}" """ # Other intents like [Text Summarization] can be added here later. } prompt_template = specialized_prompts.get(intent) if not prompt_template: return f"I can't generate a detailed prompt for the intent '{intent}' yet." prompt_for_api = prompt_template.replace("{{user_input}}", user_input) response = model.generate_content(prompt_for_api) return response.text.strip() def main(): """Main function to run the prompt generator.""" load_dotenv() api_key = os.getenv("GOOGLE_API_KEY") if not api_key: print("Error: GOOGLE_API_KEY not found in .env file.") sys.exit(1) try: genai.configure(api_key=api_key) model = genai.GenerativeModel('gemini-1.5-pro-latest') except Exception as e: print(f"Error configuring the AI client: {e}") sys.exit(1) # 1. Get user input from the terminal user_input = input("Enter your simple prompt idea: ") try: # 2. Step 1: Infer Intent print("\nStep 1: Inferring intent...") intent = get_intent(model, user_input) print(f"Intent detected: {intent}") # 3. Step 2: Generate Detailed Prompt print("\nStep 2: Generating detailed prompt...") detailed_prompt = generate_detailed_prompt(model, user_input, intent) print("\n--- Your Detailed Prompt Paragraph ---") print(detailed_prompt) print("------------------------------------") except Exception as e: print(f"\nAn error occurred: {e}") if __name__ == "__main__": main() ``` ## 실행 방법 `uv`로 구성한 가상환경이 활성화된 상태에서 스크립트를 실행한다. ```bash python main.py ``` 스크립트가 실행되면 "Enter your simple prompt idea:" 라는 메시지가 나타나고, 여기에 아이디어를 입력하면 2단계에 걸쳐 최종 결과물이 출력된다. ## 다음 단계 다음 단계(`V6`)에서는 코드를 좀 더 기능적으로 분리하고, 다른 의도들(`[Text Summarization]` 등)에 대한 2단계 프롬프트도 추가하는 리팩토링을 진행하여 스크립트의 확장성을 높일 것이다.