Pranav1908/CodeReviewAutomation
0
1from langchain_groq import ChatGroq2import traceback3import json4 5# Initialize LLM6try:7 llm = ChatGroq(8 temperature=0,9 groq_api_key="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",10 model_name="llama-3.2-90b-vision-preview"11 )12except Exception as e:13 print(f"Error initializing LLM: {e}")14 traceback.print_exc()15 raise16 17# Prompt18prompt = ("You would be given a code as an input for the code review {code}. Make sure to use everything you know "19 "to provide the best support possible."20 "You must strive to provide a complete and accurate response."21 "You are expected to give a detailed, informative response for the code written for each line of the code. Ensure the answer is complete"22 "and maintain a helpful and friendly tone throughout."23 )24 25# Function to make predictions26def generate(escaped_code):27 try:28 result = llm.invoke(escaped_code)29 return result.content30 except Exception as e:31 print(f"Error during generation of Code Review: {e}")32 traceback.print_exc()33 raise34 35 36def loadContext(file_path: str) -> str:37 try:38 with open(file_path,'r',encoding='utf-8') as file:39 content = file.read()40 return content41 except Exception as e:42 raise Exception(f"Failed to read the file at {file_path}: {str(e)}")43 