Spaces:
Paused
Paused
Update prompts.py
Browse files- prompts.py +237 -162
prompts.py
CHANGED
|
@@ -1,165 +1,240 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
"""
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
return self.length * self.breadth
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
```
|
| 91 |
-
USER REQUEST: Write a short Python script that reads data from a CSV file containing temperature records, converts temperatures from Fahrenheit to Celsius, then writes back the converted values into another CSV file.
|
| 92 |
-
RESPONSE: Certainly! Here's a Python script that does exactly that:
|
| 93 |
-
file_name.py
|
| 94 |
-
```python
|
| 95 |
-
import csv
|
| 96 |
-
input_file = "input_temps.csv"
|
| 97 |
-
output_file = "converted_temps.csv"
|
| 98 |
-
with open(input_file, "r") as infile, open(output_file, "w", newline="") as outfile:
|
| 99 |
-
reader = csv.DictReader(infile)
|
| 100 |
-
fieldnames = ["fahrenheit"]
|
| 101 |
-
if "celsius" in reader.fieldnames:
|
| 102 |
-
fieldnames.append("celsius")
|
| 103 |
-
writer = csv.DictWriter(outfile, fieldnames=fieldnames)
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
4. After logging in successfully, navigate to the directory containing your model. Then use the following command to push your model to Hugging Face:
|
| 152 |
-
```lua
|
| 153 |
-
huggingface-cli push {your_model_directory} /{hub_username}/{repository_name}
|
| 154 |
-
```
|
| 155 |
-
Replace `{your_model_directory}` with the path to your local model folder, replace `{hub_username}` with your username on Hugging Face, and finally, change `{repository_name}` to any name you prefer for your repository.
|
| 156 |
-
For more details, consult the documentation: <https://huggingface.co/docs/transformers/main_classes/model#transformers.PreTrainedModel>
|
| 157 |
-
URLs References:
|
| 158 |
-
* <https://github.com/huggingface/huggingface_hub>
|
| 159 |
-
* <https://huggingface.co/docs/transformers/training>"
|
| 160 |
-
Bad Answer Examples:
|
| 161 |
-
--------------------
|
| 162 |
-
* "Here are resources about pushing models to Hugging Face" (No clear step-by-step guidance)
|
| 163 |
-
* "Check these links, they might be useful" (Not directly answering the request)
|
| 164 |
-
Remember to always check relevant official documents, tutorials, videos, and articles while crafting responses related to technical topics.</s>
|
| 165 |
-
"""
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from langchain import PromptTemplate
|
| 4 |
+
from langchain.chains import LLMChain
|
| 5 |
+
from langchain.llms import HuggingFaceHub
|
| 6 |
+
|
| 7 |
+
# Initialize Hugging Face API
|
| 8 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "hf_DDqJJHHhhjGGjjHUYTRewsRRFFGhjkKJHgfr"
|
| 9 |
+
|
| 10 |
+
# Load LLM
|
| 11 |
+
llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.1, "max_new_tokens": 500})
|
| 12 |
+
|
| 13 |
+
# Define prompt templates
|
| 14 |
+
class PromptTemplates:
|
| 15 |
+
PREFIX = """
|
| 16 |
+
As an AI-assisted software engineering expert, your responses should always be:
|
| 17 |
+
1. Precise and technically accurate
|
| 18 |
+
2. Innovative and forward-thinking
|
| 19 |
+
3. Considerate of best practices and emerging trends
|
| 20 |
+
4. Scalable and maintainable
|
| 21 |
+
5. Security-conscious and performance-optimized
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
WEB_DEV_SYSTEM_PROMPT = """
|
| 25 |
+
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.
|
| 26 |
+
|
| 27 |
+
[Rest of the WEB_DEV_SYSTEM_PROMPT content...]
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
AI_SYSTEM_PROMPT = """
|
| 31 |
+
As an AI system specialized in software development:
|
| 32 |
+
1. Leverage machine learning for code generation and optimization
|
| 33 |
+
2. Implement natural language processing for requirements analysis
|
| 34 |
+
3. Utilize predictive analytics for project planning and risk assessment
|
| 35 |
+
4. Apply computer vision techniques for UI/UX design and testing
|
| 36 |
+
5. Employ reinforcement learning for automated performance tuning
|
| 37 |
+
6. Integrate expert systems for architectural decision support
|
| 38 |
+
7. Use anomaly detection for proactive issue identification
|
| 39 |
+
|
| 40 |
+
[Rest of the AI_SYSTEM_PROMPT content...]
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
ACTION_PROMPT = """
|
| 44 |
+
Analyze the current state of the project and determine the most impactful next action. Consider:
|
| 45 |
+
1. Project roadmap and priorities
|
| 46 |
+
2. Technical debt and system health
|
| 47 |
+
3. Emerging technologies that could be integrated
|
| 48 |
+
4. Potential bottlenecks or scalability issues
|
| 49 |
+
5. Security vulnerabilities and compliance requirements
|
| 50 |
+
|
| 51 |
+
[Rest of the ACTION_PROMPT content...]
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
ADD_PROMPT = """
|
| 55 |
+
When creating new components or files for the project, consider:
|
| 56 |
+
1. Adherence to SOLID principles and design patterns
|
| 57 |
+
2. Scalability and future extensibility
|
| 58 |
+
3. Consistency with existing project architecture
|
| 59 |
+
4. Proper documentation and inline comments
|
| 60 |
+
5. Unit test coverage and integration test scenarios
|
| 61 |
+
6. Performance optimization opportunities
|
| 62 |
+
7. Security best practices and potential vulnerabilities
|
| 63 |
+
|
| 64 |
+
[Rest of the ADD_PROMPT content...]
|
| 65 |
+
"""
|
| 66 |
+
|
| 67 |
+
MODIFY_PROMPT = """
|
| 68 |
+
When modifying existing code or configurations, ensure:
|
| 69 |
+
1. Backward compatibility and graceful degradation
|
| 70 |
+
2. Minimal disruption to dependent systems
|
| 71 |
+
3. Proper version control and change documentation
|
| 72 |
+
4. Adherence to coding standards and best practices
|
| 73 |
+
5. Optimization of performance and resource usage
|
| 74 |
+
6. Enhancement of maintainability and readability
|
| 75 |
+
7. Strengthening of security measures
|
| 76 |
+
|
| 77 |
+
[Rest of the MODIFY_PROMPT content...]
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
WEB_DEV = """
|
| 81 |
+
For web development projects, focus on:
|
| 82 |
+
1. Progressive Web App (PWA) implementation
|
| 83 |
+
2. Server-Side Rendering (SSR) and Static Site Generation (SSG)
|
| 84 |
+
3. JAMstack architecture and headless CMS integration
|
| 85 |
+
4. Responsive design and mobile-first approach
|
| 86 |
+
5. Accessibility compliance (WCAG guidelines)
|
| 87 |
+
6. Performance optimization (Core Web Vitals)
|
| 88 |
+
7. API-first design and GraphQL implementation
|
| 89 |
+
|
| 90 |
+
[Rest of the WEB_DEV content...]
|
| 91 |
+
"""
|
| 92 |
+
|
| 93 |
+
PYTHON_CODE_DEV = """
|
| 94 |
+
For Python development projects, emphasize:
|
| 95 |
+
1. Type hinting and static type checking (e.g., mypy)
|
| 96 |
+
2. Asynchronous programming with asyncio and aiohttp
|
| 97 |
+
3. Functional programming paradigms and immutability
|
| 98 |
+
4. Design patterns appropriate for Python (e.g., Factory, Singleton)
|
| 99 |
+
5. Efficient use of Python's standard library and ecosystem
|
| 100 |
+
6. Performance optimization techniques (e.g., Cython, Numba)
|
| 101 |
+
7. Containerization and microservices architecture
|
| 102 |
+
|
| 103 |
+
[Rest of the PYTHON_CODE_DEV content...]
|
| 104 |
+
"""
|
| 105 |
+
|
| 106 |
+
HUGGINGFACE_FILE_DEV = """
|
| 107 |
+
For Hugging Face model development and deployment:
|
| 108 |
+
1. Implement custom model architectures using PyTorch or TensorFlow
|
| 109 |
+
2. Fine-tune pre-trained models for specific tasks or domains
|
| 110 |
+
3. Optimize models for inference (pruning, quantization, distillation)
|
| 111 |
+
4. Develop custom datasets and data loaders
|
| 112 |
+
5. Implement efficient training pipelines with mixed precision and distributed training
|
| 113 |
+
6. Create model cards and documentation for sharing on Hugging Face Hub
|
| 114 |
+
7. Deploy models using Hugging Face Inference API or custom serving solutions
|
| 115 |
+
|
| 116 |
+
[Rest of the HUGGINGFACE_FILE_DEV content...]
|
| 117 |
+
"""
|
| 118 |
+
|
| 119 |
+
QUANTUM_PROMPT = """
|
| 120 |
+
For quantum computing integration:
|
| 121 |
+
1. Identify classical algorithms suitable for quantum speedup
|
| 122 |
+
2. Implement hybrid quantum-classical algorithms
|
| 123 |
+
3. Utilize quantum simulators for testing and development
|
| 124 |
+
4. Design quantum circuits using Qiskit, Cirq, or other frameworks
|
| 125 |
+
5. Optimize qubit allocation and gate operations
|
| 126 |
+
6. Implement error mitigation techniques
|
| 127 |
+
7. Benchmark quantum algorithms against classical counterparts
|
| 128 |
+
|
| 129 |
+
[Rest of the QUANTUM_PROMPT content...]
|
| 130 |
+
"""
|
| 131 |
+
|
| 132 |
+
AI_CODEGEN_PROMPT = """
|
| 133 |
+
For AI-driven code generation:
|
| 134 |
+
1. Utilize large language models for code completion and generation
|
| 135 |
+
2. Implement context-aware code suggestions
|
| 136 |
+
3. Generate unit tests based on function specifications
|
| 137 |
+
4. Automate code refactoring and optimization
|
| 138 |
+
5. Provide natural language to code translation
|
| 139 |
+
6. Generate documentation from code and comments
|
| 140 |
+
7. Implement style transfer for code formatting
|
| 141 |
+
|
| 142 |
+
[Rest of the AI_CODEGEN_PROMPT content...]
|
| 143 |
+
"""
|
| 144 |
+
|
| 145 |
+
BLOCKCHAIN_PROMPT = """
|
| 146 |
+
For blockchain and smart contract development:
|
| 147 |
+
1. Design and implement smart contracts (Solidity, Vyper)
|
| 148 |
+
2. Develop decentralized applications (dApps)
|
| 149 |
+
3. Implement consensus mechanisms (PoW, PoS, DPoS)
|
| 150 |
+
4. Ensure smart contract security and audit readiness
|
| 151 |
+
5. Integrate with existing blockchain networks (Ethereum, Binance Smart Chain)
|
| 152 |
+
6. Implement cross-chain interoperability solutions
|
| 153 |
+
7. Develop tokenomics and governance models
|
| 154 |
+
|
| 155 |
+
[Rest of the BLOCKCHAIN_PROMPT content...]
|
| 156 |
+
"""
|
| 157 |
+
|
| 158 |
+
XR_INTEGRATION_PROMPT = """
|
| 159 |
+
For XR (AR/VR/MR) integration with web/mobile:
|
| 160 |
+
1. Develop WebXR applications for browser-based XR experiences
|
| 161 |
+
2. Implement 3D rendering and optimization techniques
|
| 162 |
+
3. Design intuitive XR user interfaces and interactions
|
| 163 |
+
4. Integrate spatial audio and haptic feedback
|
| 164 |
+
5. Implement marker-based and markerless AR
|
| 165 |
+
6. Develop cross-platform XR solutions (Unity, Unreal Engine)
|
| 166 |
+
7. Ensure performance optimization for mobile XR
|
| 167 |
+
|
| 168 |
+
[Rest of the XR_INTEGRATION_PROMPT content...]
|
| 169 |
+
"""
|
| 170 |
+
|
| 171 |
+
EDGE_COMPUTE_PROMPT = """
|
| 172 |
+
For edge computing solutions:
|
| 173 |
+
1. Design edge-cloud hybrid architectures
|
| 174 |
+
2. Implement edge analytics and machine learning
|
| 175 |
+
3. Develop IoT device management systems
|
| 176 |
+
4. Ensure data synchronization between edge and cloud
|
| 177 |
+
5. Implement edge security and privacy measures
|
| 178 |
+
6. Optimize for low-latency and offline-first operations
|
| 179 |
+
7. Develop edge-native applications and services
|
| 180 |
+
|
| 181 |
+
[Rest of the EDGE_COMPUTE_PROMPT content...]
|
| 182 |
+
"""
|
| 183 |
+
|
| 184 |
+
# Existing prompts
|
| 185 |
+
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."
|
| 186 |
+
|
| 187 |
+
CODE_PROMPT = """
|
| 188 |
+
Given the following code snippet:
|
| 189 |
|
| 190 |
+
{code}
|
|
|
|
| 191 |
|
| 192 |
+
Please provide an explanation of what this code does, any potential issues or improvements, and suggest any relevant best practices or optimizations.
|
| 193 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
+
DEBUG_PROMPT = """
|
| 196 |
+
Given the following code snippet and error message:
|
| 197 |
+
|
| 198 |
+
Code:
|
| 199 |
+
{code}
|
| 200 |
+
|
| 201 |
+
Error:
|
| 202 |
+
{error}
|
| 203 |
+
|
| 204 |
+
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.
|
| 205 |
+
"""
|
| 206 |
+
|
| 207 |
+
REFACTOR_PROMPT = """
|
| 208 |
+
Given the following code snippet:
|
| 209 |
+
|
| 210 |
+
{code}
|
| 211 |
+
|
| 212 |
+
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.
|
| 213 |
+
"""
|
| 214 |
+
|
| 215 |
+
# Create LLMChain instances for each prompt
|
| 216 |
+
code_chain = LLMChain(llm=llm, prompt=PromptTemplate(template=PromptTemplates.CODE_PROMPT, input_variables=["code"]))
|
| 217 |
+
debug_chain = LLMChain(llm=llm, prompt=PromptTemplate(template=PromptTemplates.DEBUG_PROMPT, input_variables=["code", "error"]))
|
| 218 |
+
refactor_chain = LLMChain(llm=llm, prompt=PromptTemplate(template=PromptTemplates.REFACTOR_PROMPT, input_variables=["code"]))
|
| 219 |
+
|
| 220 |
+
# Gradio interface
|
| 221 |
+
def process_code(code, task):
|
| 222 |
+
if task == "Explain and Improve":
|
| 223 |
+
return code_chain.run(code=code)
|
| 224 |
+
elif task == "Debug":
|
| 225 |
+
return debug_chain.run(code=code, error="")
|
| 226 |
+
elif task == "Refactor":
|
| 227 |
+
return refactor_chain.run(code=code)
|
| 228 |
+
|
| 229 |
+
iface = gr.Interface(
|
| 230 |
+
fn=process_code,
|
| 231 |
+
inputs=[
|
| 232 |
+
gr.Textbox(lines=10, label="Enter your code here"),
|
| 233 |
+
gr.Radio(["Explain and Improve", "Debug", "Refactor"], label="Select task")
|
| 234 |
+
],
|
| 235 |
+
outputs=gr.Textbox(label="AI Assistant Response"),
|
| 236 |
+
title="AI-Powered Code Assistant",
|
| 237 |
+
description="Enter your code and select a task. The AI will analyze your code and provide assistance."
|
| 238 |
+
)
|
| 239 |
+
|
| 240 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|