MCPcopy Create free account
hub / github.com/GitsSaikat/PyGen / parse_generated_content

Function parse_generated_content

pygen/generate_package.py:12–62  ·  view source on GitHub ↗

Parse the generated content into a dictionary of file paths and contents. Expects the format: file content here

(content: str)

Source from the content-addressed store, hash-verified

10 return api_key
11
12def parse_generated_content(content: str) -> Dict[str, str]:
13 """
14 Parse the generated content into a dictionary of file paths and contents.
15 Expects the format:
16 <file_path>
17 <begin_content>
18 file content here
19 <end_content>
20 """
21 files = {}
22 current_file = None
23 current_content = []
24 state = 'expect_file'
25
26 lines = content.split('\n')
27 for line_num, line in enumerate(lines, 1):
28 stripped = line.strip()
29 if state == 'expect_file':
30 if stripped.startswith('<') and stripped.endswith('>'):
31 current_file = stripped[1:-1].strip()
32 if not current_file:
33 print(f"Warning: Empty file path at line {line_num}")
34 current_file = None
35 continue
36 state = 'expect_begin_content'
37 elif stripped == '':
38 continue # Skip empty lines
39 else:
40 print(f"Warning: Expected <file_path> at line {line_num}, got: {stripped}")
41 elif state == 'expect_begin_content':
42 if stripped == '<begin_content>':
43 current_content = []
44 state = 'collect_content'
45 else:
46 print(f"Warning: Expected <begin_content> after <{current_file}> at line {line_num}, got: {stripped}")
47 current_file = None
48 state = 'expect_file'
49 elif state == 'collect_content':
50 if stripped == '<end_content>':
51 if current_file in files:
52 print(f"Warning: Duplicate file path '{current_file}' at line {line_num}. Overwriting previous content.")
53 files[current_file] = '\n'.join(current_content).strip()
54 current_file = None
55 current_content = []
56 state = 'expect_file'
57 else:
58 current_content.append(line)
59 # Check if any file was not properly closed
60 if state != 'expect_file':
61 print(f"Warning: Incomplete file definition for {current_file}")
62 return files
63
64def generate_python_package(package_name: str, package_description: str, features: List[str]) -> Optional[Dict[str, str]]:
65 """Generate a Python package structure and content using Google Gemini Pro 002 model."""

Callers 1

generate_python_packageFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected