Rahaf2001 commited on
Commit
e6ac99d
·
verified ·
1 Parent(s): ecadd64

Delete llm_integration.py

Browse files
Files changed (1) hide show
  1. llm_integration.py +0 -57
llm_integration.py DELETED
@@ -1,57 +0,0 @@
1
- # llm_integration.py
2
- import os
3
-
4
- # Try to set up an OpenAI client. If anything fails, keep _client=None so the app still runs.
5
- try:
6
- from openai import OpenAI
7
- _client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
8
- _model = os.getenv("OPENAI_MODEL", "gpt-4o-mini") # change if you use Azure/OpenRouter
9
- except Exception as e:
10
- _client = None
11
- _model = None
12
-
13
- DISABLED_MSG = (
14
- "[LLM disabled] Install 'openai' and set the OPENAI_API_KEY secret "
15
- "in your Space settings to enable AI-generated plans."
16
- )
17
-
18
- def _chat(system: str, user: str, temperature: float = 0.4) -> str:
19
- """Small helper that calls the model or returns a friendly fallback."""
20
- if _client is None or _model is None:
21
- return DISABLED_MSG
22
- try:
23
- resp = _client.chat.completions.create(
24
- model=_model,
25
- messages=[{"role": "system", "content": system},
26
- {"role": "user", "content": user}],
27
- temperature=temperature,
28
- )
29
- return (resp.choices[0].message.content or "").strip()
30
- except Exception as e:
31
- # Keep the UI responsive even if the API fails
32
- return f"[LLM error] {e}"
33
-
34
- def agent_workout_llm(level: str, days_per_week: int, goal: str, equipment: str) -> str:
35
- system = (
36
- "You are a certified strength coach. Create concise, beginner-safe weekly training plans. "
37
- "Prefer compound movements, progressive overload, clear sets x reps, and brief cues."
38
- )
39
- user = (
40
- f"Design a {int(days_per_week)}-day plan for a {level} user. "
41
- f"Goal: {goal}. Equipment: {equipment}. "
42
- "Format with bullets, include sets x reps, rest times, and 1–2 safety tips."
43
- )
44
- return _chat(system, user, temperature=0.35)
45
-
46
- def agent_nutrition_llm(weight_kg: float, target_kcal: int,
47
- liked_csv: str, avoid_csv: str, meals: int) -> str:
48
- system = (
49
- "You are a registered dietitian. Provide practical beginner nutrition plans. "
50
- "Respect preferences and allergies. Keep portions realistic."
51
- )
52
- user = (
53
- f"Create a {int(meals)}-meal/day plan ≈{int(target_kcal)} kcal for a {float(weight_kg)} kg person. "
54
- f"Preferred foods: {liked_csv or 'none'}. Avoid: {avoid_csv or 'none'}. "
55
- "Include approximate macros per meal and a short grocery list."
56
- )
57
- return _chat(system, user, temperature=0.35)