diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 4bf6b8a..0000000 --- a/Dockerfile +++ /dev/null @@ -1,28 +0,0 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build - -WORKDIR /src - -COPY *.sln . -COPY src/Nyanlabs.Umogen.Core/*.csproj src/Nyanlabs.Umogen.Core/ -COPY src/Nyanlabs.Umogen.Server/*.csproj src/Nyanlabs.Umogen.Server/ - -COPY test/Nyanlabs.Umogen.WebTests/*.csproj test/Nyanlabs.Umogen.WebTests/ -COPY test/Nyanlabs.Umogen.CoreTests/*.csproj test/Nyanlabs.Umogen.CoreTests/ - -RUN dotnet restore - -COPY . . - -RUN dotnet publish -c Release -o /build - -FROM mcr.microsoft.com/dotnet/aspnet:8.0 - -RUN apt update -y -RUN apt install -y libreoffice-writer-nogui - -COPY --from=build /build /app - -WORKDIR /app - -EXPOSE 8080 -ENTRYPOINT [ "dotnet", "Nyanlabs.Umogen.Server.dll" ] 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/Api/ApiRequest.cs b/src/Nyanlabs.Umogen.Core/Models/Api/ApiRequest.cs index d06f947..4646f18 100644 --- a/src/Nyanlabs.Umogen.Core/Models/Api/ApiRequest.cs +++ b/src/Nyanlabs.Umogen.Core/Models/Api/ApiRequest.cs @@ -2,7 +2,7 @@ namespace Nyanlabs.Umogen.Core.Models; public record ApiRequest { - public string Model { get; set; } = "gpt-4"; + public string Model { get; set; } = "gpt-3.5-turbo"; public float Temperature { get; set; } = 0.7f; public ICollection<GptMessage> Messages { get; set; } = new List<GptMessage>(); public bool Stream { get; set; } diff --git a/src/Nyanlabs.Umogen.Core/Models/Person.cs b/src/Nyanlabs.Umogen.Core/Models/Person.cs index c1aaefe..2546060 100644 --- a/src/Nyanlabs.Umogen.Core/Models/Person.cs +++ b/src/Nyanlabs.Umogen.Core/Models/Person.cs @@ -16,7 +16,7 @@ public record Person(string Name, string Surname, string IdC, string Pesel, Date public DateTime? DoB { get; set; } = DoB; [JsonIgnore] - public virtual ICollection<LegalEntity> Companies { get; set; } = default!; + public virtual ICollection<LegalEntity> Companies { get; set; } public string GetName() { diff --git a/src/Nyanlabs.Umogen.Core/Models/UmoAnalModel.cs b/src/Nyanlabs.Umogen.Core/Models/UmoAnalModel.cs index 1b7004a..5240185 100644 --- a/src/Nyanlabs.Umogen.Core/Models/UmoAnalModel.cs +++ b/src/Nyanlabs.Umogen.Core/Models/UmoAnalModel.cs @@ -5,13 +5,13 @@ namespace Nyanlabs.Umogen.Core.Models; public class UmoAnalModel { [JsonPropertyName("c_type")] - public string ContractType { get; set; } = default!; + public string ContractType { get; set; } [JsonPropertyName("j_pos")] - public string JobPosition { get; set; } = default!; + public string JobPosition { get; set; } [JsonPropertyName("k_lit")] - public string ValueLiteral { get; set; } = default!; + public string ValueLiteral { get; set; } [JsonPropertyName("conds")] - public ICollection<string> Conditions { get; set; } = default!; + public ICollection<string> Conditions { get; set; } - public UmoDoctype Doctype => UmoDoctypeBindings.GetFromName(ContractType)!.Value; + public UmoDoctype Doctype => UmoDoctypeBindings.GetFromName(ContractType).Value; } diff --git a/src/Nyanlabs.Umogen.Core/Models/UmoDocumentResult.cs b/src/Nyanlabs.Umogen.Core/Models/UmoDocumentResult.cs index c34bfe6..0def101 100644 --- a/src/Nyanlabs.Umogen.Core/Models/UmoDocumentResult.cs +++ b/src/Nyanlabs.Umogen.Core/Models/UmoDocumentResult.cs @@ -32,9 +32,9 @@ public class UmoDocumentResult(UmoDoctype? type, Person employee, IEntity employ .Replace(ENACT_DATE, DateTime.Now.ToString("dd.MM.yyyy")) .Replace(ISSUE_DATE, DateTime.Now.ToString("dd.MM.yyyy")) .Replace(PAYMENT_LIT, Anal.ValueLiteral) - .Replace(PAYMENT, Payment!.Value.ToString()) + .Replace(PAYMENT, Payment.Value.ToString()) .Replace(WORK_TYPE, Anal.JobPosition) - .Replace(DYNAMIC_DATA, string.Join(", ", Anal.Conditions.Select(x => x.Trim('-').Trim(' ')))); + .Replace(DYNAMIC_DATA, string.Join('\n', Anal.Conditions.Select(a => $"- {a}"))); string tmp = Path.GetTempFileName(); await File.WriteAllTextAsync(tmp, xml); diff --git a/src/Nyanlabs.Umogen.Core/UmoEngine.cs b/src/Nyanlabs.Umogen.Core/UmoEngine.cs index 0bc2f24..67d21e5 100644 --- a/src/Nyanlabs.Umogen.Core/UmoEngine.cs +++ b/src/Nyanlabs.Umogen.Core/UmoEngine.cs @@ -8,7 +8,7 @@ public class UmoEngine : IDisposable { if (isFilePath) { - apiKey ??= Environment.GetEnvironmentVariable("UMO_KEY_FILE") ?? Umogen.DEFAULT_API_KEY_FILE; + apiKey ??= Umogen.DEFAULT_API_KEY_FILE; if (!File.Exists(apiKey)) { throw new ArgumentException($"No such file: {apiKey}"); diff --git a/src/Nyanlabs.Umogen.Core/Umogen.cs b/src/Nyanlabs.Umogen.Core/Umogen.cs index ae99545..f8471c6 100644 --- a/src/Nyanlabs.Umogen.Core/Umogen.cs +++ b/src/Nyanlabs.Umogen.Core/Umogen.cs @@ -5,7 +5,7 @@ namespace Nyanlabs.Umogen.Core; public class Umogen { public const string DEFAULT_API_KEY_FILE = "umogenkey.secret"; - public const string PROMPT = "You analyze employment prompt requests and return document type (one of these 'Umowa o Pracę', 'Umowa Zlecenie', 'Umowa o Dzieło') and elaborate description of job details as a list separated by hyphens and newlines. Also give a very generalized job position. You write them in format: '{ \"c_type\": \"<contract type>\", \"j_pos\": \"<rodzaj zawodu>\", \"k_lit\": \"<kwota słownie>\", \"conds\": [ <warunki zatrudnienia> ]'. Nie opisuj wynagrodzenia w '<warunki zatrudnienia>'. Add any clauses (anti-competitive, NDA, etc) to the bottom if requested."; + public const string PROMPT = "You analyze employment prompt requests and return document type (one of these 'Umowa o Pracę', 'Umowa Zlecenie', 'Umowa o Dzieło') and elaborate description of job details as a list separated by hyphens and newlines. Also give a very generalized job position. You write them in format: '{ \"c_type\": \"<contract type>\", \"j_pos\": \"<rodzaj zawodu>\", \"k_lit\": \"<kwota słownie>\", \"conds\": [ <warunki zatrudnienia> ]'"; public static readonly JsonSerializerOptions JSON_OPTS = new(JsonSerializerDefaults.Web) { PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower diff --git a/src/Nyanlabs.Umogen.Server/DataContext.cs b/src/Nyanlabs.Umogen.Server/DataContext.cs index 8c54a0b..c0f6c6c 100644 --- a/src/Nyanlabs.Umogen.Server/DataContext.cs +++ b/src/Nyanlabs.Umogen.Server/DataContext.cs @@ -11,8 +11,7 @@ public class DataContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder o) { - - o.UseSqlite($"Data Source={Environment.GetEnvironmentVariable("UMO_DATA") ?? "data.db"};"); + o.UseSqlite("Data Source=data.db;"); } protected override void OnModelCreating(ModelBuilder m) diff --git a/src/Nyanlabs.Umogen.Server/Pages/Contracts.razor b/src/Nyanlabs.Umogen.Server/Pages/Contracts.razor index f05c469..34c7a76 100644 --- a/src/Nyanlabs.Umogen.Server/Pages/Contracts.razor +++ b/src/Nyanlabs.Umogen.Server/Pages/Contracts.razor @@ -14,12 +14,12 @@ <div class="row justify-content-center align-items-center g-2"> <div class="col mb-3"> <label for="employer" class="form-label">Pracodawca (PESEL lub NIP)</label> - <Autocomplete Value="@_employerId" AcceptedValues="GetEmployers()" Change="ChgEmployer" /> + <input type="text" class="form-control" id="employer" @onchange="ChgEmployer" value="@_employerId"> <span class="validation-message">@(employer == null ? "" : $"{employer.GetName()}")</span> </div> <div class="col mb-3"> <label for="employee" class="form-label">Pracownik (PESEL)</label> - <Autocomplete Value="@_employeeId" AcceptedValues="GetEmployees()" Change="ChgEmployee" /> + <input type="text" class="form-control" id="employee" @onchange="ChgEmployee" value="@_employeeId"> <span class="validation-message">@(employee == null ? "" : $"{employee.Name} {employee.Surname}")</span> </div> </div> @@ -59,8 +59,7 @@ { _employerId = (string)e.Value!; employer = await db.Persons.AsNoTracking().SingleOrDefaultAsync(s => s.Pesel == _employerId) as IEntity ?? await - db.Companies.AsNoTracking().Include(i => i.Representative).SingleOrDefaultAsync(s => s.Nip == _employerId); - StateHasChanged(); + db.Companies.AsNoTracking().SingleOrDefaultAsync(s => s.Nip == _employerId); } private async Task ChgEmployee(ChangeEventArgs e) @@ -71,7 +70,7 @@ private string _validityText = ""; - private void ChgValidity(ChangeEventArgs e) + private async Task ChgValidity(ChangeEventArgs e) { string val = (string)e.Value!; _validityText = val; @@ -97,19 +96,6 @@ _validity = new ValidTime(now, span); } - private IEnumerable<(string, string)> GetEmployers() - { - var pers = db.Persons.AsNoTracking().AsEnumerable().Select(p => ($"{p.Name} {p.Surname}", p.Pesel)); - var comp = db.Companies.AsNoTracking().AsEnumerable().Select(c => (c.Name, c.Nip!)); - - return pers.Union(comp); - } - - private IEnumerable<(string, string)> GetEmployees() - { - return db.Persons.AsNoTracking().AsEnumerable().Select(p => ($"{p.Name} {p.Surname}", p.Pesel)); - } - private async Task Process() { disB = true; @@ -117,7 +103,7 @@ await Task.Yield(); output = string.Empty; - using UmoEngine eng = new(); + using UmoEngine eng = new("/home/nya/Dev/csharp/umogen/umogenkey.secret"); UmoProcess proc = new(eng); Thread.Yield(); @@ -129,11 +115,11 @@ } var anal = System.Text.Json.JsonSerializer.Deserialize<UmoAnalModel>(output, Umogen.JSON_OPTS); - UmoDocumentResult res = new(null, employee!, employer!, _validity, _payment, - anal!); + UmoDocumentResult res = new(null, employee, employer, _validity, _payment, + anal); - var bytes = await res.ProcessPdf(Path.Combine(Environment.GetEnvironmentVariable("UMO_TEMPLATES")!, - anal!.Doctype.TemplateDoc())); + var bytes = await res.ProcessPdf(Path.Combine("/home/nya/Dev/csharp/umogen/", + $"templates/{anal.Doctype.TemplateDoc()}")); await js.InvokeVoidAsync("blobby", bytes); disB = false; diff --git a/src/Nyanlabs.Umogen.Server/Properties/launchSettings.json b/src/Nyanlabs.Umogen.Server/Properties/launchSettings.json index ca46943..19c4480 100644 --- a/src/Nyanlabs.Umogen.Server/Properties/launchSettings.json +++ b/src/Nyanlabs.Umogen.Server/Properties/launchSettings.json @@ -16,13 +16,22 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7029;http://localhost:5214", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } } } } diff --git a/src/Nyanlabs.Umogen.Server/Shared/Autocomplete.razor b/src/Nyanlabs.Umogen.Server/Shared/Autocomplete.razor deleted file mode 100644 index c9d5e07..0000000 --- a/src/Nyanlabs.Umogen.Server/Shared/Autocomplete.razor +++ /dev/null @@ -1,51 +0,0 @@ -<div class="relat" @onfocusin="(() => focus = true)"> - <input type="text" class="form-control" @oninput="Prechange" value="@Value"> - @if (focus) - { - <div class="autocomplete-items"> - @foreach (var tup in Filter()) - { - <div @onclick="async (e) => await Select(tup.Item2)"> - @tup.Item1 (@tup.Item2) - </div> - } - </div> - } -</div> -@code { - private bool focus = false; - [Parameter] - public IEnumerable<(string, string)> AcceptedValues { get; set; } = []; - - - [Parameter] - public string Value { get; set; } = ""; - - private async Task Prechange(ChangeEventArgs e) - { - Value = (string)e.Value!; - StateHasChanged(); - await Change.InvokeAsync(e); - } - - [Parameter] - public EventCallback<ChangeEventArgs> Change { get; set; } - - private async Task Select(string s) - { - focus = false; - Value = s; - - await Prechange(new() - { - Value = s - }); - StateHasChanged(); - } - - private IEnumerable<(string, string)> Filter() - { - return AcceptedValues.Where(v => v.Item1.StartsWith(Value, StringComparison.OrdinalIgnoreCase) || - v.Item2.StartsWith(Value, StringComparison.OrdinalIgnoreCase)); - } -} diff --git a/src/Nyanlabs.Umogen.Server/Shared/Autocomplete.razor.css b/src/Nyanlabs.Umogen.Server/Shared/Autocomplete.razor.css deleted file mode 100644 index 5ff9644..0000000 --- a/src/Nyanlabs.Umogen.Server/Shared/Autocomplete.razor.css +++ /dev/null @@ -1,32 +0,0 @@ -.relat { - position: relative; -} - -.autocomplete { - position: relative; - display: inline-block; -} - -.autocomplete-items { - position: absolute; - border: 1px solid #d4d4d4; - border-bottom: none; - border-top: none; - z-index: 99; - /*position the autocomplete items to be the same width as the container:*/ - top: 3rem; - left: 0; - right: 0; - width: fit-content; -} - -.autocomplete-items div { - padding: 10px; - cursor: pointer; - background-color: #fff; - border-bottom: 1px solid #d4d4d4; -} - -.autocomplete-items div:hover { - background-color: rgb(156, 237, 248); -} diff --git a/src/Nyanlabs.Umogen.Server/appsettings.json b/src/Nyanlabs.Umogen.Server/appsettings.json index 8f1b7f5..10f68b8 100644 --- a/src/Nyanlabs.Umogen.Server/appsettings.json +++ b/src/Nyanlabs.Umogen.Server/appsettings.json @@ -5,13 +5,5 @@ "Microsoft.AspNetCore": "Warning" } }, - - "Kestrel": { - "Endpoints": { - "Http": { - "Url": "http://+:8080" - } - } - }, "AllowedHosts": "*" } diff --git a/test/Nyanlabs.Umogen.WebTests/GenerationTests.cs b/test/Nyanlabs.Umogen.WebTests/GenerationTests.cs index f682096..eed01b6 100644 --- a/test/Nyanlabs.Umogen.WebTests/GenerationTests.cs +++ b/test/Nyanlabs.Umogen.WebTests/GenerationTests.cs @@ -8,4 +8,24 @@ public class GenerationTests private Person ModelEmployer => new("Kotek", "Miauczyński", "CBS4327563", "04281308999", new DateTime(2004, 08, 13)); private Person ModelEmployee => new("Miau", "Kotczyński", "CBS69696969", "76011694336", new DateTime(1976, 1, 16)); + + [Fact] + public async Task Meow4Me() + { + // Given + var rootDir = Environment.CurrentDirectory.Replace("test/Nyanlabs.Umogen.WebTests/bin/Debug/net8.0", ""); + + UmoEngine eng = new(Path.Combine(rootDir, Core.Umogen.DEFAULT_API_KEY_FILE)); + + // When + UmoDocument doc = new(UmoDoctype.CONTR_EMPLOYMENT, ModelEmployer, ModelEmployee); + + UmoProcess proc = new(eng); + // var enu = proc.Ask("I would like to employ Jan Kowalski ID NO CBS3727348 for part time job as a shopkeeper and pay 1400zł."); + + // await foreach (var str in enu) + // { + // Console.Write(str); + // } + } } diff --git a/test/Nyanlabs.Umogen.WebTests/PdfTest.cs b/test/Nyanlabs.Umogen.WebTests/PdfTest.cs index ab58059..0c1ebb5 100644 --- a/test/Nyanlabs.Umogen.WebTests/PdfTest.cs +++ b/test/Nyanlabs.Umogen.WebTests/PdfTest.cs @@ -31,7 +31,7 @@ public class PdfTest } var anal = JsonSerializer.Deserialize<UmoAnalModel>(sb.ToString(), Core.Umogen.JSON_OPTS); - UmoDocumentResult r = new(null, ModelEmployer, ModelEmployee, ValidTime.Invalid, 2137, anal!); + UmoDocumentResult r = new(null, ModelEmployer, ModelEmployee, ValidTime.Invalid, 2137, anal); // When byte[] b = await r.ProcessPdf(Path.Combine(root, $"templates/{r.DocType.TemplateDoc()}"));