Loading ad...

Building the Assistant Backend

Zack’s assistant could do a lot:

  • Summarize his inbox into a daily digest
  • Draft email replies in multiple styles
  • Transcribe meetings
  • Summarize transcripts and extract action items

It worked beautifully, but it was also messy. Each feature was its own Python script. Zack had to remember file names, run them one by one, and copy-paste results between them.

“This is powerful,” Zack thought, “but it doesn’t feel like one assistant. It feels like a toolbox.”

That’s when he realized he needed a backend, a single application where all these scripts could live, organized and accessible.

Step 1: Implement backend

Zack listed the problems with running separate scripts:

  • Too many entry points: One script for emails, one for replies, one for transcription.
  • Hard to share: If his colleague Sara wanted to try, she’d have to install everything and run Python commands.
  • No integration: Email summaries weren’t feeding into reply drafts. Meeting transcripts weren’t automatically turned into notes.

A backend API would solve this.

  • One server running in the background.
  • Endpoints like /summarize_email, /draft_reply, /transcribe_meeting.
  • A simple way to connect to a future frontend (dashboard or Slack bot).

In short: the backend would turn Zack’s toolbox into a real assistant service.

Step 2: Flask vs FastAPI

Zack researched two popular frameworks for Python APIs:

  • Flask:
    • Simple, lightweight, great for beginners.
    • Easy to set up routes (/summarize, /transcribe).
    • Lots of tutorials.
  • FastAPI:
    • Modern, faster performance.
    • Automatic documentation (Swagger UI).
    • More structured (good for bigger projects).

Since Zack was still learning, he chose Flask. Later, he could switch to FastAPI if he needed advanced features.

Step 3: Setting up the Flask project

In his assistant folder, Zack created this structure:

1
2
3
4
5
6
7
8
assistant/
│── app.py
│── services/
│    ├── email_summary.py
│    ├── reply_drafts.py
│    ├── meeting_transcription.py
│    └── meeting_summary.py
│── requirements.txt

This way, each feature lived in its own file, and app.py tied them together.

Step 4: Writing the Flask backend

Here’s Zack’s first version of app.py:

python
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
from flask import Flask, request, jsonify
from services import email_summary, reply_drafts, meeting_transcription, meeting_summary

app = Flask(__name__)

@app.route("/summarize_email", methods=["POST"])
def summarize_email():
    data = request.json
    email_text = data.get("email", "")
    result = email_summary.summarize_email(email_text)
    return jsonify({"summary": result})

@app.route("/draft_reply", methods=["POST"])
def draft_reply():
    data = request.json
    email_text = data.get("email", "")
    result = reply_drafts.generate_replies(email_text)
    return jsonify({"drafts": result})

@app.route("/transcribe_meeting", methods=["POST"])
def transcribe_meeting():
    file = request.files["audio"]
    filepath = f"uploads/{file.filename}"
    file.save(filepath)
    result = meeting_transcription.transcribe(filepath)
    return jsonify({"transcript": result})

@app.route("/summarize_meeting", methods=["POST"])
def summarize_meeting():
    data = request.json
    transcript = data.get("transcript", "")
    result = meeting_summary.summarize(transcript)
    return jsonify(result)

if __name__ == "__main__":
    app.run(debug=True, port=5000)

Step 5: Creating the service files

Each service file wrapped the logic Zack had already built in earlier lessons.

services/email_summary.py

python
1
2
3
4
5
6
7
8
9
10
from openai import OpenAI
client = OpenAI()

def summarize_email(email_text):
    prompt = f"Summarize this email in one sentence, highlighting the main request and any deadlines:\n\n{email_text}"
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": prompt}]
    )
    return response.choices[0].message.content.strip()

services/reply_drafts.py

python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from openai import OpenAI
client = OpenAI()

def generate_replies(email_text):
    prompt = f"""
    Create three possible replies to this email:
    1. Short and direct
    2. Polite and formal
    3. Casual or bullet-point style

    Email:
    {email_text}
    """
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": prompt}]
    )
    return response.choices[0].message.content.strip().split("\n")

services/meeting_summary.py

python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from openai import OpenAI
client = OpenAI()

def summarize(transcript):
    prompt = f"""
    You are a meeting assistant. Summarize the following transcript in 3–5 sentences, then extract action items in JSON with keys owner, task, due_date.

    Transcript:
    {transcript}
    """
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": prompt}]
    )
    return {"output": response.choices[0].message.content.strip()}

Step 6: Running the server

In his terminal, Zack ran:

python
1
python app.py

Flask started a server on http://127.0.0.1:5000/.

Now he could test endpoints with Postman or curl.

Example: summarize an email

1
2
3
curl -X POST http://127.0.0.1:5000/summarize_email \
     -H "Content-Type: application/json" \
     -d '{"email":"Hi Zack, can you send the updated project plan by Friday?"}'

Output:

json
1
{"summary": "Request to send the updated project plan by Friday."}

Step 7: Exercise

Your task:

  1. Set up the Flask project with the structure above.
  2. Implement at least two endpoints (/summarize_email and /draft_reply).
  3. Test them with curl or Postman.

Expected:

  • Input: JSON with email text.
  • Output: summary or list of drafts.

Step 8: Zack’s reflection

After building the backend, Zack felt a shift.

“Now it’s not just code,” he thought. “It’s a service.”

  • He could run one server and access all features.
  • He could share the endpoints with Sara, who didn’t know Python.
  • He could imagine a frontend dashboard or Slack integration plugging into this backend.

For the first time, Zack’s assistant felt like a real product, not just a bunch of scripts.

Conclusion

In this lesson, Zack’s assistant evolved again:

  • He learned why a backend matters for integration and sharing.
  • He chose Flask for simplicity.
  • He built a structured project with separate services.
  • He ran an API server with endpoints for emails, replies, transcription, and meeting summaries.
  • He tested it with curl/Postman.

Now the assistant was becoming something Zack could use daily and even share with his team.

In the next lesson, Zack will focus on creating a simple frontend dashboard, where he can click buttons instead of running curl commands. That’s when his assistant becomes truly user-friendly.

Frequently Asked Questions

A backend combines multiple scripts into one service. It makes your assistant easier to use, integrate, and share with others.

Flask is simpler for beginners, with less setup. FastAPI is faster and has built-in docs, but Flask is great for learning and small projects.

Endpoints for summarizing emails, drafting replies, transcribing meetings, and summarizing transcripts into notes and action items.

You can send requests using curl in the terminal or use Postman/Insomnia to test endpoints with JSON input.

Still have questions?Contact our support team