Spaces:
Runtime error
Runtime error
File size: 2,541 Bytes
fe893f9 | 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 | from tech_wizard.tech_kb import TechKnowledgeBase
from tech_wizard.openai_module import OpenAIClient
import os
import json
class TechWizardTools:
def __init__(self, openai_api_key=None):
self.kb = TechKnowledgeBase()
self.llm = OpenAIClient(api_key=openai_api_key or os.getenv("OPENAI_API_KEY"))
def architect_system(self, requirements: str) -> str:
"""Design a technical system architecture."""
kb_context = self.kb.get_info("architecture")
prompt = f"""
Requirements: {requirements}
Architecture Patterns Knowledge: {json.dumps(kb_context, indent=2)}
Please design a technical architecture. Include:
1. Recommended Pattern (e.g., Microservices vs Monolith).
2. Technology Stack (Frontend, Backend, DB, Cache).
3. A Mermaid.js diagram representing the system.
4. Scalability and Security considerations.
"""
return self.llm.chat(prompt)
def design_api(self, features: str) -> str:
"""Design a secure and versioned API surface."""
kb_context = self.kb.get_info("api")
prompt = f"""
Feature Requirements: {features}
API Best Practices: {json.dumps(kb_context, indent=2)}
Design a REST or GraphQL API surface. Include:
1. Endpoint paths and methods.
2. Request/Response schemas (JSON).
3. Authentication/Authorization strategy.
4. Error handling logic.
"""
return self.llm.chat(prompt)
def setup_webhooks(self, source_platform: str) -> str:
"""Generate secure webhook handler logic."""
kb_context = self.kb.get_info("webhooks")
prompt = f"""
Source Platform (e.g., Stripe, GitHub, Shopify): {source_platform}
Webhook Knowledge: {json.dumps(kb_context, indent=2)}
Generate a secure webhook handler (Python/FastAPI or Node.js).
Must include signature verification, idempotency, and asynchronous processing.
"""
return self.llm.chat(prompt)
def configure_routing(self, domain: str, app_details: str) -> str:
"""Design DNS and routing configuration."""
kb_context = self.kb.get_info("domains")
prompt = f"""
Domain: {domain}
App/Infrastructure Details: {app_details}
Routing Knowledge: {json.dumps(kb_context, indent=2)}
Provide a DNS configuration plan (A, CNAME, TXT records) and SSL/TLS strategy.
"""
return self.llm.chat(prompt)
|