added functionality for hint generation and changed logging #107

Open
villac wants to merge 12 commits from villac/catsoop:feature/hint-generation into main
First-time contributor

Adds universal hint functionality through "view hint" with lots of context for any hint function.

Adds universal hint functionality through "view hint" with lots of context for any hint function.
hz requested changes 2025-12-19 18:31:28 +00:00
hz left a comment

Thanks for putting this in, @villac! I won't actually be able to do a full test of this for a little while (hopefully either this weekend or early next week), but I wanted to ask some initial questions and offer some initial suggestions from a quick look at the code. I'll have some more thoughts once I've been able to actually try it out.

Thanks for putting this in, @villac! I won't actually be able to do a full test of this for a little while (hopefully either this weekend or early next week), but I wanted to ask some initial questions and offer some initial suggestions from a quick look at the code. I'll have some more thoughts once I've been able to actually try it out.
@ -176,0 +176,4 @@
if ("hint" in thisone) {
document.getElementById(name + "_hint").innerHTML = thisone["hint"];
catsoop.run_all_scripts(name + "_hint");
}
Owner

The formatting here looks a little funny. Can you try running Prettier on this file to make sure the formatting is consistent throughout?

The formatting here looks a little funny. Can you try running [Prettier](https://prettier.io/) on this file to make sure the formatting is consistent throughout?
Author
First-time contributor

I think this should be resolved now

I think this should be resolved now
villac marked this conversation as resolved
@ -248,6 +252,7 @@ for (var i of [
"viewanswer",
"clearanswer",
"viewexplanation",
"view_hint",
Owner

I have a slight preference for naming this new action consistently with the existing ones (i.e., viewhint instead of view_hint).

I have a slight preference for naming this new action consistently with the existing ones (i.e., `viewhint` instead of `view_hint`).
Author
First-time contributor

should be updated everywhere now.

should be updated everywhere now.
villac marked this conversation as resolved
@ -599,0 +613,4 @@
Modeled after handle_viewanswer
:param context: dict of pretty much the whole website relative to a user
:param outdict: dict containing responses for each question
Owner

Catsoop formats docstrings a little differently from this. Please follow the docstring convention from, e.g., this file (for this one and for the other new functions here).

Catsoop formats docstrings a little differently from this. Please follow the docstring convention from, e.g., [this file](https://catsoop.org/git/catsoop/catsoop/src/branch/main/catsoop/cslog.py#L296-L310) (for this one and for the other new functions here).
Author
First-time contributor

Docstrings were updated

Docstrings were updated
@ -599,0 +632,4 @@
q, args = context[_n("name_map")][name]
defaults = q.get("defaults",{})
# important to add default values, but don't want to overwrite things
update_no_overwrite(args,defaults)
Owner

I would probably have tackled this a little bit differently, to avoid the need for the update_no_overwrite helper. We could instead do something like:

    info = q.get("defaults", {})
    info.update(args)

and then use info throughout instead of args.

I would probably have tackled this a little bit differently, to avoid the need for the `update_no_overwrite` helper. We could instead do something like: ``` info = q.get("defaults", {}) info.update(args) ``` and then use `info` throughout instead of `args`.
Author
First-time contributor

great suggestion, used it.

great suggestion, used it.
@ -599,0 +642,4 @@
fallback_default = lambda x: "no provided hints"
hint_func = args.get("csq_hint", fallback_default)
# default limit hints to 3 to limit # of API requests for LLM generated hints
Owner

Looking at some of the code below, it looks like this is really intended to work for LLM-generated hints first and foremost. I'm not a big LLM fan, but I'm fine with keeping things general here to allow for things like that. One thing I'm nervous about, though, is that I think it would be good to have an easy way to release multiple hard-coded hints.

For example, it would be nice to be able to specify a list of hard-coded, human-generated hints as well. With the current API, it feels like this will be a little painful; it feels like I would need to set something like the following for every question where i wanted to allow hints:

my_hints = [...]  # the hints i want to use

# boilerplate to let catsoop use these
num_hints = len(my_hints)
def csq_hint(x):
    return my_hints[len(x['viewed_hints'])]

I'll need to do some more testing to know for sure, but it feels like we might be able to generalize the API here a bit

Looking at some of the code below, it looks like this is really intended to work for LLM-generated hints first and foremost. I'm not a big LLM fan, but I'm fine with keeping things general here to allow for things like that. One thing I'm nervous about, though, is that I think it would be good to have an easy way to release multiple hard-coded hints. For example, it would be nice to be able to specify a list of hard-coded, human-generated hints as well. With the current API, it feels like this will be a little painful; it feels like I would need to set something like the following for every question where i wanted to allow hints: ``` my_hints = [...] # the hints i want to use # boilerplate to let catsoop use these num_hints = len(my_hints) def csq_hint(x): return my_hints[len(x['viewed_hints'])] ```` I'll need to do some more testing to know for sure, but it feels like we might be able to generalize the API here a bit
Author
First-time contributor

I've revamped the hint handling to allow for hard-coded hints. While my work is geared towards AI generated dynamic hints, I see the use of being able to set hard-coded hints easily as well. Additionally, there is support for a mix of the two approaches as well.

I've revamped the hint handling to allow for hard-coded hints. While my work is geared towards AI generated dynamic hints, I see the use of being able to set hard-coded hints easily as well. Additionally, there is support for a mix of the two approaches as well.
@ -599,0 +683,4 @@
full_hint_html += language.source_transform_string(context, raw_html)
# Add message that no more hints can be view if exceeding limit
if len(current_hints) >= num_hints:
Owner

Shouldn't this part short_circuit out earlier on? This will still invoke the hint function and add a new hint even if we're over the limit, won't it?

Shouldn't this part short_circuit out earlier on? This will still invoke the hint function and add a new hint even if we're over the limit, won't it?
Author
First-time contributor

This just makes sure we make sure to display that no more hints can be shown. It won't trigger the creation of a new hint; it just adds text to the display.

This just makes sure we make sure to display that no more hints can be shown. It won't trigger the creation of a new hint; it just adds text to the display.
@ -599,0 +710,4 @@
count = len(h_list)
current_hint_counts[n] = count
# log submission in problemactions
Owner

Maybe this should say "log this action" or similar, since this isn't really a submission, per se.

Maybe this should say "log this action" or similar, since this isn't really a submission, per se.
villac marked this conversation as resolved
@ -1578,0 +1746,4 @@
error = "This question is not yet available."
elif not _get(qargs, "csq_allow_view_hint", True, bool):
error = "Viewing the hint is not allowed for this question."
else:
Owner

I feel like we're also missing an option here where we've already viewed the max number of hints; in that case, we should error out as well, I think.

I feel like we're also missing an option here where we've already viewed the max number of hints; in that case, we should error out as well, I think.
Author
First-time contributor

You're right. I fixed that and also added handling for allowing viewing hints before submission based on flag settings.

You're right. I fixed that and also added handling for allowing viewing hints before submission based on flag settings.
@ -1578,0 +1750,4 @@
lastlog = context[_n("last_log")]
score = lastlog.get("scores", {}).get(name)
if score is None:
error = "You must submit an answer before viewing a hint."
Owner

Hmmm, maybe this restriction is also one that we should put behind an option? Some people only allow a single submission for a question, in which case disallowing hints altogether might not be desirable.

Hmmm, maybe this restriction is also one that we should put behind an option? Some people only allow a single submission for a question, in which case disallowing hints altogether might not be desirable.
villac marked this conversation as resolved
Author
First-time contributor

I just now had a chance to read these comments. I don't think I'll be able to resolve these comments until after the IAP course I am working on concludes, but these are helpful comments. Once IAP is over/if I can find the time before then, I'll resolve these points and make some updates to other additions to the logging I have done since submitting this.

I just now had a chance to read these comments. I don't think I'll be able to resolve these comments until after the IAP course I am working on concludes, but these are helpful comments. Once IAP is over/if I can find the time before then, I'll resolve these points and make some updates to other additions to the logging I have done since submitting this.
villac changed title from added functionality for hint generation and changed logging to WIP: added functionality for hint generation and changed logging 2026-01-08 21:13:03 +00:00
villac force-pushed feature/hint-generation from 3a5bc51c1c to 682c62d879 2026-02-24 06:42:31 +00:00 Compare
villac changed title from WIP: added functionality for hint generation and changed logging to added functionality for hint generation and changed logging 2026-02-24 06:49:58 +00:00
Author
First-time contributor

Hi Adam, there have been some substantial revisions since you last viewed this pull request. I appreciated all your thoughts and implemented all your comments. I think the most notable change is the new Hint Handler class which abstracts hint handling more and allows for easier definition of hard-coded or function specific hints. It should be noted that this version of CAT-SOOP was used for the IAP 2026 offering of Practical Computational Thinking. I hope that if we can integrate this work it may be used in other classes as well.

Hi Adam, there have been some substantial revisions since you last viewed this pull request. I appreciated all your thoughts and implemented all your comments. I think the most notable change is the new Hint Handler class which abstracts hint handling more and allows for easier definition of hard-coded or function specific hints. It should be noted that this version of CAT-SOOP was used for the IAP 2026 offering of Practical Computational Thinking. I hope that if we can integrate this work it may be used in other classes as well.
villac force-pushed feature/hint-generation from 682c62d879 to 4678a590b3 2026-03-08 04:34:54 +00:00 Compare
villac force-pushed feature/hint-generation from f608ab6560 to ae904cddbf 2026-04-26 02:02:32 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'feature/hint-generation:villac-feature/hint-generation'
git switch 'villac-feature/hint-generation'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'villac-feature/hint-generation'
git switch 'villac-feature/hint-generation'
git rebase 'main'
git switch 'main'
git merge --ff-only 'villac-feature/hint-generation'
git switch 'villac-feature/hint-generation'
git rebase 'main'
git switch 'main'
git merge --no-ff 'villac-feature/hint-generation'
git switch 'main'
git merge --squash 'villac-feature/hint-generation'
git switch 'main'
git merge --ff-only 'villac-feature/hint-generation'
git switch 'main'
git merge 'villac-feature/hint-generation'
git push origin 'main'
Sign in to join this conversation.
No reviewers
hz
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
catsoop/catsoop!107
No description provided.