generated from NetCoreTemplates/blazor-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
99 changed files
with
11,014 additions
and
7,502 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.AspNetCore.Components.Web; | ||
|
||
namespace MyApp.ServiceInterface; | ||
|
||
public class BlazorRenderer(HtmlRenderer htmlRenderer) | ||
{ | ||
public Task<string> RenderComponent<T>() where T : IComponent | ||
=> RenderComponent<T>(ParameterView.Empty); | ||
|
||
public Task<string> RenderComponent<T>(Dictionary<string, object?> dictionary) where T : IComponent | ||
=> RenderComponent<T>(ParameterView.FromDictionary(dictionary)); | ||
|
||
private Task<string> RenderComponent<T>(ParameterView parameters) where T : IComponent | ||
{ | ||
return htmlRenderer.Dispatcher.InvokeAsync(async () => | ||
{ | ||
var output = await htmlRenderer.RenderComponentAsync<T>(parameters); | ||
return output.ToHtmlString(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace MyApp.Data; | ||
|
||
public class AppConfig | ||
{ | ||
public static AppConfig Instance { get; } = new(); | ||
public string LocalBaseUrl { get; set; } | ||
public string PublicBaseUrl { get; set; } | ||
public string CacheDir { get; set; } | ||
public string? GitPagesBaseUrl { get; set; } | ||
public List<ApplicationUser> ModelUsers { get; set; } = []; | ||
public ApplicationUser DefaultUser { get; set; } = new() | ||
{ | ||
Model = "unknown", | ||
UserName = "unknown", | ||
ProfileUrl = "/img/profiles/user2.svg", | ||
}; | ||
|
||
public ApplicationUser GetApplicationUser(string model) | ||
{ | ||
var user = ModelUsers.FirstOrDefault(x => x.Model == model); | ||
return user ?? DefaultUser; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
using Microsoft.AspNetCore.Identity; | ||
using ServiceStack.DataAnnotations; | ||
|
||
namespace MyApp.Data; | ||
|
||
// Add profile data for application users by adding properties to the ApplicationUser class | ||
[Alias("AspNetUsers")] | ||
public class ApplicationUser : IdentityUser | ||
{ | ||
public string? FirstName { get; set; } | ||
public string? LastName { get; set; } | ||
public string? DisplayName { get; set; } | ||
public string? ProfileUrl { get; set; } | ||
public string? Model { get; set; } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections.Concurrent; | ||
using ServiceStack.IO; | ||
|
||
namespace MyApp.Data; | ||
|
||
public class IdFiles(int id, string dir1, string dir2, string fileId, List<IVirtualFile> files) | ||
{ | ||
public int Id { get; init; } = id; | ||
public string Dir1 { get; init; } = dir1; | ||
public string Dir2 { get; init; } = dir2; | ||
public string FileId { get; init; } = fileId; | ||
public List<IVirtualFile> Files { get; init; } = files; | ||
public ConcurrentDictionary<string, string> FileContents { get; } = []; | ||
|
||
public async Task LoadContentsAsync() | ||
{ | ||
if (FileContents.Count > 0) return; | ||
var tasks = new List<Task>(); | ||
tasks.AddRange(Files.Select(async file => { | ||
FileContents[file.Name] = await file.ReadAllTextAsync(); | ||
})); | ||
await Task.WhenAll(tasks); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using MyApp.ServiceModel; | ||
using ServiceStack; | ||
using ServiceStack.IO; | ||
|
||
namespace MyApp.Data; | ||
|
||
public static class R2Extensions | ||
{ | ||
public static Dictionary<string,int> ModelScores = new() | ||
{ | ||
["starcoder2:3b"] = 1, //3B | ||
["phi"] = 2, //2.7B | ||
["gemma:2b"] = 3, | ||
["gemma"] = 4, //7B | ||
["codellama"] = 5, //7B | ||
["mistral"] = 6, //7B | ||
["starcoder2:15b"] = 7, //15B | ||
["mixtral"] = 8, //47B | ||
}; | ||
|
||
public static (string dir1, string dir2, string fileId) ToFileParts(this int id) | ||
{ | ||
var idStr = $"{id}".PadLeft(9, '0'); | ||
var dir1 = idStr[..3]; | ||
var dir2 = idStr.Substring(3, 3); | ||
var fileId = idStr[6..]; | ||
return (dir1, dir2, fileId); | ||
} | ||
|
||
public static async Task<IdFiles> GetQuestionFilesAsync(this R2VirtualFiles r2, int id) | ||
{ | ||
var (dir1, dir2, fileId) = ToFileParts(id); | ||
|
||
var files = (await r2.EnumerateFilesAsync($"{dir1}/{dir2}").ToListAsync()) | ||
.Where(x => x.Name.Glob($"{fileId}.*")) | ||
.OrderByDescending(x => x.LastModified) | ||
.Cast<IVirtualFile>() | ||
.ToList(); | ||
|
||
return new IdFiles(id: id, dir1: dir1, dir2: dir2, fileId: fileId, files: files); | ||
} | ||
|
||
public static async Task<QuestionAndAnswers?> ToQuestionAndAnswers(this IdFiles idFiles) | ||
{ | ||
var fileName = idFiles.FileId + ".json"; | ||
await idFiles.LoadContentsAsync(); | ||
|
||
var to = new QuestionAndAnswers(); | ||
foreach (var entry in idFiles.FileContents) | ||
{ | ||
if (entry.Key == fileName) | ||
{ | ||
to.Post = entry.Value.FromJson<Post>(); | ||
} | ||
else if (entry.Key.StartsWith(idFiles.FileId + ".a.")) | ||
{ | ||
to.Answers.Add(entry.Value.FromJson<Answer>()); | ||
} | ||
} | ||
|
||
if (to.Post == null) | ||
return null; | ||
|
||
to.Answers.Each(x => x.UpVotes = ModelScores.GetValueOrDefault(x.Model, 1)); | ||
to.Answers.Sort((a, b) => b.Votes - a.Votes); | ||
return to; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.