import os from huggingface_hub import InferenceClient def _get_client() -> InferenceClient: return InferenceClient( model="Qwen/Qwen2.5-7B-Instruct", token=os.getenv("HF_TOKEN") ) def generate_weekly_plan(prompt: str) -> str: """ Calls the LLM with the full 7-day blueprint prompt. Returns the raw text output which will be split on [NUTRITION_MATRIX_START]. """ try: client = _get_client() response = client.chat_completion( messages=[ { "role": "system", "content": ( "You are a certified elite strength & conditioning coach " "and clinical Indian sports nutritionist. " "Produce structured, precise, professional output. " "Never use informal language, filler phrases, or excessive punctuation. " "Follow the exact format requested without deviation." ) }, {"role": "user", "content": prompt} ], max_tokens=3500, temperature=0.65 ) return response.choices[0].message.content except Exception as e: return f"[MODEL_ERROR] Unable to connect to inference endpoint: {str(e)}" def generate_flexspace_patch(prompt: str) -> str: """ Calls the LLM with a targeted FlexSpace alteration prompt. Expects a compact, surgical modification output. """ try: client = _get_client() response = client.chat_completion( messages=[ { "role": "system", "content": ( "You are an adaptive fitness coach performing a precision plan modification. " "Output only the modified day section in the original structured format. " "Be surgical — change only what conflicts with the constraint." ) }, {"role": "user", "content": prompt} ], max_tokens=900, temperature=0.55 ) return response.choices[0].message.content except Exception as e: return f"[MODEL_ERROR] FlexSpace patch failed: {str(e)}"