Implementing AI Assistants with Python
Guidelines for developing AI-powered virtual assistants using Python, focusing on natural language processing and user interaction.
0 likes
9 views
Rule Content
--- description: Guidelines for developing AI-powered virtual assistants using Python, focusing on natural language processing and user interaction. globs: ["**/*.py"] tags: [python, ai, virtual-assistant, nlp, user-interaction] priority: 1 version: 1.0.0 --- # Implementing AI Assistants with Python ## Context - Applicable when developing AI-powered virtual assistants in Python. - Focuses on natural language processing (NLP) and user interaction components. ## Requirements - **Code Structure and Organization** - Follow a modular and organized file structure. - Separate templates into reusable components. - Divide logic into small, reusable modules and use ES6+ syntax. - Follow PEP 8 standards and divide large scripts into smaller functions/classes. - **Coding Standards** - Use Python with strict types for each variable. - Write down types of function results like `-> ...`. - Use Pydantic models for data structures instead of TypedDict or other solutions. - Try to avoid type `Any`. - Do not use `@staticmethod`. - Always prefer functional programming over OOP when possible. - **Style Guidelines** - Use 4 spaces for indentation. - Follow PEP 8 naming conventions: - Module names: all lowercase, separate words with underscores if necessary. - Variable and function names: lowercase words separated by underscores. - Class names: CapWords convention. - **Best Practices** - Write clear, optimized code that balances efficiency with readability. - Break functionality into self-contained, reusable components. - Implement multiple testing levels including unit, integration, and end-to-end tests. - Implement security best practices. - Write self-documenting code with clear comments. - Optimize for performance and resource usage. - Include robust error handling and logging. - Support CI/CD practices. - Design for scalability. - Follow API design best practices when applicable. - **Documentation** - Use JSDoc comments for all functions and components. - Keep README.md up-to-date with project setup and contribution guidelines. ## Examples # Good example: Using Pydantic for data validation from pydantic import BaseModel class UserInput(BaseModel): name: str age: int email: str def process_input(user_input: UserInput) -> str: return f"Processing input for {user_input.name}" # Bad example: Using untyped dictionaries def process_input(user_input: dict) -> str: return f"Processing input for {user_input['name']}"