wenjin272 commented on code in PR #596: URL: https://github.com/apache/flink-agents/pull/596#discussion_r3085853831
########## python/flink_agents/runtime/skill/skill_parser.py: ########## @@ -0,0 +1,146 @@ +################################################################################ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ +import re +from dataclasses import dataclass +from typing import Dict + +import yaml + +from flink_agents.runtime.skill.agent_skill import AgentSkill + + +@dataclass +class ParsedMarkdown: + """Result of parsing markdown with frontmatter. + + Contains both the extracted metadata and the markdown content. + + Attributes: + ---------- + metadata : Dict[str, str] + YAML metadata extracted from frontmatter. + content : str + Markdown content (without frontmatter). + """ + + metadata: Dict[str, str] + content: str + + +class MarkdownSkillParser: + """Utility for parsing Markdown files with YAML frontmatter.""" + + # Pattern to match frontmatter: starts with ---, ends with --- + # Group 1: frontmatter content (non-greedy) + # Group 2: remaining content + FRONTMATTER_PATTERN = re.compile( + r"^---\s*[\r\n]+(.*?)[\r\n]*---(?:\s*[\r\n]+)?(.*)", re.DOTALL + ) + + # Pattern to match key: value format + KEY_VALUE_PATTERN = re.compile(r"^([a-zA-Z_][a-zA-Z0-9_-]*)\s*:\s*(.*)$") Review Comment: Initially, the coding agent generated code that used regular expressions to parse YAML frontmatter. I later switched to using a YAML library but forgot to remove these two PATTERNs. I will remove this. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
