Spaces:
Sleeping
Sleeping
File size: 1,088 Bytes
c2af030 | 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 | import sys
from codeInsight.inference.code_assistant import CodeAssistant
from codeInsight.safety.safety_checker import SafetyChecker
from codeInsight.exception import ExceptionHandle
from codeInsight.logger import logging
class PredictionPipeline:
def __init__(self, config_path : str = "config/model.yaml"):
try:
self.assistant = CodeAssistant(config_path)
self.safety_checker = SafetyChecker()
logging.info("Prediction Pipeline initialized successfully.")
except Exception as e:
logging.error("Failed to initialize PredictionPipeline")
raise ExceptionHandle(e, sys)
def predict(self, instruction : str) -> str:
try:
raw_output = self.assistant.generate(instruction)
safe_output = self.safety_checker.check_outputs(raw_output)
return safe_output
except Exception as e:
logging.error(f"Prediction failed: {e}")
return "An error occurred while processing your request. Please try again." |