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

Function generate_python_package

pygen/package_ollama.py:82–170  ·  view source on GitHub ↗

Generate a Python package structure and content using the Ollama model.

(package_name: str, package_description: str, features: List[str], model_name: str)

Source from the content-addressed store, hash-verified

80 return response
81
82def generate_python_package(package_name: str, package_description: str, features: List[str], model_name: str) -> Optional[Dict[str, str]]:
83 """Generate a Python package structure and content using the Ollama model."""
84
85 # Format the features as a bulleted list
86 if features:
87 features_formatted = "\n".join(f"- {feature.strip()}" for feature in features)
88 features_section = f"\n\nInclude the following features:\n{features_formatted}"
89 else:
90 features_section = ""
91
92 # Updated prompt with clearer instructions
93 prompt = f"""
94You are to generate the structure and content of a Python package named `{package_name}` based on the following description:
95{package_description}{features_section}
96
97Provide the package structure and content **strictly** in the following format for each file:
98
99<file_path>
100<begin_content>
101file_content
102<end_content>
103
104Include **only** the files specified below, in the given order:
105
106- setup.py
107- README.md
108- requirements.txt
109- examples/example_{package_name}.py
110- tests/test_{package_name}.py
111- {package_name}/__init__.py
112- {package_name}/main.py
113
114Ensure there are no extra lines or spaces between the tags and the content.
115
116**Important Instructions:**
117
118- Do **not** include any text outside the specified format.
119- Do **not** provide any explanations, introductions, or conclusions.
120- Ensure that every `<begin_content>` has a matching `<end_content>`.
121- Use the exact file paths and filenames as specified.
122- The content inside `<begin_content>` and `<end_content>` should be the code or text for that file.
123
124**Example:**
125
126<setup.py>
127<begin_content>
128from setuptools import setup, find_packages
129
130setup(
131 name='{package_name}',
132 version='0.1.0',
133 description='An example package',
134 author='Your Name',
135 packages=find_packages(),
136 install_requires=[
137 # Add dependencies here
138 ],
139 classifiers=[

Callers 1

mainFunction · 0.70

Calls 2

parse_generated_contentFunction · 0.70

Tested by

no test coverage detected