Generate an enhanced Markdown documentation file (DOCUMENTATION.md) using the AI model. Args: client (Groq): The AI client instance. model_name (str): The model name to use. package_structure (Dict[str, str]): Dictionary mapping file paths to their contents.
(client: Groq, model_name: str, package_structure: Dict[str, str], package_name: str, max_retries: int = 5)
| 446 | return zip_buffer.getvalue() |
| 447 | |
| 448 | def generate_markdown_documentation(client: Groq, model_name: str, package_structure: Dict[str, str], package_name: str, max_retries: int = 5) -> Optional[str]: |
| 449 | """ |
| 450 | Generate an enhanced Markdown documentation file (DOCUMENTATION.md) using the AI model. |
| 451 | |
| 452 | Args: |
| 453 | client (Groq): The AI client instance. |
| 454 | model_name (str): The model name to use. |
| 455 | package_structure (Dict[str, str]): Dictionary mapping file paths to their contents. |
| 456 | package_name (str): Name of the Python package. |
| 457 | max_retries (int): Maximum number of retries for the request. |
| 458 | |
| 459 | Returns: |
| 460 | Optional[str]: The content of the generated DOCUMENTATION.md file or None if failed. |
| 461 | """ |
| 462 | # Prepare the prompt |
| 463 | prompt = f""" |
| 464 | You are to generate comprehensive documentation for a Python package named '{package_name}'. The package contains the following files and their contents: |
| 465 | |
| 466 | """ |
| 467 | |
| 468 | for file_path, content in package_structure.items(): |
| 469 | prompt += f"File: {file_path}\nContent:\n\"\"\"\n{content}\n\"\"\"\n\n" |
| 470 | |
| 471 | prompt += f""" |
| 472 | Based on the above files and their contents, generate detailed and user-friendly documentation in Markdown format. The documentation should include an overview, installation instructions, usage examples, API references, and any other relevant sections that would help users understand and utilize the package effectively. Do not include any code that is not part of the package. Ensure the documentation is well-structured and written in clear, professional language. Be and act like technical writer. Try to be verbose as much as possible. Write the documentation in a tutorial like style and explain how to use each file. |
| 473 | |
| 474 | Begin the documentation below: |
| 475 | """ |
| 476 | |
| 477 | retries = 0 |
| 478 | while retries < max_retries: |
| 479 | try: |
| 480 | response = client.chat.completions.create( |
| 481 | messages=[ |
| 482 | { |
| 483 | "role": "user", |
| 484 | "content": prompt.strip(), |
| 485 | } |
| 486 | ], |
| 487 | model=model_name, |
| 488 | ) |
| 489 | documentation_content = response.choices[0].message.content.strip() |
| 490 | return documentation_content |
| 491 | except Exception as e: |
| 492 | retries += 1 |
| 493 | wait_time = 2 ** retries |
| 494 | print(f"Error generating documentation: {str(e)}") |
| 495 | print(f"Retrying in {wait_time} seconds... (Attempt {retries}/{max_retries})") |
| 496 | time.sleep(wait_time) |
| 497 | else: |
| 498 | print(f"Failed to generate documentation after {max_retries} attempts.") |
| 499 | return None |
| 500 | |
| 501 | def main(): |
| 502 | st.set_page_config(page_title="🛠️ PyGen", layout="wide") |