Skip to content

Commit 89f44a0

Browse files
added docstrings to server functions
1 parent f3608c8 commit 89f44a0

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

app/api/server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,27 @@
1616

1717
@app.get("/")
1818
def home():
19+
"""Render the home page of the chatbot application."""
1920
return render_template("index.html")
2021

2122

2223
@app.post("/query")
2324
@limiter.limit("60 per minute") # limit LLM calls
2425
def query():
26+
"""Process a user query using RAG (Retrieval-Augmented Generation).
27+
28+
Retrieves relevant documents from the vector store and generates a
29+
response using the LLM with the retrieved context.
30+
"""
2531
q = request.json["query"]
2632
context = retrieve_top_k(q, k=10)
2733
answer = generate_response(q, context)
2834
return jsonify({"answer": answer})
2935

3036

31-
# rate limit error response
3237
@app.errorhandler(429)
3338
def ratelimit_handler(e):
39+
"""Handle rate limit exceeded errors."""
3440
return jsonify({
3541
"error": "Rate limit exceeded. Please slow down."
3642
}), 429

app/api/testing_server.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828
questions : list[str] = list(set(p["question"] for p in pairs))
2929
configs : list[str] = list(set(p["config"] for p in pairs))
3030

31-
# prepare all unique pairs of configs for each question and insert into db if not already there
3231
def prepare_pairs():
32+
"""Prepare and insert unique configuration pairs for A/B testing.
33+
34+
For each question, generates all unique pairs of configurations and inserts
35+
them into the ab_pairs table if they don't already exist.
36+
"""
3337
conn = get_db_connection()
3438
cur = conn.cursor()
3539
# insert unique pairs of configs for each question into the ab_pairs table (if they don't already exist)
@@ -53,8 +57,13 @@ def prepare_pairs():
5357
conn.close()
5458

5559

56-
# get the next unanswered pair from the db, along with the corresponding answers, and randomize left/right
5760
def get_next_pair() -> tuple[int, str, dict, dict] | None:
61+
"""Retrieve the next unanswered A/B testing pair with randomized positioning.
62+
63+
Fetches an unanswered comparison pair from the database along with their
64+
corresponding answers. Randomly assigns configs to left/right positions
65+
to avoid position bias.
66+
"""
5867
conn = get_db_connection()
5968
cur = conn.cursor()
6069

@@ -95,6 +104,11 @@ def get_next_pair() -> tuple[int, str, dict, dict] | None:
95104

96105
@app.route("/")
97106
def index():
107+
"""Render the A/B evaluation interface with the next comparison pair.
108+
109+
Fetches the next unanswered pair and renders the evaluation template.
110+
Returns a completion message when all pairs have been evaluated.
111+
"""
98112
pair = get_next_pair()
99113

100114
if not pair:
@@ -113,6 +127,12 @@ def index():
113127

114128
@app.route("/vote", methods=["POST"])
115129
def vote():
130+
"""Process and save a user's vote for an A/B comparison pair.
131+
132+
Extracts the pair_id and winner choice from the form submission, records
133+
the vote in ab_results, marks the pair as answered, and redirects to the
134+
next evaluation.
135+
"""
116136
pair_id = request.form["pair_id"]
117137
winner = request.form["winner"]
118138

0 commit comments

Comments
 (0)