Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files6 unmodified lines7891011121 unmodified line141516171819202122231 unmodified line252627282930313233343536375 unmodified lines434445464748491 unmodified line51525354555657585960616263646 unmodified lines"""import osfrom groq import Groqimport httpxfrom tenacity import retry, stop_after_attempt, wait_exponential1 unmodified lineload_dotenv()_client = Groq(api_key=os.getenv("GROQ_API_KEY"),http_client=httpx.Client(timeout=30.0))def call_llm_raw(messages: list) -> str:1 unmodified lineCall Groq with pre-built messages list.Used by V2 agent for Pass 1 and Pass 3."""response = _client.chat.completions.create(model="llama-3.3-70b-versatile",messages=messages,temperature=0.3,max_tokens=1500)return response.choices[0].message.content@retry(5 unmodified linesCall Groq Llama-3. Used by V1 agent.Retries 3 times with exponential backoff."""user_message = f"""QUESTION: {query}SUPREME COURT JUDGMENT EXCERPTS:{context}1 unmodified lineAnswer based only on the excerpts above. Cite judgment IDs.Use proper markdown formatting."""response = _client.chat.completions.create(model="llama-3.3-70b-versatile",messages=[{"role": "system", "content": "You are NyayaSetu, an Indian legal research assistant. Answer only from provided excerpts. Cite judgment IDs. End with: NOTE: This is not legal advice."},{"role": "user", "content": user_message}],temperature=0.1,max_tokens=1500)return response.choices[0].message.content6 unmodified lines789101112131 unmodified line151617181920212223242526272829301 unmodified line32333435363738394041424344454647485 unmodified lines54555657585960611 unmodified line63646566676869707172737475767778796 unmodified lines"""import osimport loggingfrom groq import Groqimport httpxfrom tenacity import retry, stop_after_attempt, wait_exponential1 unmodified lineload_dotenv()logger = logging.getLogger(__name__)api_key = os.getenv("GROQ_API_KEY")logger.info(f"GROQ_API_KEY loaded: {bool(api_key)} (length: {len(api_key) if api_key else 0})")_client = Groq(api_key=api_key,http_client=httpx.Client(timeout=30.0))logger.info("Groq client initialized successfully")def call_llm_raw(messages: list) -> str:1 unmodified lineCall Groq with pre-built messages list.Used by V2 agent for Pass 1 and Pass 3."""try:response = _client.chat.completions.create(model="llama-3.3-70b-versatile",messages=messages,temperature=0.3,max_tokens=1500)return response.choices[0].message.contentexcept Exception as e:logger.error(f"Groq API error in call_llm_raw: {type(e).__name__}: {str(e)}", exc_info=True)raise@retry(5 unmodified linesCall Groq Llama-3. Used by V1 agent.Retries 3 times with exponential backoff."""try:user_message = f"""QUESTION: {query}SUPREME COURT JUDGMENT EXCERPTS:{context}1 unmodified lineAnswer based only on the excerpts above. Cite judgment IDs.Use proper markdown formatting."""response = _client.chat.completions.create(model="llama-3.3-70b-versatile",messages=[{"role": "system", "content": "You are NyayaSetu, an Indian legal research assistant. Answer only from provided excerpts. Cite judgment IDs. End with: NOTE: This is not legal advice."},{"role": "user", "content": user_message}],temperature=0.1,max_tokens=1500)return response.choices[0].message.contentexcept Exception as e:logger.error(f"Groq API error in call_llm: {type(e).__name__}: {str(e)}", exc_info=True)raise
src/llm.py+34-19