Skip to content

Commit

Permalink
block deletion of global assistant assets
Browse files Browse the repository at this point in the history
- added enum scope
- tagged global with Scope.Global
- Check deletion requests for Global and return not authorised
  • Loading branch information
gloveboxes committed Oct 2, 2024
1 parent 66d6888 commit 6132d5c
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 6132d5c

Please sign in to comment.