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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue