refactor: migrate API key storage from API_KEY.txt to activity_root/data#97
refactor: migrate API key storage from API_KEY.txt to activity_root/data#97adarshkumar23 wants to merge 5 commits intosugarlabs:mainfrom
Conversation
Replace the flat-file API_KEY.txt approach with Sugar's standard activity_root/data/ directory for persistent per-activity configuration. - LLM.py: Read/write API key from get_activity_root()/data/api_key - LLM.py: Add save_api_key() helper for programmatic key persistence - activity.py: Export save_api_key for future settings UI integration - README.md: Add API key configuration section Ref: sugarlabs#60 (comment)
mebinthattil
left a comment
There was a problem hiding this comment.
Thank you for these changes, would love to see a screen recording of these changes in action inside sugar / screenshots of these changes working.
Also include info on how to request for an API key from Sugar-AI. Check the Sugar-AI docs for more context.
|
|
||
| else: | ||
| print("Error, LLM did not respond") | ||
| print("Error, LLM did not respond") No newline at end of file |
There was a problem hiding this comment.
No newline in EOF. Diff your changes before pushing from next time, you'll be able to catch these.
There was a problem hiding this comment.
Fixed in 57cb868. Here's the diff confirming the change:
Also noted — will run git diff --staged before every commit going forward.
Fixing.EOF.Line.in.LLM.py.and.Review.Comments.mp4
There was a problem hiding this comment.
I was asking about a screen recording of you running these changes inside the activity and not just running LLM.py in your terminal.
Please send that video. Be sure to test it inside of sugar.
Summary
Replaces the flat-file
API_KEY.txtapproach with Sugar's standardactivity_root/data/directory for persistent per-activity configuration, as discussed by @mebinthattil in #60.Problem
The current code reads the API key from
API_KEY.txtin the bundle's working directory. This has several issues:get_activity_root()/data/for persistent configurationChanges
LLM.py: Read/write the API key fromget_activity_root()/data/api_keyinstead ofAPI_KEY.txtLLM.py: Addsave_api_key()public helper for programmatic key persistence (enables future settings UI)LLM.py: Improve error messages to log the expected key file pathactivity.py: Exportsave_api_keyfrom the LLM importREADME.md: Add "API Key Configuration" section documenting the new storage locationHow it works
The
data/subdirectory ofget_activity_root()survives across activity invocations and is the Sugar-standard location for per-activity persistent state. This is the same pattern already used inchat.py(line 249).If no key is found, the activity logs the expected path and gracefully falls back to the on-device SLM or AIML brain — no crash.
Related
TODOcomment:#TODO: Dont hard code these, need to see how sugar as a whole manages API Keys