diff --git a/example/gpt.yaml b/example/gpt.yaml new file mode 100644 index 0000000..fcd3a4f --- /dev/null +++ b/example/gpt.yaml @@ -0,0 +1,5 @@ +files: + - .github/workflows/run_struct.yaml: + user_prompt: | + make sure that token is set on secrets and value is TOKEN + make sure that password is set on secrets and value is PASSWORD diff --git a/struct_module/commands/generate.py b/struct_module/commands/generate.py index a0f0c44..aa8cd4f 100644 --- a/struct_module/commands/generate.py +++ b/struct_module/commands/generate.py @@ -90,8 +90,19 @@ def _create_structure(self, args): } ) + # Determine the full file path + file_path_to_create = os.path.join(args.base_path, name) + existing_content = None + if os.path.exists(file_path_to_create): + self.logger.info(f"File already exists: {file_path_to_create}") + with open(file_path_to_create, 'r') as existing_file: + existing_content = existing_file.read() + + file_item.process_prompt( + args.dry_run, + existing_content=existing_content + ) file_item.apply_template_variables(template_vars) - file_item.process_prompt(args.dry_run) file_item.create( args.base_path, diff --git a/struct_module/file_item.py b/struct_module/file_item.py index d6106c4..a8ede99 100644 --- a/struct_module/file_item.py +++ b/struct_module/file_item.py @@ -47,7 +47,7 @@ def _configure_openai(self): self.openai_client = OpenAI(api_key=openai_api_key) if not openai_model: self.logger.debug("OpenAI model not found. Using default model.") - self.openai_model = "gpt-3.5-turbo" + self.openai_model = "gpt-4.1" else: self.logger.debug(f"Using OpenAI model: {openai_model}") self.openai_model = openai_model @@ -55,10 +55,8 @@ def _configure_openai(self): def _get_file_directory(self): return os.path.dirname(self.name) - def process_prompt(self, dry_run=False): + def process_prompt(self, dry_run=False, existing_content=None): if self.user_prompt: - self.logger.debug(f"Using user prompt: {self.user_prompt}") - if not self.openai_client or not openai_api_key: self.logger.warning("Skipping processing prompt as OpenAI API key is not set.") return @@ -68,17 +66,25 @@ def process_prompt(self, dry_run=False): else: system_prompt = self.system_prompt + # If existing_content is provided, append it to the user prompt + user_prompt = self.user_prompt + if existing_content: + user_prompt += f"\n\nCurrent file content (if any):\n```\n{existing_content}\n```\n\nPlease modify existing content so that it meets the new requirements. Your output should be plain text, without any code blocks or formatting. Do not include any explanations or comments. Just provide the final content of the file." + + self.logger.debug(f"Using system prompt: {system_prompt}") + self.logger.debug(f"Using user prompt: {user_prompt}") + if dry_run: self.logger.info("[DRY RUN] Would generate content using OpenAI API.") self.content = "[DRY RUN] Generating content using OpenAI" return - if not self.openai_client or not openai_api_key: + if self.openai_client and openai_api_key: completion = self.openai_client.chat.completions.create( model=self.openai_model, messages=[ {"role": "system", "content": system_prompt}, - {"role": "user", "content": self.user_prompt} + {"role": "user", "content": user_prompt} ] )