diff --git a/.gitignore b/.gitignore index 32ab2a2..7e52515 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ **/target/ /build /umogenkey.secret +**.db +**.db-* diff --git a/out.pdf b/out.pdf new file mode 100644 index 0000000..cfb3252 Binary files /dev/null and b/out.pdf differ diff --git a/src/Nyanlabs.Umogen.Core/Models/ApiChoice.cs b/src/Nyanlabs.Umogen.Core/Models/Api/ApiChoice.cs similarity index 100% rename from src/Nyanlabs.Umogen.Core/Models/ApiChoice.cs rename to src/Nyanlabs.Umogen.Core/Models/Api/ApiChoice.cs diff --git a/src/Nyanlabs.Umogen.Core/Models/ApiRequest.cs b/src/Nyanlabs.Umogen.Core/Models/Api/ApiRequest.cs similarity index 100% rename from src/Nyanlabs.Umogen.Core/Models/ApiRequest.cs rename to src/Nyanlabs.Umogen.Core/Models/Api/ApiRequest.cs diff --git a/src/Nyanlabs.Umogen.Core/Models/ApiResponse.cs b/src/Nyanlabs.Umogen.Core/Models/Api/ApiResponse.cs similarity index 100% rename from src/Nyanlabs.Umogen.Core/Models/ApiResponse.cs rename to src/Nyanlabs.Umogen.Core/Models/Api/ApiResponse.cs diff --git a/src/Nyanlabs.Umogen.Core/Models/ApiResponseFormat.cs b/src/Nyanlabs.Umogen.Core/Models/Api/ApiResponseFormat.cs similarity index 100% rename from src/Nyanlabs.Umogen.Core/Models/ApiResponseFormat.cs rename to src/Nyanlabs.Umogen.Core/Models/Api/ApiResponseFormat.cs diff --git a/src/Nyanlabs.Umogen.Core/Models/GptMessage.cs b/src/Nyanlabs.Umogen.Core/Models/Api/GptMessage.cs similarity index 100% rename from src/Nyanlabs.Umogen.Core/Models/GptMessage.cs rename to src/Nyanlabs.Umogen.Core/Models/Api/GptMessage.cs diff --git a/src/Nyanlabs.Umogen.Core/Models/LegalEntity.cs b/src/Nyanlabs.Umogen.Core/Models/LegalEntity.cs index 10180f2..8cfeb0f 100644 --- a/src/Nyanlabs.Umogen.Core/Models/LegalEntity.cs +++ b/src/Nyanlabs.Umogen.Core/Models/LegalEntity.cs @@ -1,11 +1,18 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + namespace Nyanlabs.Umogen.Core.Models; -public class LegalEntity(string Name, string? Nip = null, string? Headquarters = null, Person? Representative = null) : IEntity, INLSerializable +public class LegalEntity : IEntity, INLSerializable { - public string Name { get; set; } = Name; - public string? Nip { get; set; } = Nip; - public string? Headquarters { get; set; } = Headquarters; - public Person? Representative { get; set; } = Representative; + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Key] + public long Id { get; set; } + public string Name { get; set; } = default!; + public string? Nip { get; set; } = default!; + public string? Headquarters { get; set; } + public Person? Representative { get; set; } + public long? PersonId { get; set; } public string GetName() { @@ -24,6 +31,6 @@ public class LegalEntity(string Name, string? Nip = null, string? Headquarters = public string SerializeToDocument() { - return $"{Name}, reprezentowaną przez {Representative.GetName()}"; + return $"{Name}{(Representative != null ? $", reprezentowaną przez {Representative.GetName()}" : "")}"; } } diff --git a/src/Nyanlabs.Umogen.Core/Models/Person.cs b/src/Nyanlabs.Umogen.Core/Models/Person.cs index b833009..2546060 100644 --- a/src/Nyanlabs.Umogen.Core/Models/Person.cs +++ b/src/Nyanlabs.Umogen.Core/Models/Person.cs @@ -1,13 +1,23 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text.Json.Serialization; + namespace Nyanlabs.Umogen.Core.Models; -public record Person(string Name, string Surname, string? Id = null, string? Pesel = null, DateTime? DoB = null) : IEntity, INLSerializable +public record Person(string Name, string Surname, string IdC, string Pesel, DateTime? DoB = null) : IEntity, INLSerializable { + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Key] + public long Id { get; set; } public string Name { get; set; } = Name; public string Surname { get; set; } = Surname; - public string? IDCode { get; set; } = Id; - public string? Pesel { get; set; } = Pesel; + public string IDCode { get; set; } = IdC; + public string Pesel { get; set; } = Pesel; public DateTime? DoB { get; set; } = DoB; + [JsonIgnore] + public virtual ICollection Companies { get; set; } + public string GetName() { return $"{Name} {Surname}"; diff --git a/src/Nyanlabs.Umogen.Core/Models/UmoAnalModel.cs b/src/Nyanlabs.Umogen.Core/Models/UmoAnalModel.cs index 49ce09c..5240185 100644 --- a/src/Nyanlabs.Umogen.Core/Models/UmoAnalModel.cs +++ b/src/Nyanlabs.Umogen.Core/Models/UmoAnalModel.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; using System.Text.Json.Serialization; -using System.Threading.Tasks; namespace Nyanlabs.Umogen.Core.Models; diff --git a/src/Nyanlabs.Umogen.Core/Models/ValidTime.cs b/src/Nyanlabs.Umogen.Core/Models/ValidTime.cs index 044b961..81f6595 100644 --- a/src/Nyanlabs.Umogen.Core/Models/ValidTime.cs +++ b/src/Nyanlabs.Umogen.Core/Models/ValidTime.cs @@ -27,6 +27,6 @@ public readonly struct ValidTime : INLSerializable, IDocSerializable public string SerializeToDocument() { - return this.Start != DateTime.MaxValue ? $"na czas od {Start:dd MMM yyyy} do {End:dd MMM yyyy}" : "na czas nieokreślony"; + return this.Start != DateTime.MaxValue ? $"na czas od {Start:dd.MM.yyyy} do {End:dd.MM.yyyy}" : "na czas nieokreślony"; } } diff --git a/src/Nyanlabs.Umogen.Core/SseConsumer.cs b/src/Nyanlabs.Umogen.Core/SseConsumer.cs index a07ba05..079d0e4 100644 --- a/src/Nyanlabs.Umogen.Core/SseConsumer.cs +++ b/src/Nyanlabs.Umogen.Core/SseConsumer.cs @@ -27,6 +27,7 @@ public class SseConsumer : IDisposable, IAsyncDisposable yield return JsonSerializer.Deserialize(line, Umogen.JSON_OPTS) ?? throw new DataException("Invalid data..."); } + reader.Close(); } public void Dispose() diff --git a/src/Nyanlabs.Umogen.Server/DataContext.cs b/src/Nyanlabs.Umogen.Server/DataContext.cs new file mode 100644 index 0000000..c0f6c6c --- /dev/null +++ b/src/Nyanlabs.Umogen.Server/DataContext.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; + +using Nyanlabs.Umogen.Core.Models; + +namespace Nyanlabs.Umogen.Server; + +public class DataContext : DbContext +{ + public DbSet Persons => Set(); + public DbSet Companies => Set(); + + protected override void OnConfiguring(DbContextOptionsBuilder o) + { + o.UseSqlite("Data Source=data.db;"); + } + + protected override void OnModelCreating(ModelBuilder m) + { + m.Entity().HasOne(e => e.Representative).WithMany(e => e.Companies); + } +} diff --git a/src/Nyanlabs.Umogen.Server/Nyanlabs.Umogen.Server.csproj b/src/Nyanlabs.Umogen.Server/Nyanlabs.Umogen.Server.csproj index 1770d66..fc5d989 100644 --- a/src/Nyanlabs.Umogen.Server/Nyanlabs.Umogen.Server.csproj +++ b/src/Nyanlabs.Umogen.Server/Nyanlabs.Umogen.Server.csproj @@ -6,6 +6,8 @@ + + diff --git a/src/Nyanlabs.Umogen.Server/Pages/Contracts.razor b/src/Nyanlabs.Umogen.Server/Pages/Contracts.razor index 0a94e73..52d9c9d 100644 --- a/src/Nyanlabs.Umogen.Server/Pages/Contracts.razor +++ b/src/Nyanlabs.Umogen.Server/Pages/Contracts.razor @@ -2,19 +2,43 @@ @using Umogen.Core; @using Umogen.Core.Models; @inject IJSRuntime js +@inject DataContext db +@using Microsoft.EntityFrameworkCore; Umowy

Umowy

-
- -
-
- -
-
- +
+
+
+
+ + + @(employer == null ? "" : $"{employer.GetName()}") +
+
+ + + @(employee == null ? "" : $"{employee.Name} {employee.Surname}") +
+
+
+
+ + +
+
+ + +
+
+
+ + +
+ +
@@ -22,19 +46,69 @@
OUT: @output
- - @code { - private string _prompt, _person, _value; + private string _employerId = "", _employeeId = ""; + private Person? employee; + private IEntity? employer; + private string _query = ""; + private ValidTime _validity; + private decimal _payment; private string output = ""; + private bool disB = false; + + private async Task ChgEmployer(ChangeEventArgs e) + { + _employerId = (string)e.Value!; + employer = await db.Persons.AsNoTracking().SingleOrDefaultAsync(s => s.Pesel == _employerId) as IEntity ?? await + db.Companies.AsNoTracking().SingleOrDefaultAsync(s => s.Nip == _employerId); + } + + private async Task ChgEmployee(ChangeEventArgs e) + { + _employeeId = (string)e.Value!; + employee = await db.Persons.AsNoTracking().SingleOrDefaultAsync(s => s.Pesel == _employeeId); + } + + private string _validityText = ""; + + private async Task ChgValidity(ChangeEventArgs e) + { + string val = (string)e.Value!; + _validityText = val; + StateHasChanged(); + + var now = DateTime.Now; + + if (!TimeSpan.TryParse(val, out TimeSpan span)) + { + _validityText = "nieokreślony"; + _validity = ValidTime.Invalid; + } + + if (span.TotalDays < 1) + { + _validityText = "nieokreślony"; + _validity = ValidTime.Invalid; + StateHasChanged(); + return; + } + + _validityText = $"{span.TotalDays} d"; + _validity = new ValidTime(now, span); + } private async Task Process() { + disB = true; + this.StateHasChanged(); + await Task.Yield(); + output = string.Empty; using UmoEngine eng = new("/home/nya/Dev/csharp/umogen/umogenkey.secret"); UmoProcess proc = new(eng); Thread.Yield(); - await foreach (var str in proc.Ask(_prompt)) + + await foreach (var str in proc.Ask(_query + $" wynagrodzenie {_payment} zł")) { output += str; Console.Write(str); @@ -42,13 +116,14 @@ } var anal = System.Text.Json.JsonSerializer.Deserialize(output, Umogen.JSON_OPTS); - UmoDocumentResult res = new(null, new Person("Kotek", "Miauczyński", "CBS4327563", "04281308999", new DateTime(2004, 08, - 13)), - new Person("Kotek", "Miauczyński", "CBS4327563", "04281308999", new DateTime(2004, 08, 13)), ValidTime.Invalid, 2137, + UmoDocumentResult res = new(null, employee, employer, _validity, _payment, anal); var bytes = await res.ProcessPdf(Path.Combine("/home/nya/Dev/csharp/umogen/", $"templates/{anal.Doctype.TemplateDoc()}")); await js.InvokeVoidAsync("blobby", bytes); + + disB = false; + this.StateHasChanged(); } } diff --git a/src/Nyanlabs.Umogen.Server/Pages/Entities.razor b/src/Nyanlabs.Umogen.Server/Pages/Entities.razor new file mode 100644 index 0000000..4cb587f --- /dev/null +++ b/src/Nyanlabs.Umogen.Server/Pages/Entities.razor @@ -0,0 +1,97 @@ +@page "/entities" +@inject DataContext db +@using Microsoft.EntityFrameworkCore + +Podmioty + +

Podmioty

+ + + +@if (_mode == 1) +{ +
+ +
+} + +
+ + + + + + + + + + + @foreach (var person in db.Persons.AsNoTracking().ToList()) + { + + + + + + + } + +
IdImięPESELSeria dowodu
@person.Id@person.Name @person.Surname@person.Pesel@person.IdC
+
+ + + +@if (_mode == 2) +{ +
+ +
+} + +
+ + + + + + + + + + + + @foreach (var company in db.Companies.AsNoTracking().Include(c => c.Representative).ToList()) + { + + + + + + + + } + +
IdNazwaNIPSiedzibaReprezentant
@company.Id@company.Name@company.Nip@company.Headquarters@(company.Representative!.Name) @(company.Representative.Surname) [ID @company.Representative.Id] +
+
+ +@code { + int _mode = 0; + private void HideAll() + { + _mode = 0; + } + private void ShowCompanyDialog() + { + _mode = (_mode != 2 ? 2 : 0); + } + + private void ShowPersonDialog() + { + _mode = (_mode != 1 ? 1 : 0); + } +} diff --git a/src/Nyanlabs.Umogen.Server/Pages/Index.razor b/src/Nyanlabs.Umogen.Server/Pages/Index.razor index d90107f..a6d3026 100644 --- a/src/Nyanlabs.Umogen.Server/Pages/Index.razor +++ b/src/Nyanlabs.Umogen.Server/Pages/Index.razor @@ -2,4 +2,14 @@ Index -

Hello, meowmeow~

+
+

umogen

+

Silly Integrated Unified System for Accounting and Contract Handling

+

umogen is an experiment that aims to leverage large language models in order to decrease the effort of + handwriting various Polish legal contracts. This iteration will focus on employment and service contracts, + namely: contract of employment + and civic-law contracts which are the primary contracts used to employ workers. Moreover, civic-law contracts + can be utilized to exchange services.

+

Check podmioty for entity data manipulation and umowy to get + started with contract generation.

+
diff --git a/src/Nyanlabs.Umogen.Server/Pages/People.razor b/src/Nyanlabs.Umogen.Server/Pages/People.razor deleted file mode 100644 index acfb104..0000000 --- a/src/Nyanlabs.Umogen.Server/Pages/People.razor +++ /dev/null @@ -1,20 +0,0 @@ -@page "/people" - -Osoby - -

Osoby

- - -@if (addVis) -{ - -} - -@code { - private bool addVis = false; - - private void Toggle() - { - addVis = !addVis; - } -} diff --git a/src/Nyanlabs.Umogen.Server/Pages/_Host.cshtml b/src/Nyanlabs.Umogen.Server/Pages/_Host.cshtml index fa06e99..a64dbd5 100644 --- a/src/Nyanlabs.Umogen.Server/Pages/_Host.cshtml +++ b/src/Nyanlabs.Umogen.Server/Pages/_Host.cshtml @@ -10,8 +10,7 @@ - + diff --git a/src/Nyanlabs.Umogen.Server/Program.cs b/src/Nyanlabs.Umogen.Server/Program.cs index 11fa1b3..8aac821 100644 --- a/src/Nyanlabs.Umogen.Server/Program.cs +++ b/src/Nyanlabs.Umogen.Server/Program.cs @@ -1,14 +1,24 @@ using Femsci.AspapajNet; +using Nyanlabs.Umogen.Server; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); builder.Services.AddPapiez(); +builder.Services.AddDbContextFactory(); var app = builder.Build(); +using (var db = new DataContext()) +{ + await db.Database.EnsureCreatedAsync(); +} + + + if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); diff --git a/src/Nyanlabs.Umogen.Server/Shared/CompanyAddForm.razor b/src/Nyanlabs.Umogen.Server/Shared/CompanyAddForm.razor new file mode 100644 index 0000000..4cf49e8 --- /dev/null +++ b/src/Nyanlabs.Umogen.Server/Shared/CompanyAddForm.razor @@ -0,0 +1,56 @@ +@inject DataContext db + +

Dodaj firmę

+
+
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ + +
+ +
+
+ +@code { + [Parameter] + public required Action OnSubmit { get; set; } + + private long _reprId; + private string _name = string.Empty, + _loc = string.Empty, + _nip = string.Empty; + + private async Task Submit() + { + Core.Models.LegalEntity p = new() + { + Name = _name, + Nip = _nip, + Headquarters = _loc, + PersonId = _reprId, + }; + await db.AddAsync(p); + await db.SaveChangesAsync(); + + _name = string.Empty; + _loc = string.Empty; + _nip = string.Empty; + _reprId = 0; + + OnSubmit.Invoke(); + } +} diff --git a/src/Nyanlabs.Umogen.Server/Shared/Navi.razor b/src/Nyanlabs.Umogen.Server/Shared/Navi.razor index 5003a2e..ad5228d 100644 --- a/src/Nyanlabs.Umogen.Server/Shared/Navi.razor +++ b/src/Nyanlabs.Umogen.Server/Shared/Navi.razor @@ -11,7 +11,7 @@ Home