Skip to content

Commit 27d7c3f

Browse files
committed
Add support for rendering human answers
1 parent bae32b6 commit 27d7c3f

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

MyApp.ServiceInterface/Data/AppConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class AppConfig
1717

1818
public ApplicationUser GetApplicationUser(string model)
1919
{
20-
var user = ModelUsers.FirstOrDefault(x => x.Model == model);
20+
var user = ModelUsers.FirstOrDefault(x => x.Model == model || x.UserName == model);
2121
return user ?? DefaultUser;
2222
}
2323
}

MyApp.ServiceInterface/Data/R2Extensions.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace MyApp.Data;
66

77
public static class R2Extensions
88
{
9+
public const int MostVotedScore = 10;
10+
public const int AcceptedScore = 9;
911
public static Dictionary<string,int> ModelScores = new()
1012
{
1113
["starcoder2:3b"] = 1, //3B
@@ -56,12 +58,31 @@ public static async Task<IdFiles> GetQuestionFilesAsync(this R2VirtualFiles r2,
5658
{
5759
to.Answers.Add(entry.Value.FromJson<Answer>());
5860
}
61+
else if (entry.Key.StartsWith(idFiles.FileId + ".h."))
62+
{
63+
var post = entry.Value.FromJson<Post>();
64+
var answer = new Answer
65+
{
66+
Id = $"{post.Id}",
67+
Model = "human",
68+
UpVotes = entry.Key.Contains("h.most-voted") ? MostVotedScore : AcceptedScore,
69+
Choices = [
70+
new()
71+
{
72+
Index = 1,
73+
Message = new() { Role = "human", Content = post.Body ?? "" }
74+
}
75+
]
76+
};
77+
if (to.Answers.All(x => x.Id != answer.Id))
78+
to.Answers.Add(answer);
79+
}
5980
}
6081

6182
if (to.Post == null)
6283
return null;
6384

64-
to.Answers.Each(x => x.UpVotes = ModelScores.GetValueOrDefault(x.Model, 1));
85+
to.Answers.Each(x => x.UpVotes = x.UpVotes == 0 ? ModelScores.GetValueOrDefault(x.Model, 1) : x.UpVotes);
6586
to.Answers.Sort((a, b) => b.Votes - a.Votes);
6687
return to;
6788
}

MyApp/Configure.AppHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override void Configure()
3434
FileSystemVirtualFiles.AssertDirectory(HostingEnvironment.ContentRootPath.CombineWith(AppConfig.Instance.CacheDir));
3535

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

4040
private string? ResolveGitBlobBaseUrl(IVirtualDirectory contentDir)

0 commit comments

Comments
 (0)