Skip to content
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

feat: support channel-specific and category-specific system prompts #83

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mmiguel6288
Copy link

Adds "channel_prompts" and "category_prompts" fields to the config yaml file. These are keyed by discord channel IDs and category IDs and contain specific system prompts. The server will use the channel-specific system prompt if defined, otherwise the category-specific system prompt, otherwise the default general system prompt.

@jakobdylanc
Copy link
Owner

Thanks for this!

One weakness I see is with threads. If a user creates a thread within a channel, the channel prompt will no longer apply, which isn't ideal.

I faced a similar issue with the allowed_channel_ids config - if a user creates a thread within an allowed channel, the bot would not reply in the thread. However I fixed this, and now any thread created within an allowed channel will work. See what I did here (using parent_id):

or (allowed_channel_ids and not is_dm and not any(id in allowed_channel_ids for id in (new_msg.channel.id, getattr(new_msg.channel, "parent_id", None))))

Ensure system prompts configured for a channel also apply to threads within that channel by checking the parent ID.
@mmiguel6288
Copy link
Author

Ah, thank you for pointing that out! I just updated the PR to try to use the parent_id if the initial channel ID lookup doesn't work. I just tested it out in a thread and it looks like it works.

@jakobdylanc
Copy link
Owner

jakobdylanc commented Dec 8, 2024

New idea:

  • change system_prompt to system_prompts
  • first entry is default for the main system prompt
  • the rest of the entries can be channel IDs OR category IDs, and the code checks for both
  • keep the same priority you proposed - channel ID > category ID > default

@mmiguel6288
Copy link
Author

That would be a simpler config file. The risk of a collision between a channel ID and a category ID should be low given that part of the bits in these ID fields are timestamps.

Replace system_prompt with system_prompts where first entry is the default prompt and additional entries are channel/category ID overrides. Maintain channel > category > default priority order.
@mmiguel6288 mmiguel6288 force-pushed the channel-specific-prompts branch from d663374 to 7e2e4a2 Compare December 9, 2024 04:45
@mmiguel6288
Copy link
Author

Ok I made the update you suggested.

@jakobdylanc
Copy link
Owner

Thanks!!

I'm going to keep thinking about this for now. You've actually inspired some other changes that I want to make first.

Namely, I want to make it so allowed_channel_ids accepts both channel IDs and category IDs.

Also, I want to rename allowed_role_ids to allowed_user_ids, and make it accept both user IDs and role IDs.

@mmiguel6288
Copy link
Author

Sounds good - I'll use my fork in the mean time. I love this project - makes it so easy to deploy an LLM home server without worrying about securing ports at home and what not - keep up the great work!

@jakobdylanc
Copy link
Owner

It would be a good idea if system_prompts accepted everything, e.g. user IDs, role IDs, channel IDs, and category IDs, with priority in that order. This would offer maximum control.

I imagine there is no risk of collision, but correct me if I'm wrong.

@mmiguel6288
Copy link
Author

That's an interesting idea. The priority ordering we were going for is more-specific to more-general. The hierarchy is clear for threads > channels > categories. The hierarchy is also clear for users > roles on their own. But the specificity ordering is less clear to me when we combine two hierarchies. If we do (users > roles > threads > channels > categories > default), then that means the user will be treated with the same user-specific system prompt everywhere in the server, even if you have thematically different channels. I think if the user is a bot that performs a specific function then I could see that being desirable, but if the user is a person, then that person can't participate in the themes set up in each channel, which is probably not desirable in most cases. Another option is to do (threads > channels > categories > users > roles > default) - however in that case, user-specific prompts will only apply in channels that don't have a custom channel/category-specific prompt. The latter prioritization makes sense to me for a user that is a person, but the former prioritization makes sense to me for a user that is a bot. There are probably other use cases I'm not thinking about. What do you think?

Regarding collisions, my understanding is that there is no risk of collisions across any of these. It looks like Discord uses snowflake IDs that contain millisecond resolution timestamps as well as an increment. https://discord.com/developers/docs/reference#snowflakes

@mmiguel6288
Copy link
Author

Another idea is to have the channel-like and user-like hierarchies be separate and append both to the system prompt sent to the LLM when both are applicable e.g. include the channel-specific prompt and also append the user-specific prompt so that the LLM sees both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants