Skip to content

Commit

Permalink
Small fixes and test endpoint for automated ranking.
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric committed Apr 2, 2024
1 parent 218bf3d commit 41ee277
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MyApp.ServiceInterface/Data/QuestionFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public async Task LoadContentsAsync()
await Task.WhenAll(tasks);
}

public string GetAnswerUserName(string answerFileName) => answerFileName[(FileId + ".a.").Length..].LeftPart('.');
public string GetAnswerUserName(string answerFileName) => answerFileName[(FileId + ".a.").Length..].LastLeftPart('.');

public string GetAnswerId(string answerFileName) => Id + "-" + GetAnswerUserName(answerFileName);

Expand Down
5 changes: 4 additions & 1 deletion MyApp.ServiceInterface/Data/QuestionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class QuestionsProvider(ILogger<QuestionsProvider> log, IVirtualFiles fs,
public const int MostVotedScore = 10;
public const int AcceptedScore = 9;
public static List<string> ModelUserNames { get; } = [
"phi", "gemma-2b", "qwen-4b", "codellama", "gemma", "deepseek-coder", "mistral", "mixtral"
"phi", "gemma-2b", "qwen-4b", "codellama", "gemma", "deepseek-coder-6.7b", "mistral", "mixtral","gpt-4-turbo",
"claude-3-haiku","claude-3-sonnet","claude-3-opus"
];
public static Dictionary<string,int> ModelScores = new()
{
Expand All @@ -21,6 +22,8 @@ public class QuestionsProvider(ILogger<QuestionsProvider> log, IVirtualFiles fs,
["codellama"] = 4, //7B
["gemma"] = 5, //7B
["deepseek-coder:6.7b"] = 5, //6.7B
["deepseek-coder:6"] = 5, //TODO Remove once data is clean, some 6.7b models are saved as 6 due to finding the first decimal
["deepseek-coder:33b"] = 6, //33B
["mistral"] = 7, //7B
["mixtral"] = 8, //47B
["accepted"] = 9,
Expand Down
83 changes: 83 additions & 0 deletions MyApp.ServiceInterface/QuestionServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MyApp.Data;
using ServiceStack;
using MyApp.ServiceModel;
using ServiceStack.IO;
using ServiceStack.OrmLite;
using ServiceStack.Text;

Expand All @@ -23,6 +24,23 @@ private List<string> ValidateQuestionTags(List<string>? tags)
throw new ArgumentException("Maximum of 5 tags allowed", nameof(tags));
return validTags;
}

public async Task<object> Get(GetAllAnswers request)
{
var question = await questions.GetQuestionAsync(request.Id);
var modelNames = question.Question?.Answers.Where(x => !string.IsNullOrEmpty(x.Model)).Select(x => x.Model).ToList();
var humanAnswers = question.Question?.Answers.Where(x => string.IsNullOrEmpty(x.Model)).Select(x => x.Id.SplitOnFirst("-")[1]).ToList();
modelNames?.AddRange(humanAnswers ?? []);
var answers = question
.GetAnswerFiles()
.ToList();

return new GetAllAnswersResponse
{
Answers = modelNames ?? new List<string>()
};
}


public async Task<object> Any(AskQuestion request)
{
Expand Down Expand Up @@ -219,6 +237,16 @@ public async Task<object> Any(GetQuestionFile request)

return new HttpResult(json, MimeTypes.Json);
}

public async Task<object> Get(GetAnswerFile request)
{
var answerFile = await questions.GetAnswerFileAsync(request.Id);
if (answerFile == null)
throw HttpError.NotFound("Answer does not exist");

var json = await answerFile.ReadAllTextAsync();
return new HttpResult(json, MimeTypes.Json);
}

public async Task<object> Any(GetAnswerBody request)
{
Expand All @@ -243,6 +271,30 @@ public async Task<object> Any(GetAnswerBody request)
}
}

/// <summary>
/// DEBUG
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<object> Any(CreateRankingPostJob request)
{
MessageProducer.Publish(new DbWrites
{
CreatePostJobs = new List<PostJob>
{
new PostJob
{
PostId = request.PostId,
Model = "rank",
Title = $"rank-{request.PostId}",
CreatedDate = DateTime.UtcNow,
CreatedBy = nameof(DbWrites),
}
}
});
return "{ \"success\": true }";
}

public async Task<object> Any(CreateWorkerAnswer request)
{
var json = request.Json;
Expand Down Expand Up @@ -374,3 +426,34 @@ private string GetUserName()
return userName;
}
}


/// <summary>
/// DEBUG
/// </summary>
[ValidateIsAuthenticated]
public class CreateRankingPostJob
{
public int PostId { get; set; }
}

[ValidateIsAuthenticated]
public class GetAnswerFile
{
/// <summary>
/// Format is {PostId}-{UserName}
/// </summary>
public string Id { get; set; }
}

public class GetAllAnswersResponse
{
public string Question { get; set; }
public List<string> Answers { get; set; }
}

[ValidateIsAuthenticated]
public class GetAllAnswers : IReturn<GetAllAnswersResponse>, IGet
{
public int Id { get; set; }
}
9 changes: 8 additions & 1 deletion MyApp.ServiceModel/Posts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,14 @@ public class RankAnswers : IPost, IReturn<IdResponse>
[ValidateGreaterThan(0)]
public int PostId { get; set; }

public Dictionary<string,int> Votes { get; set; }
/// <summary>
/// Model used to rank the answers
/// </summary>
public string Model { get; set; }

public Dictionary<string,int> ModelVotes { get; set; }

public int? PostJobId { get; set; }
}

[ValidateIsAuthenticated]
Expand Down

0 comments on commit 41ee277

Please sign in to comment.