Skip to content

Commit

Permalink
Add support for rendering human answers
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Mar 16, 2024
1 parent bae32b6 commit 27d7c3f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MyApp.ServiceInterface/Data/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AppConfig

public ApplicationUser GetApplicationUser(string model)
{
var user = ModelUsers.FirstOrDefault(x => x.Model == model);
var user = ModelUsers.FirstOrDefault(x => x.Model == model || x.UserName == model);
return user ?? DefaultUser;
}
}
23 changes: 22 additions & 1 deletion MyApp.ServiceInterface/Data/R2Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace MyApp.Data;

public static class R2Extensions
{
public const int MostVotedScore = 10;
public const int AcceptedScore = 9;
public static Dictionary<string,int> ModelScores = new()
{
["starcoder2:3b"] = 1, //3B
Expand Down Expand Up @@ -56,12 +58,31 @@ public static async Task<IdFiles> GetQuestionFilesAsync(this R2VirtualFiles r2,
{
to.Answers.Add(entry.Value.FromJson<Answer>());
}
else if (entry.Key.StartsWith(idFiles.FileId + ".h."))
{
var post = entry.Value.FromJson<Post>();
var answer = new Answer
{
Id = $"{post.Id}",
Model = "human",
UpVotes = entry.Key.Contains("h.most-voted") ? MostVotedScore : AcceptedScore,
Choices = [
new()
{
Index = 1,
Message = new() { Role = "human", Content = post.Body ?? "" }
}
]
};
if (to.Answers.All(x => x.Id != answer.Id))
to.Answers.Add(answer);
}
}

if (to.Post == null)
return null;

to.Answers.Each(x => x.UpVotes = ModelScores.GetValueOrDefault(x.Model, 1));
to.Answers.Each(x => x.UpVotes = x.UpVotes == 0 ? ModelScores.GetValueOrDefault(x.Model, 1) : x.UpVotes);
to.Answers.Sort((a, b) => b.Votes - a.Votes);
return to;
}
Expand Down
2 changes: 1 addition & 1 deletion MyApp/Configure.AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void Configure()
FileSystemVirtualFiles.AssertDirectory(HostingEnvironment.ContentRootPath.CombineWith(AppConfig.Instance.CacheDir));

using var db = GetDbConnection();
AppConfig.Instance.ModelUsers = db.Select(db.From<ApplicationUser>().Where(x => x.Model != null));
AppConfig.Instance.ModelUsers = db.Select(db.From<ApplicationUser>().Where(x => x.Model != null || x.UserName == "human"));
}

private string? ResolveGitBlobBaseUrl(IVirtualDirectory contentDir)
Expand Down

0 comments on commit 27d7c3f

Please sign in to comment.