- ingests fitness data from CSV using pandas,
- collects user fitness goals interactively,
- composes a chat message sequence (system, assistant, user),
- calls a language model to generate role-specific, actionable recommendations.

What we’ll build
- Load a CSV into a pandas DataFrame and summarize it.
- Collect user goals into a
goalslist. - Build a
trainerfunction that assembles chat messages (user goals + system/assistant context) and calls the model. - Refine the assistant prompt to return direct, role-aware, point-form recommendations.
Prerequisites
Install pandas if you don’t have it:"YOUR_API_KEY" in the example with a secure retrieval method (e.g., environment variable).
Minimal, complete example
The script below demonstrates a compact implementation. It:- reads a CSV into a DataFrame,
- gathers goals interactively,
- builds the chat
messageslist, - sends the request to the model and prints the response.
How the message sequence works
The assistant receives three kinds of messages:
This ordering ensures the model sees the user goals plus clear, role-specific context and a compact data snapshot.
Typical interactive run (example)
Example model output (trimmed and formatted)
Prompt refinement tips
- Be explicit about role and required output style (e.g., “The person is an accountant. Respond: Direct. Point form.”).
- Avoid including large raw datasets in prompts. Instead:
- Send
df.head().to_string()ordf.describe()snippets, - Or extract key columns and aggregate statistics.
- Send
- If you need repeated or more detailed data analysis, run offline analysis with pandas and provide only the relevant derived metrics to the model.
Avoid sending very large raw datasets directly in prompts. Summarize or extract key columns/rows to keep prompts concise and within token limits.
Best practices and security
- Store API keys securely (environment variables, secrets managers).
- Sanitize any sensitive user data before sending to remote APIs.
- Use conservative temperature settings for reproducible, factual recommendations when needed.
- Log prompts and model outputs carefully, respecting privacy and compliance requirements.
Links and References
- pandas documentation
- OpenAI API docs (or your model provider’s docs)
- Kubernetes Basics — for deploying services (if you plan to containerize and deploy)