Skip to content

Commit

Permalink
Introduce "Safe" SystemDescription (microsoft#589)
Browse files Browse the repository at this point in the history
### Motivation and Context
<!-- Thank you for your contribution to the chat-copilot repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Stored system prompt references `TimeSkill `plugin that has been renamed
to `TimePlugin`.

System prompts for each chat have been stored in cosmosdb.


### Description
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

Dynamically intercept system-prompt and replace plugin reference.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [Contribution
Guidelines](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
  • Loading branch information
crickman authored Nov 10, 2023
1 parent ea64e21 commit 3e743f8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion webapi/Controllers/ChatArchiveController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private async Task<ChatArchive> CreateChatArchiveAsync(Guid chatId, Cancellation
chatArchive.ChatTitle = chat.Title;

// get the system description
chatArchive.SystemDescription = chat.SystemDescription;
chatArchive.SystemDescription = chat.SafeSystemDescription;

// get the chat history
chatArchive.ChatHistory = await this.GetAllChatMessagesAsync(chatIdString);
Expand Down
2 changes: 1 addition & 1 deletion webapi/Controllers/ChatHistoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public async Task<IActionResult> EditChatSessionAsync(
if (await this._sessionRepository.TryFindByIdAsync(chatId.ToString(), callback: v => chat = v))
{
chat!.Title = chatParameters.Title ?? chat!.Title;
chat!.SystemDescription = chatParameters.SystemDescription ?? chat!.SystemDescription;
chat!.SystemDescription = chatParameters.SystemDescription ?? chat!.SafeSystemDescription;
chat!.MemoryBalance = chatParameters.MemoryBalance ?? chat!.MemoryBalance;
await this._sessionRepository.UpsertAsync(chat);
await messageRelayHubContext.Clients.Group(chatId.ToString()).SendAsync(ChatEditedClientCall, chat);
Expand Down
5 changes: 5 additions & 0 deletions webapi/Models/Storage/ChatSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public class ChatSession : IStorageEntity
/// </summary>
public string SystemDescription { get; set; }

/// <summary>
/// Fixed system description with "TimeSkill" replaced by "TimePlugin"
/// </summary>
public string SafeSystemDescription => this.SystemDescription.Replace("TimeSkill", "TimePlugin", StringComparison.OrdinalIgnoreCase);

/// <summary>
/// The balance between long term memory and working term memory.
/// The higher this value, the more the system will rely on long term memory by lowering
Expand Down
2 changes: 1 addition & 1 deletion webapi/Plugins/Chat/ChatPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,6 @@ private async Task SetSystemDescriptionAsync(string chatId, CancellationToken ca
throw new ArgumentException("Chat session does not exist.");
}

this._promptOptions.SystemDescription = chatSession!.SystemDescription;
this._promptOptions.SystemDescription = chatSession!.SafeSystemDescription;
}
}

0 comments on commit 3e743f8

Please sign in to comment.