File size: 2,334 Bytes
9363fb2 26dd121 9363fb2 26dd121 ee40810 26dd121 ee40810 26dd121 ee40810 26dd121 ee40810 26dd121 ee40810 26dd121 ee40810 26dd121 | 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 65 66 67 68 | 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)}"
|