-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add persistent synonyms with pdictng #134
Conversation
maybe a decorator, like requires_admin / hide? at least fewer # type: hides in the link it looks like a protocol might be the way to go, or a Command class that inherits from Callable but has more attributes.... mobfriend issue should be fixed, run |
Okay @technillogue , I pulled your fix from main (thx!) and then updated to a decorator and protocol. This fixes most of the issues with mypy, except for adding synonyms to an inherited method, because the signatures no longer match. Don't know how common this use case is though? Definitely reduced the amount of |
this is so exciting. |
I'm going to add the pdictng_readme.md document requested by @technillogue in #112 |
synonymbot.py
Outdated
class SynonymAttributes(Protocol): | ||
syns: list | ||
|
||
|
||
def has_synonyms(func: Any) -> SynonymAttributes: | ||
return func |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh FUCK YEAH
SynonymAttributes might need a __call__
?
synonymbot.py
Outdated
"""Build synonyms from in-code definitions. | ||
|
||
Run this command as admin when bot is first deployed. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm slightly confused about this workflow. Why not do this offline? examining pdict requires auth. (not saying don't do this, just curious)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh nvm i think i get it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apartly because accessing pdict requires await and I think you can't do in init.
It also allows to clear and reset the thesaurus while the bot is live w/o rebooting.
does that track?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's the grungy internals of manipulating aPersistDict.dict_ which can be done in a synchronous context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, or maybe just create_task inside of init? i was thinking about this today.
should the bot re-up on dev-installed commands when it reboots?
…imilarly to requires_admin, hide, and group_help_text on the imogen branch
* persistent synonyms working * synonyms in match_command * deal with edge cases for synonyms * move synonymbot to forest and update for new pdictng * switch from a protocol to only setting the synonyms in a decorator, similarly to requires_admin, hide, and group_help_text on the imogen branch Co-authored-by: technillogue <technillogue@gmail.com>
A bot with a thesaurus!
We want to be able to easily define synonyms for the various commands within bots: "hi" for "hello", "picture" for "imagine", etc.
I pulled the relevant logic out of #127 and put it into SynonymBot class, using the powerful aPersistDict for stateful storage of synonyms.
Devs can still add lists of synonyms to methods in development, but now admins and users can adjust the bot's vocabulary directly in Signal. The interface is roughly based on the syntax of
ln
in the command line, like so:link hello wazzup
SynonymBot has commands for linking, unlinking, listing synonyms, and more. It also has dialogue branches for various error states.
Still wondering:
Design/abstraction
Technical hurdles
type: ignore
but it seems to be an open issue in the community. Several hacky solutions are listed at Declare and use attributes of function objects python/mypy#2087NLP questions
link
andunlink
are available to users. This opens possibilities for abuse.string_dist
Happy to accept feedback on any of the above, or anything I missed.
Sample dialogue