Skip to content

Commit

Permalink
Merge pull request #342 from microsoft/block-deletion-of-global-assis…
Browse files Browse the repository at this point in the history
…tants

block deletion of global assistant assets
  • Loading branch information
gloveboxes authored Oct 2, 2024
2 parents 66d6888 + 6132d5c commit 506df7e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/AzureAIProxy.Shared/Database/Assistant.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
namespace AzureAIProxy.Shared.Database;
using System.ComponentModel.DataAnnotations.Schema;

public enum Scope
{
Personal,
Global
}

public partial class Assistant
{
public string ApiKey { get; set; } = null!;
public string Id { get; set; } = null!;

[NotMapped]
public Scope Scope { get; set; } = Scope.Personal; // Default to Personal
}
2 changes: 2 additions & 0 deletions src/AzureAIProxy/Routes/AzureOpenAIAssistants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ private static async Task<IResult> CreateThreadAsync(
var assistant = await assistantService.GetIdAsync(requestContext.ApiKey, assistantId.Split("/").First());
if (assistant is null)
return OpenAIResult.Unauthorized("Unauthorized assistant access.");
else if (method == HttpMethod.Delete.Method && assistant.Scope == Scope.Global)
return OpenAIResult.Unauthorized("Unauthorized assistant deletion.");
}
else if (threadId is not null)
{
Expand Down
3 changes: 2 additions & 1 deletion src/AzureAIProxy/Services/AssistantService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public async Task DeleteIdAsync(string apiKey, string responseContent)
result = new Assistant
{
ApiKey = apiKey,
Id = id
Id = id,
Scope = Scope.Global
};
memoryCache.Set(cacheKey, result, TimeSpan.FromMinutes(10));
}
Expand Down

0 comments on commit 506df7e

Please sign in to comment.