Skip to content

Commit

Permalink
Organize commands under tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed May 30, 2024
1 parent 1fc6b5c commit 6c5f7c8
Show file tree
Hide file tree
Showing 34 changed files with 104 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace MyApp.ServiceInterface.AiServer;

[Tag(Tags.AI)]
public class CreateAnswerCommentTaskCommand(AppConfig appConfig) : IAsyncCommand<CreateAnswerCommentTask>
{
public const string SystemPrompt =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MyApp.ServiceInterface.AiServer;

[Tag(Tags.AI)]
public class CreateAnswerTasksCommand(ILogger<CreateAnswerTasksCommand> log,
AppConfig appConfig, QuestionsProvider questions) : IAsyncCommand<CreateAnswerTasks>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MyApp.ServiceInterface.AiServer;

[Tag(Tags.AI)]
public class CreateRankAnswerTaskCommand(AppConfig appConfig, QuestionsProvider questions) : IAsyncCommand<CreateRankAnswerTask>
{
//https://github.com/f/awesome-chatgpt-prompts?tab=readme-ov-file#act-as-a-tech-reviewer
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/AnswerAddedToPostCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Answers)]
public class AnswerAddedToPostCommand(IDbConnection db) : IAsyncCommand<AnswerAddedToPost>
{
public async Task ExecuteAsync(AnswerAddedToPost request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/AppDbPeriodicTasksCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Database)]
public class AppDbPeriodicTasksCommand(ILogger<AppDbPeriodicTasksCommand> log,
AppConfig appConfig, IDbConnectionFactory dbFactory, IMessageProducer mq, EmailRenderer renderer)
: IAsyncCommand<PeriodicTasks>
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/CreateAnswerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Answers)]
public class CreateAnswerCommand(AppConfig appConfig, IDbConnection db) : IAsyncCommand<Post>
{
public async Task ExecuteAsync(Post answer)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/CreateCommentVoteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Database)]
public class CreateCommentVoteCommand(IDbConnection db, QuestionsProvider questions) : IAsyncCommand<Vote>
{
public async Task ExecuteAsync(Vote vote)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/CreateFlagCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Database)]
public class CreateFlagCommand(IDbConnection db) : IAsyncCommand<Flag>
{
public async Task ExecuteAsync(Flag request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/CreateNotificationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Notifications)]
public class CreateNotificationCommand(AppConfig appConfig, IDbConnection db) : IAsyncCommand<Notification>
{
public async Task ExecuteAsync(Notification request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/CreatePostCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Questions)]
public class CreatePostCommand(ILogger<CreatePostCommand> log, AppConfig appConfig, IDbConnection db) : IAsyncCommand<Post>
{
public async Task ExecuteAsync(Post post)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/CreatePostVoteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Database)]
public class CreatePostVoteCommand(AppConfig appConfig, IDbConnection db, IMessageProducer mqClient) : IAsyncCommand<Vote>
{
public async Task ExecuteAsync(Vote vote)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/DeleteAnswersCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Answers)]
public class DeleteAnswersCommand(IDbConnection db) : IAsyncCommand<DeleteAnswers>
{
public async Task ExecuteAsync(DeleteAnswers request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/DeleteCommentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Database)]
public class DeleteCommentCommand(AppConfig appConfig, IDbConnection db) : IAsyncCommand<DeleteComment>
{
public async Task ExecuteAsync(DeleteComment request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/DeletePostsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Database)]
public class DeletePostsCommand(AppConfig appConfig, IDbConnection db) : IAsyncCommand<DeletePosts>
{
public async Task ExecuteAsync(DeletePosts request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/ImportQuestionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Questions)]
public class ImportQuestionCommand(ILogger<ImportQuestionCommand> log, AppConfig appConfig) : IAsyncCommand<ImportQuestion>
{
static readonly Regex ValidTagCharsRegex = new("[^a-zA-Z0-9#+.]", RegexOptions.Compiled);
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/MarkAsReadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Notifications)]
public class MarkAsReadCommand(AppConfig appConfig, IDbConnection db) : IAsyncCommand<MarkAsRead>
{
public async Task ExecuteAsync(MarkAsRead request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/MarkPostAsReadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Notifications)]
public class MarkPostAsReadCommand(AppConfig appConfig, IDbConnection db, QuestionsProvider questions) : IAsyncCommand<MarkPostAsRead>
{
public async Task ExecuteAsync(MarkPostAsRead request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/NewCommentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Database)]
public class NewCommentCommand(AppConfig appConfig, IDbConnection db) : IAsyncCommand<NewComment>
{
public async Task ExecuteAsync(NewComment request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/PostSubscriptionsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Notifications)]
public class PostSubscriptionsCommand(IDbConnection db) : IAsyncCommand<PostSubscriptions>
{
public async Task ExecuteAsync(PostSubscriptions request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/SaveGradeResultCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Answers)]
public class SaveGradeResultCommand(AppConfig appConfig, IDbConnection db, IMessageProducer mq, WorkerAnswerNotifier answerNotifier)
: IAsyncCommand<StatTotals>
{
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/TagSubscriptionsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Notifications)]
public class TagSubscriptionsCommand(IDbConnection db) : IAsyncCommand<TagSubscriptions>
{
public async Task ExecuteAsync(TagSubscriptions request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/UpdatePostCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Questions)]
public class UpdatePostCommand(IDbConnection db) : IAsyncCommand<Post>
{
public async Task ExecuteAsync(Post question)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/App/UpdateReputationsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MyApp.ServiceInterface.App;

[Tag(Tags.Notifications)]
public class UpdateReputationsCommand(AppConfig appConfig, IDbConnection db) : IAsyncCommand<UpdateReputations>
{
public async Task ExecuteAsync(UpdateReputations request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/CreatorKit/SendMailRunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace MyApp.ServiceInterface.CreatorKit;

[Tag(Tags.CreatorKit)]
public class SendMailRunCommand(
ILogger<SendMailRunCommand> log,
IDbConnectionFactory dbFactory,
Expand Down
2 changes: 2 additions & 0 deletions MyApp.ServiceInterface/CreatorKit/SendMessagesCommand.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using CreatorKit.ServiceModel.Types;
using MyApp.Data;
using MyApp.ServiceInterface;
using MyApp.ServiceModel;
using ServiceStack;
using ServiceStack.Data;
using ServiceStack.OrmLite;

namespace CreatorKit.ServiceInterface;

[Tag(Tags.CreatorKit)]
public class SendMessagesCommand(IDbConnectionFactory dbFactory, EmailProvider emailProvider) : IAsyncCommand<SendMailMessages>
{
public async Task ExecuteAsync(SendMailMessages request)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/Data/Tasks.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MyApp.ServiceInterface;
using MyApp.ServiceInterface.AiServer;
using MyApp.ServiceInterface.App;
using MyApp.ServiceInterface.Jobs;
using MyApp.ServiceModel;
using ServiceStack;
using ServiceStack.DataAnnotations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
using System.Data;
using MyApp.Data;
using MyApp.ServiceModel;
using ServiceStack;
using ServiceStack.Messaging;
using ServiceStack.OrmLite;
using MyApp.Data;
using MyApp.ServiceModel;

namespace MyApp.ServiceInterface.App;
namespace MyApp.ServiceInterface.Jobs;

public class CompletePostJobsCommand(IDbConnection Db, ModelWorkerQueue modelWorkers, IMessageProducer mqClient) : IAsyncCommand<CompletePostJobs>
[Tag(Tags.Jobs)]
public class CompletePostJobsCommand(IDbConnection db, ModelWorkerQueue modelWorkers, IMessageProducer mqClient) : IAsyncCommand<CompletePostJobs>
{
public async Task ExecuteAsync(CompletePostJobs request)
{
var jobIds = request.Ids;
await Db.UpdateOnlyAsync(() => new PostJob {
await db.UpdateOnlyAsync(() => new PostJob {
CompletedDate = DateTime.UtcNow,
},
x => jobIds.Contains(x.Id));
var postJobs = await Db.SelectAsync(Db.From<PostJob>()
var postJobs = await db.SelectAsync(db.From<PostJob>()
.Where(x => jobIds.Contains(x.Id)));

foreach (var postJob in postJobs)
{
// If there's no outstanding model answer jobs for this post, add a rank job
if (!await Db.ExistsAsync(Db.From<PostJob>()
if (!await db.ExistsAsync(db.From<PostJob>()
.Where(x => x.PostId == postJob.PostId && x.CompletedDate == null)))
{
var rankJob = new PostJob
Expand All @@ -33,7 +34,7 @@ public async Task ExecuteAsync(CompletePostJobs request)
CreatedDate = DateTime.UtcNow,
CreatedBy = nameof(DbWrites),
};
await Db.InsertAsync(rankJob);
await db.InsertAsync(rankJob);
modelWorkers.Enqueue(rankJob);
mqClient.Publish(new SearchTasks { AddPostToIndex = postJob.PostId });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Data;
using MyApp.Data;
using ServiceStack;
using ServiceStack.OrmLite;
using MyApp.Data;

namespace MyApp.ServiceInterface.App;
namespace MyApp.ServiceInterface.Jobs;

[Tag(Tags.Jobs)]
public class CreatePostJobsCommand(IDbConnection db, ModelWorkerQueue modelWorkers) : IAsyncCommand<CreatePostJobs>
{
public async Task ExecuteAsync(CreatePostJobs request)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Data;
using ServiceStack;
using ServiceStack.OrmLite;
using MyApp.Data;
using MyApp.ServiceModel;
using ServiceStack;
using ServiceStack.OrmLite;

namespace MyApp.ServiceInterface.App;
namespace MyApp.ServiceInterface.Jobs;

[Tag(Tags.Jobs)]
public class FailJobCommand(IDbConnection db, ModelWorkerQueue modelWorkers) : IAsyncCommand<FailJob>
{
public async Task ExecuteAsync(FailJob request)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Data;
using ServiceStack;
using ServiceStack.OrmLite;
using MyApp.Data;
using MyApp.ServiceModel;
using ServiceStack;
using ServiceStack.OrmLite;

namespace MyApp.ServiceInterface.App;
namespace MyApp.ServiceInterface.Jobs;

[Tag(Tags.Jobs)]
public class StartJobCommand(IDbConnection db) : IAsyncCommand<StartJob>
{
public async Task ExecuteAsync(StartJob job)
Expand Down
1 change: 1 addition & 0 deletions MyApp.ServiceInterface/Renderers/RegenerateMetaCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace MyApp.ServiceInterface.Renderers;

[Tag(Tags.Renderer)]
public class RegenerateMetaCommand(
ILogger<RegenerateMetaCommand> log,
IDbConnectionFactory dbFactory,
Expand Down
13 changes: 13 additions & 0 deletions MyApp.ServiceInterface/Tags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace MyApp.ServiceInterface;

public class Tags
{
public const string Database = nameof(Database);
public const string Questions = nameof(Questions);
public const string Answers = nameof(Answers);
public const string Notifications = nameof(Notifications);
public const string Jobs = nameof(Jobs);
public const string CreatorKit = nameof(CreatorKit);
public const string AI = nameof(AI);
public const string Renderer = nameof(Renderer);
}
41 changes: 41 additions & 0 deletions MyApp.Tests/Top1KQuestionTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ public async Task Recreate_answers_for_Top1K_questions_for_gemini_pro_15()
apiCreate.Response!.Results.PrintDump();;
}

[Test]
public async Task Recreate_answers_for_Top1K_questions_for_gemini_flash()
{
var client = await TestUtils.CreateAuthenticatedProdClientAsync();
var apiCreate = await client.ApiAsync(new CreateAnswersForModels
{
Models = ["gemini-flash"],
PostIds = Migration1005.Top1KIds,
});

apiCreate.Error.PrintDump();
apiCreate.ThrowIfError();
apiCreate.Response!.Errors.PrintDump();
apiCreate.Response!.Results.PrintDump();;
}

[Test]
public async Task Find_answers_that_have_not_been_individually_graded()
{
Expand Down Expand Up @@ -176,4 +192,29 @@ public async Task Create_Gemini_Pro_15_User()
api.Response.PrintDump();
api.ThrowIfError();
}

[Test]
public async Task Generate_top_10k_answers_for_gemini_flash()
{
var txt = await File.ReadAllTextAsync(TestUtils.GetHostDir().CombineWith("App_Data/top10k-6.txt"));
var ids = new List<int>();
foreach (var line in txt.ReadLines())
{
ids.Add(int.Parse(line.Trim()));
}

var client = await TestUtils.CreateAuthenticatedProdClientAsync();
// client.GetHttpClient().Timeout = TimeSpan.FromMinutes(5);
var apiCreate = await client.ApiAsync(new CreateAnswersForModels
{
// Models = ["gemini-flash","gemini-pro-1.5"],
Models = ["gemini-flash"],
PostIds = ids,
});

apiCreate.Error.PrintDump();
apiCreate.ThrowIfError();
apiCreate.Response!.Errors.PrintDump();
apiCreate.Response!.Results.PrintDump();;
}
}
2 changes: 2 additions & 0 deletions MyApp/Configure.Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected override void NavigateToCore(string uri, bool forceLoad)
}
}

[Tag(Tags.Renderer)]
public class RenderQuestionPostCommand(BlazorRenderer renderer, RendererCache cache) : IAsyncCommand<QuestionAndAnswers>
{
public async Task ExecuteAsync(QuestionAndAnswers request)
Expand All @@ -61,6 +62,7 @@ public async Task ExecuteAsync(QuestionAndAnswers request)
}
}

[Tag(Tags.Renderer)]
public class RenderHomeTabCommand(BlazorRenderer renderer, RendererCache cache) : IAsyncCommand<RenderHome>
{
public async Task ExecuteAsync(RenderHome request)
Expand Down

0 comments on commit 6c5f7c8

Please sign in to comment.