-
Notifications
You must be signed in to change notification settings - Fork 9
Add custom AI chat instances feature #231
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
Conversation
Co-authored-by: MikeAlhayek <[email protected]>
Co-authored-by: MikeAlhayek <[email protected]>
… history support Co-authored-by: MikeAlhayek <[email protected]>
| } | ||
|
|
||
| var instances = await _instanceManager.GetAllAsync(); | ||
| var instanceList = instances.ToList(); |
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.
No need for the extra mutation.
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.
Fixed in d1d26ff - combined the GetAllAsync and ToList calls into a single statement.
src/Modules/CrestApps.OrchardCore.AI.Chat/Controllers/CustomChatController.cs
Show resolved
Hide resolved
| } | ||
|
|
||
| var instance = await _instanceManager.NewAsync(); | ||
| var model = await PopulateViewModelAsync(instance, isNew: true); |
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.
This is where we can use display manager too.
| /// <summary> | ||
| /// Represents a custom AI chat instance with user-defined configuration. | ||
| /// </summary> | ||
| public sealed class AICustomChatInstance : Entity |
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.
Maybe here we should inherit from AIProfile instead and follow the same things we do for AIProfile here in the CustomChat. We may want to also rename the Custom Chat to CustomAIProfile too.
| /// <summary> | ||
| /// Service for managing custom AI chat instances. | ||
| /// </summary> | ||
| public interface ICustomChatInstanceManager |
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.
We can instead implement ICatalogManager and register SourceCatalogManager<>
The store will register SourceDocumentCatalog<> to use reusable code
Co-authored-by: MikeAlhayek <[email protected]>
|
@copilot retry the work. |
- Model: AICustomChatInstance now inherits from SourceCatalogEntry - Index: AICustomChatInstanceIndex now inherits from CatalogItemIndex - Catalog: New ICustomChatInstanceCatalog and CustomChatInstanceCatalog - Manager: DefaultCustomChatInstanceManager now extends SourceCatalogManager - Controller: CustomChatController now uses IDisplayManager pattern - Display Driver: New AICustomChatInstanceDisplayDriver - Views: Updated to use DisplayManager shapes and EditCatalogEntryViewModel Co-authored-by: MikeAlhayek <[email protected]>
Completed the refactoring in e7b2bc4:
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
|
||
| var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); | ||
|
|
||
| var instances = (await _instanceManager.GetForCurrentUserAsync()).ToList(); |
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.
Don't add .ToList()
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.
Fixed in 1141918 - removed .ToList() and now using .Count() method since GetForCurrentUserAsync() returns IEnumerable.
|
|
||
| foreach (var entry in recentHistory) | ||
| { | ||
| var role = entry.Role?.ToLowerInvariant() == "user" ? ChatRole.User : ChatRole.Assistant; |
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 don't think we lower the role for comparison. I believe we already store it as ChatRole.
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.
Fixed in 1141918 - now using ChatRole directly from the ChatMessageEntry without string conversion.
| /// </summary> | ||
| public sealed class ChatMessageEntry | ||
| { | ||
| public string Role { get; set; } |
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.
Can't we store ChatRole instance instead of string?
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.
Fixed in 1141918 - changed ChatMessageEntry.Role to use ChatRole type instead of string.
| int startIndex = 0; | ||
| int endIndex = startIndex + Model.Models.Count - 1; |
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.
| int startIndex = 0; | |
| int endIndex = startIndex + Model.Models.Count - 1; | |
| var startIndex = 0; | |
| var endIndex = startIndex + Model.Models.Count - 1; |
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.
Fixed in 1141918 - now using var for the variable declarations.
|
|
||
| namespace CrestApps.OrchardCore.AI.Chat; | ||
|
|
||
| public static class AICustomChatPermissions |
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.
Move this in AICustomChatConstants so iot can be accessed AICustomChatConstants.Permissions.ManageOwnCustomChatInstances
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.
Fixed in 1141918 - moved the permission to AICustomChatConstants.Permissions.ManageOwnCustomChatInstances.
…e permission to Constants - Remove .ToList() from controller line 71 - Change ChatMessageEntry.Role to use ChatRole instead of string - Simplify AIChatHub to use ChatRole directly without string conversion - Use var instead of int for variable declarations in Index.cshtml - Move permission definition to AICustomChatConstants.Permissions class Co-authored-by: MikeAlhayek <[email protected]>
|
This pull request has merge conflicts. Please resolve those before requesting a review. |
Adds the ability for users to create and manage custom AI chat instances with their own configurations, without relying on predefined AI Profiles.
New Capabilities
ChatRoletyped messagesArchitecture
Following existing codebase patterns:
AICustomChatInstancemodel inheriting fromSourceCatalogEntrywith YesSql index and migrationsICustomChatInstanceCatalogextendingISourceCatalog<>with user-scoped queriesDefaultCustomChatInstanceManagerextendingSourceCatalogManager<>for CRUD operationsCustomChatControllerusingIDisplayManager<AICustomChatInstance>pattern (matchingProfilesController)AICustomChatInstanceDisplayDriverfor rendering editor and display shapesAIChatHubwithSendCustomChatMessageSignalR method supporting conversation historycustom-chat.jsfor real-time chat interfaceAICustomChatConstants.Permissions.ManageOwnCustomChatInstancespermission with admin menu integrationKey Files
src/Modules/CrestApps.OrchardCore.AI.Chat/Models/AICustomChatInstance.cssrc/Modules/CrestApps.OrchardCore.AI.Chat/Controllers/CustomChatController.cssrc/Modules/CrestApps.OrchardCore.AI.Chat/Drivers/AICustomChatInstanceDisplayDriver.cssrc/Modules/CrestApps.OrchardCore.AI.Chat/Services/CustomChatInstanceCatalog.cssrc/Modules/CrestApps.OrchardCore.AI.Chat/Hubs/AIChatHub.cssrc/Modules/CrestApps.OrchardCore.AI.Chat/Views/CustomChat/Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.