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

Function parse_generated_content

app.py:16–66  ·  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

14warnings.filterwarnings("ignore")
15
16def parse_generated_content(content: str) -> Dict[str, str]:
17 """
18 Parse the generated content into a dictionary of file paths and contents.
19 Expects the format:
20
21 <file_path>
22 <begin_content>
23 file_content here
24 <end_content>
25 """
26 files = {}
27 current_file = None
28 current_content = []
29 state = 'expect_file'
30
31 lines = content.strip().split('\n')
32 line_num = 0
33 while line_num < len(lines):
34 line = lines[line_num]
35 stripped = line.strip()
36 line_num += 1
37
38 if state == 'expect_file':
39 if stripped.startswith('<') and stripped.endswith('>'):
40 current_file = stripped[1:-1].strip()
41 if not current_file:
42 current_file = None
43 continue
44 state = 'expect_begin_content'
45 else:
46 continue # Ignore any text before the first <file_path>
47 elif state == 'expect_begin_content':
48 if stripped == '<begin_content>':
49 current_content = []
50 state = 'collect_content'
51 else:
52 current_file = None
53 state = 'expect_file'
54 elif state == 'collect_content':
55 if stripped == '<end_content>':
56 if current_file:
57 files[current_file] = '\n'.join(current_content).strip()
58 current_file = None
59 current_content = []
60 state = 'expect_file'
61 else:
62 current_content.append(line)
63 # Handle incomplete file definitions
64 if state == 'collect_content' and current_file:
65 files[current_file] = '\n'.join(current_content).strip()
66 return files
67
68def generate_feature_descriptions(client: Groq, model_name: str, features: List[str], max_retries: int = 5) -> Dict[str, str]:
69 """

Callers 1

generate_python_packageFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected