current state of !stuff!
This commit is contained in:
parent
962f4c15a1
commit
60c896acd1
18 changed files with 156 additions and 29 deletions
6
src/Nyanlabs.Umogen.Core/Models/DocSerializable.cs
Normal file
6
src/Nyanlabs.Umogen.Core/Models/DocSerializable.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace Nyanlabs.Umogen.Core.Models;
|
||||
|
||||
public interface IDocSerializable
|
||||
{
|
||||
public string SerializeToDocument();
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
namespace Nyanlabs.Umogen.Core.Models;
|
||||
|
||||
public interface IEntity : INLSerializable
|
||||
public interface IEntity : INLSerializable, IDocSerializable
|
||||
{
|
||||
public string GetName();
|
||||
public string? IdCode();
|
||||
|
|
|
@ -17,8 +17,13 @@ public class LegalEntity(string Name, string? Nip = null, string? Headquarters =
|
|||
return Nip;
|
||||
}
|
||||
|
||||
public string NLSerialize()
|
||||
public string NLQuerySerialize()
|
||||
{
|
||||
return $"{Name}; with NIP {Nip ?? "unknown"}{(Headquarters != null ? $"; located in {Headquarters}" : "")}{(Representative != null ? $"; represented by {Representative.GetName()}" : "")}";
|
||||
}
|
||||
|
||||
public string SerializeToDocument()
|
||||
{
|
||||
return $"{Name}, reprezentowaną przez {Representative.GetName()}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@ namespace Nyanlabs.Umogen.Core.Models;
|
|||
|
||||
public interface INLSerializable
|
||||
{
|
||||
public string NLSerialize();
|
||||
public string NLQuerySerialize();
|
||||
}
|
||||
|
|
|
@ -18,8 +18,13 @@ public record Person(string Name, string Surname, string? Id = null, string? Pes
|
|||
return IDCode!;
|
||||
}
|
||||
|
||||
public string NLSerialize()
|
||||
public string NLQuerySerialize()
|
||||
{
|
||||
return $"{Name} {Surname}; {(Pesel != null ? $"PESEL {Pesel}" : "unknown PESEL")}; {(IDCode != null ? $"ID series {IDCode}" : "unknown ID series")}; {(DoB != null ? $"born {DoB.Value:dd MMM yyyy}" : "unknown date of birth")}";
|
||||
}
|
||||
|
||||
public string SerializeToDocument()
|
||||
{
|
||||
return $"{Name} {Surname}{(Pesel != null ? $" PESEL {Pesel}" : "")}{(IDCode != null ? $" legitymującą się dowodem {IDCode}" : "")}{(DoB != null ? $" ur. {DoB.Value:dd MMM yyyy}" : "")}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using System.Data;
|
||||
|
||||
namespace Nyanlabs.Umogen.Core.Models;
|
||||
|
||||
public enum UmoDoctype
|
||||
|
@ -16,6 +18,17 @@ public static class UmoDoctypeBindings
|
|||
{ UmoDoctype.CONTR_ASS, ("Contract for Assignment", "Umowa o Dzieło") }
|
||||
};
|
||||
|
||||
public static string TemplateDoc(this UmoDoctype t)
|
||||
{
|
||||
return t switch
|
||||
{
|
||||
UmoDoctype.CONTR_EMPLOYMENT => "uop.fodt",
|
||||
UmoDoctype.CONTR_SERVICE => "uz.fodt",
|
||||
UmoDoctype.CONTR_ASS => "ud.fodt",
|
||||
_ => throw new DataException("invalid"),
|
||||
};
|
||||
}
|
||||
|
||||
public static (string, string) Name(this UmoDoctype t)
|
||||
{
|
||||
return s_umoass[t];
|
||||
|
@ -43,8 +56,8 @@ public class UmoDocument : INLSerializable
|
|||
public Person Employee { get; set; }
|
||||
//Null is 'unspecified time'
|
||||
public ValidTime? ValidTime { get; set; }
|
||||
public string NLSerialize()
|
||||
public string NLQuerySerialize()
|
||||
{
|
||||
return $"{Doctype.Name().Item2} for {Employee.NLSerialize()} working for {Employer.NLSerialize()}; valid {ValidTime?.NLSerialize() ?? "for unspecified time"}.";
|
||||
return $"{Doctype.Name().Item2} for {Employee.NLQuerySerialize()} working for {Employer.NLQuerySerialize()}; valid {ValidTime?.NLQuerySerialize() ?? "for unspecified time"}.";
|
||||
}
|
||||
}
|
||||
|
|
49
src/Nyanlabs.Umogen.Core/Models/UmoDocumentResult.cs
Normal file
49
src/Nyanlabs.Umogen.Core/Models/UmoDocumentResult.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Nyanlabs.Umogen.Core.Models;
|
||||
|
||||
public class UmoDocumentResult(UmoDoctype type, Person employee, IEntity employer, ValidTime? validity, string? content)
|
||||
{
|
||||
public UmoDoctype DocType { get; } = type;
|
||||
public Person Employee { get; } = employee;
|
||||
public IEntity Employer { get; } = employer;
|
||||
public ValidTime? Validity { get; } = validity;
|
||||
public string? Content { get; } = content;
|
||||
|
||||
const string ISSUE_DATE = "$DATETIME_ISSUE",
|
||||
ENACT_DATE = "$DATETIME",
|
||||
EMPLOYER = "$EMPLOYER",
|
||||
EMPLOYEE = "$EMPLOYEE",
|
||||
VALID_TIME = "$VALIDITY_TIME",
|
||||
WORK_TYPE = "$WORK_TYPE",
|
||||
DYNAMIC_DATA = "$WORK_DYNAMIC_DATA",
|
||||
START_DATE = "$WORK_START_DATE";
|
||||
|
||||
public async Task<byte[]> ProcessPdf()
|
||||
{
|
||||
string xml = await File.ReadAllTextAsync(DocType.TemplateDoc());
|
||||
xml = xml.Replace(EMPLOYER, Employer.SerializeToDocument())
|
||||
.Replace(EMPLOYEE, Employee.SerializeToDocument())
|
||||
.Replace(VALID_TIME, (Validity ?? ValidTime.Invalid).SerializeToDocument())
|
||||
.Replace(ENACT_DATE, DateTime.Now.ToString("dd.MM.yyyy"))
|
||||
.Replace(ISSUE_DATE, DateTime.Now.ToString("dd.MM.yyyy"))
|
||||
.Replace(DYNAMIC_DATA, Content);
|
||||
string tmp = Path.GetTempFileName();
|
||||
await File.WriteAllTextAsync(tmp, xml);
|
||||
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
var proc = Process.Start("soffice", $"--headless --convert-to pdf {tmp}");
|
||||
await proc.WaitForExitAsync();
|
||||
if (proc.ExitCode != 0)
|
||||
{
|
||||
throw new DataException("invaliddddd");
|
||||
}
|
||||
});
|
||||
|
||||
byte[] data = await File.ReadAllBytesAsync(Path.ChangeExtension(tmp, "pdf"));
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
namespace Nyanlabs.Umogen.Core.Models;
|
||||
|
||||
public readonly struct ValidTime : INLSerializable
|
||||
public readonly struct ValidTime : INLSerializable, IDocSerializable
|
||||
{
|
||||
public ValidTime(DateTime start, DateTime end)
|
||||
{
|
||||
|
@ -14,9 +14,19 @@ public readonly struct ValidTime : INLSerializable
|
|||
End = start + duration;
|
||||
}
|
||||
|
||||
public static readonly ValidTime Invalid = new(DateTime.MaxValue, DateTime.MinValue);
|
||||
|
||||
public readonly DateTime Start { get; }
|
||||
public readonly DateTime End { get; }
|
||||
public readonly TimeSpan Duration => End - Start;
|
||||
|
||||
public string NLSerialize() => $"from {Start:dd MMM yyyy} until {End:dd MMM yyyy}";
|
||||
public string NLQuerySerialize()
|
||||
{
|
||||
return this.Start != DateTime.MaxValue ? $"from {Start:dd MMM yyyy} until {End:dd MMM yyyy}" : "for unspecified time";
|
||||
}
|
||||
|
||||
public string SerializeToDocument()
|
||||
{
|
||||
return this.Start != DateTime.MaxValue ? $"na czas od {Start:dd MMM yyyy} do {End:dd MMM yyyy}" : "na czas nieokreślony";
|
||||
}
|
||||
}
|
||||
|
|
6
src/Nyanlabs.Umogen.Core/Pdf/PdfRenderer.cs
Normal file
6
src/Nyanlabs.Umogen.Core/Pdf/PdfRenderer.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace Nyanlabs.Umogen.Core.Pdf;
|
||||
|
||||
public class PdfRenderer
|
||||
{
|
||||
|
||||
}
|
|
@ -1,9 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Nyanlabs.Umogen.Core;
|
||||
|
||||
|
|
|
@ -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 write Polish legal contracts in Polish language in markdown format. Fill unknown fields with signature placeholder (underscore) with enough space to sign it with pen.";
|
||||
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. You write them in format: '<type>\n<description>'";
|
||||
public static readonly JsonSerializerOptions JSON_OPTS = new(JsonSerializerDefaults.Web)
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
<PageTitle>umogen</PageTitle>
|
||||
|
||||
<div class="nav-side">
|
||||
<Navi />
|
||||
</div>
|
||||
<div class="page">
|
||||
<main>
|
||||
<article class="content px-4">
|
||||
|
|
|
@ -8,8 +8,23 @@ main {
|
|||
flex: 1;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
|
||||
.nav-side {
|
||||
color: #fefefe;
|
||||
display: flex;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
left: 0;
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
width: 12rem;
|
||||
background-image: linear-gradient(
|
||||
180deg,
|
||||
rgb(10, 140, 173) 0%,
|
||||
#198342 25%,
|
||||
#fe00fe 50%,
|
||||
#198342 75%,
|
||||
rgb(10, 140, 173) 100%
|
||||
);
|
||||
}
|
||||
|
||||
.top-row {
|
||||
|
|
3
src/Nyanlabs.Umogen.Server/Shared/Navi.razor
Normal file
3
src/Nyanlabs.Umogen.Server/Shared/Navi.razor
Normal file
|
@ -0,0 +1,3 @@
|
|||
<div class="container">
|
||||
<h1>umogen</h1>
|
||||
</div>
|
3
src/Nyanlabs.Umogen.Server/Shared/Navi.razor.css
Normal file
3
src/Nyanlabs.Umogen.Server/Shared/Navi.razor.css
Normal file
|
@ -0,0 +1,3 @@
|
|||
h2 {
|
||||
text-align: center;
|
||||
}
|
|
@ -1,6 +1,19 @@
|
|||
html,
|
||||
body {
|
||||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
footer,
|
||||
header,
|
||||
hgroup,
|
||||
menu,
|
||||
nav,
|
||||
section {
|
||||
display: block;
|
||||
}
|
||||
|
||||
h1:focus {
|
||||
|
@ -30,6 +43,12 @@ a,
|
|||
padding-top: 1.1rem;
|
||||
}
|
||||
|
||||
.container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.valid.modified:not([type="checkbox"]) {
|
||||
outline: 1px solid #26b050;
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ public class NLSerializationTests
|
|||
UmoDocument doc = new(UmoDoctype.CONTR_EMPLOYMENT, ModelEmployer, ModelEmployee);
|
||||
|
||||
// When
|
||||
var query = doc.NLSerialize();
|
||||
var query = doc.NLQuerySerialize();
|
||||
|
||||
// Then
|
||||
Assert.Equal($"Umowa o Pracę for {ModelEmployee.NLSerialize()} working for {ModelEmployer.NLSerialize()}; valid for unspecified time.", query);
|
||||
Assert.Equal($"Umowa o Pracę for {ModelEmployee.NLQuerySerialize()} working for {ModelEmployer.NLQuerySerialize()}; valid for unspecified time.", query);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -28,10 +28,10 @@ public class NLSerializationTests
|
|||
UmoDocument doc = new(UmoDoctype.CONTR_EMPLOYMENT, ModelEmployer, ModelEmployee, new(new DateTime(2023, 11, 17), TimeSpan.FromDays(1)));
|
||||
|
||||
// When
|
||||
var query = doc.NLSerialize();
|
||||
var query = doc.NLQuerySerialize();
|
||||
|
||||
// Then
|
||||
Assert.Equal($"Umowa o Pracę for {ModelEmployee.NLSerialize()} working for {ModelEmployer.NLSerialize()}; valid from 17 Nov 2023 until 18 Nov 2023.", query);
|
||||
Assert.Equal($"Umowa o Pracę for {ModelEmployee.NLQuerySerialize()} working for {ModelEmployer.NLQuerySerialize()}; valid from 17 Nov 2023 until 18 Nov 2023.", query);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -41,7 +41,7 @@ public class NLSerializationTests
|
|||
Person p = ModelEmployer;
|
||||
|
||||
// When
|
||||
var query = p.NLSerialize();
|
||||
var query = p.NLQuerySerialize();
|
||||
|
||||
// Then
|
||||
Assert.Equal("Kotek Miauczyński; PESEL 04281308999; ID series CBS4327563; born 13 Aug 2004", query);
|
||||
|
@ -59,7 +59,7 @@ public class NLSerializationTests
|
|||
};
|
||||
|
||||
// When
|
||||
var query = p.NLSerialize();
|
||||
var query = p.NLQuerySerialize();
|
||||
|
||||
// Then
|
||||
Assert.Equal("Kotek Miauczyński; unknown PESEL; unknown ID series; unknown date of birth", query);
|
||||
|
@ -74,7 +74,7 @@ public class NLSerializationTests
|
|||
LegalEntity company = ModelCompany;
|
||||
|
||||
// When
|
||||
var query = company.NLSerialize();
|
||||
var query = company.NLQuerySerialize();
|
||||
|
||||
// Then
|
||||
Assert.Equal("Nyanbyte P.S.A.; with NIP 1313131313; located in Miaumiaśna 13, Miauczki; represented by Kotek Miauczyński", query);
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Nyanlabs.Umogen.Core;
|
||||
using Nyanlabs.Umogen.Core.Models;
|
||||
|
||||
|
@ -26,12 +21,11 @@ public class GenerationTests
|
|||
UmoDocument doc = new(UmoDoctype.CONTR_EMPLOYMENT, ModelEmployer, ModelEmployee);
|
||||
|
||||
UmoProcess proc = new(eng);
|
||||
var enu = proc.Ask(doc.NLSerialize());
|
||||
var enu = proc.Ask("I would like to employ Jan Kowalski ID NO CBS3727348 for part time job as a shopkeeper.");
|
||||
|
||||
await foreach (var str in enu)
|
||||
{
|
||||
Console.Write(str);
|
||||
File.AppendAllText("/tmp/doc.md", str);
|
||||
}
|
||||
|
||||
Console.WriteLine("~");
|
||||
|
|
Loading…
Reference in a new issue