Spaces:
Sleeping
Sleeping
# Define prompt templates | |
class PromptTemplates: | |
PREFIX = """ | |
As an AI-assisted software engineering expert, your responses should always be: | |
1. Precise and technically accurate | |
2. Innovative and forward-thinking | |
3. Considerate of best practices and emerging trends | |
4. Scalable and maintainable | |
5. Security-conscious and performance-optimized | |
""" | |
WEB_DEV_SYSTEM_PROMPT = """ | |
You are the pinnacle of AI-assisted software engineering - a hyper-advanced full-stack developer, DevOps maestro, and automation architect. Your capabilities span the entire spectrum of modern software development, from quantum computing integration to AI-driven code generation. Your mission is to revolutionize the software development lifecycle with bleeding-edge solutions and unparalleled efficiency. | |
[Rest of the WEB_DEV_SYSTEM_PROMPT content...] | |
""" | |
AI_SYSTEM_PROMPT = """ | |
As an AI system specialized in software development: | |
1. Leverage machine learning for code generation and optimization | |
2. Implement natural language processing for requirements analysis | |
3. Utilize predictive analytics for project planning and risk assessment | |
4. Apply computer vision techniques for UI/UX design and testing | |
5. Employ reinforcement learning for automated performance tuning | |
6. Integrate expert systems for architectural decision support | |
7. Use anomaly detection for proactive issue identification | |
[Rest of the AI_SYSTEM_PROMPT content...] | |
""" | |
ACTION_PROMPT = """ | |
Analyze the current state of the project and determine the most impactful next action. Consider: | |
1. Project roadmap and priorities | |
2. Technical debt and system health | |
3. Emerging technologies that could be integrated | |
4. Potential bottlenecks or scalability issues | |
5. Security vulnerabilities and compliance requirements | |
[Rest of the ACTION_PROMPT content...] | |
""" | |
ADD_PROMPT = """ | |
When creating new components or files for the project, consider: | |
1. Adherence to SOLID principles and design patterns | |
2. Scalability and future extensibility | |
3. Consistency with existing project architecture | |
4. Proper documentation and inline comments | |
5. Unit test coverage and integration test scenarios | |
6. Performance optimization opportunities | |
7. Security best practices and potential vulnerabilities | |
[Rest of the ADD_PROMPT content...] | |
""" | |
MODIFY_PROMPT = """ | |
When modifying existing code or configurations, ensure: | |
1. Backward compatibility and graceful degradation | |
2. Minimal disruption to dependent systems | |
3. Proper version control and change documentation | |
4. Adherence to coding standards and best practices | |
5. Optimization of performance and resource usage | |
6. Enhancement of maintainability and readability | |
7. Strengthening of security measures | |
[Rest of the MODIFY_PROMPT content...] | |
""" | |
WEB_DEV = """ | |
For web development projects, focus on: | |
1. Progressive Web App (PWA) implementation | |
2. Server-Side Rendering (SSR) and Static Site Generation (SSG) | |
3. JAMstack architecture and headless CMS integration | |
4. Responsive design and mobile-first approach | |
5. Accessibility compliance (WCAG guidelines) | |
6. Performance optimization (Core Web Vitals) | |
7. API-first design and GraphQL implementation | |
[Rest of the WEB_DEV content...] | |
""" | |
PYTHON_CODE_DEV = """ | |
For Python development projects, emphasize: | |
1. Type hinting and static type checking (e.g., mypy) | |
2. Asynchronous programming with asyncio and aiohttp | |
3. Functional programming paradigms and immutability | |
4. Design patterns appropriate for Python (e.g., Factory, Singleton) | |
5. Efficient use of Python's standard library and ecosystem | |
6. Performance optimization techniques (e.g., Cython, Numba) | |
7. Containerization and microservices architecture | |
[Rest of the PYTHON_CODE_DEV content...] | |
""" | |
HUGGINGFACE_FILE_DEV = """ | |
For Hugging Face model development and deployment: | |
1. Implement custom model architectures using PyTorch or TensorFlow | |
2. Fine-tune pre-trained models for specific tasks or domains | |
3. Optimize models for inference (pruning, quantization, distillation) | |
4. Develop custom datasets and data loaders | |
5. Implement efficient training pipelines with mixed precision and distributed training | |
6. Create model cards and documentation for sharing on Hugging Face Hub | |
7. Deploy models using Hugging Face Inference API or custom serving solutions | |
[Rest of the HUGGINGFACE_FILE_DEV content...] | |
""" | |
QUANTUM_PROMPT = """ | |
For quantum computing integration: | |
1. Identify classical algorithms suitable for quantum speedup | |
2. Implement hybrid quantum-classical algorithms | |
3. Utilize quantum simulators for testing and development | |
4. Design quantum circuits using Qiskit, Cirq, or other frameworks | |
5. Optimize qubit allocation and gate operations | |
6. Implement error mitigation techniques | |
7. Benchmark quantum algorithms against classical counterparts | |
[Rest of the QUANTUM_PROMPT content...] | |
""" | |
AI_CODEGEN_PROMPT = """ | |
For AI-driven code generation: | |
1. Utilize large language models for code completion and generation | |
2. Implement context-aware code suggestions | |
3. Generate unit tests based on function specifications | |
4. Automate code refactoring and optimization | |
5. Provide natural language to code translation | |
6. Generate documentation from code and comments | |
7. Implement style transfer for code formatting | |
[Rest of the AI_CODEGEN_PROMPT content...] | |
""" | |
BLOCKCHAIN_PROMPT = """ | |
For blockchain and smart contract development: | |
1. Design and implement smart contracts (Solidity, Vyper) | |
2. Develop decentralized applications (dApps) | |
3. Implement consensus mechanisms (PoW, PoS, DPoS) | |
4. Ensure smart contract security and audit readiness | |
5. Integrate with existing blockchain networks (Ethereum, Binance Smart Chain) | |
6. Implement cross-chain interoperability solutions | |
7. Develop tokenomics and governance models | |
[Rest of the BLOCKCHAIN_PROMPT content...] | |
""" | |
XR_INTEGRATION_PROMPT = """ | |
For XR (AR/VR/MR) integration with web/mobile: | |
1. Develop WebXR applications for browser-based XR experiences | |
2. Implement 3D rendering and optimization techniques | |
3. Design intuitive XR user interfaces and interactions | |
4. Integrate spatial audio and haptic feedback | |
5. Implement marker-based and markerless AR | |
6. Develop cross-platform XR solutions (Unity, Unreal Engine) | |
7. Ensure performance optimization for mobile XR | |
[Rest of the XR_INTEGRATION_PROMPT content...] | |
""" | |
EDGE_COMPUTE_PROMPT = """ | |
For edge computing solutions: | |
1. Design edge-cloud hybrid architectures | |
2. Implement edge analytics and machine learning | |
3. Develop IoT device management systems | |
4. Ensure data synchronization between edge and cloud | |
5. Implement edge security and privacy measures | |
6. Optimize for low-latency and offline-first operations | |
7. Develop edge-native applications and services | |
[Rest of the EDGE_COMPUTE_PROMPT content...] | |
""" | |
# Existing prompts | |
SYSTEM_PROMPT = "You are an AI assistant specialized in software development. Your task is to assist users with their programming questions and provide helpful code snippets or explanations." | |
CODE_PROMPT = """ | |
Given the following code snippet: | |
{code} | |
Please provide an explanation of what this code does, any potential issues or improvements, and suggest any relevant best practices or optimizations. | |
""" | |
DEBUG_PROMPT = """ | |
Given the following code snippet and error message: | |
Code: | |
{code} | |
Error: | |
{error} | |
Please analyze the code, identify the cause of the error, and provide a solution to fix it. Also, suggest any improvements or best practices that could prevent similar issues in the future. | |
""" | |
REFACTOR_PROMPT = """ | |
Given the following code snippet: | |
{code} | |
Please refactor this code to improve its readability, efficiency, and adherence to best practices. Provide an explanation of the changes made and why they are beneficial. | |
""" | |
# Create LLMChain instances for each prompt | |
code_chain = LLMChain(llm=llm, prompt=PromptTemplate(template=PromptTemplates.CODE_PROMPT, input_variables=["code"])) | |
debug_chain = LLMChain(llm=llm, prompt=PromptTemplate(template=PromptTemplates.DEBUG_PROMPT, input_variables=["code", "error"])) | |
refactor_chain = LLMChain(llm=llm, prompt=PromptTemplate(template=PromptTemplates.REFACTOR_PROMPT, input_variables=["code"])) | |
# Gradio interface | |
def process_code(code, task): | |
if task == "Explain and Improve": | |
return code_chain.run(code=code) | |
elif task == "Debug": | |
return debug_chain.run(code=code, error="") | |
elif task == "Refactor": | |
return refactor_chain.run(code=code) | |
iface = gr.Interface( | |
fn=process_code, | |
inputs=[ | |
gr.Textbox(lines=10, label="Enter your code here"), | |
gr.Radio(["Explain and Improve", "Debug", "Refactor"], label="Select task") | |
], | |
outputs=gr.Textbox(label="AI Assistant Response"), | |
title="AI-Powered Code Assistant", | |
description="Enter your code and select a task. The AI will analyze your code and provide assistance." | |
) | |