├── src
├── ArtificialApi
│ ├── appsettings.Development.json
│ ├── appsettings.json
│ ├── ArtificialApi.http
│ ├── Properties
│ │ └── launchSettings.json
│ ├── ArtificialApi.csproj
│ └── Program.cs
├── ArtificialCast
│ ├── ArtificialCast.csproj
│ └── ArtificialCast.cs
├── ArtificialCast.Tests
│ ├── ArtificialCast.Tests.csproj
│ └── UnitTest1.cs
└── ArtificialCast.sln
├── .gitignore
├── API.md
├── LICENSE
└── README.md
/src/ArtificialApi/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft.AspNetCore": "Warning"
6 | }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/ArtificialApi/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft.AspNetCore": "Warning"
6 | }
7 | },
8 | "AllowedHosts": "*"
9 | }
10 |
--------------------------------------------------------------------------------
/src/ArtificialApi/ArtificialApi.http:
--------------------------------------------------------------------------------
1 | @ArtificialApi_HostAddress = http://localhost:5026
2 |
3 | GET {{ArtificialApi_HostAddress}}/todos/
4 | Accept: application/json
5 |
6 | ###
7 |
8 | GET {{ArtificialApi_HostAddress}}/todos/1
9 | Accept: application/json
10 |
11 | ###
12 |
--------------------------------------------------------------------------------
/src/ArtificialCast/ArtificialCast.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net9.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/ArtificialApi/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/launchsettings.json",
3 | "profiles": {
4 | "http": {
5 | "commandName": "Project",
6 | "dotnetRunMessages": true,
7 | "launchBrowser": true,
8 | "launchUrl": "todos",
9 | "applicationUrl": "http://localhost:5026",
10 | "environmentVariables": {
11 | "ASPNETCORE_ENVIRONMENT": "Development"
12 | }
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/ArtificialApi/ArtificialApi.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net9.0
5 | enable
6 | enable
7 | true
8 | false
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build Folders (you can edit these to match your project structure)
2 | bin/
3 | obj/
4 |
5 | # User-specific files
6 | *.user
7 | *.suo
8 | *.userosscache
9 | *.sln.docstates
10 |
11 | # Logs
12 | *.log
13 |
14 | # Visual Studio Code
15 | .vscode/
16 | *.code-workspace
17 |
18 | # Rider
19 | .idea/
20 | *.sln.iml
21 |
22 | # Dotnet specific
23 | project.lock.json
24 | project.fragment.lock.json
25 | artifacts/
26 |
27 | # NuGet
28 | *.nupkg
29 | *.snupkg
30 | .nuget/
31 | packages/
32 |
33 | # Entity Framework
34 | *.efmigration
35 |
36 | # ASP.NET Scaffolding
37 | ScaffoldingReadMe.txt
38 |
39 | # Others
40 | *.DS_Store
41 | Thumbs.db
--------------------------------------------------------------------------------
/src/ArtificialCast.Tests/ArtificialCast.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net9.0
5 | enable
6 | enable
7 | false
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/API.md:
--------------------------------------------------------------------------------
1 | # API
2 |
3 | ## ArtificialCast AC
4 |
5 | Transforms any object into another type using structured inference and LLMs.
6 |
7 | ```csharp
8 | public static Task AC(TIn input);
9 | ```
10 |
11 | ## ArtificialFactory AF
12 | Generates an object of the specified type using type metadata.
13 |
14 | ```csharp
15 | public static Task AF();
16 | ```
17 |
18 | ## ArtificialMerge AM
19 | Merges two unrelated objects into a new type using structured inference.
20 |
21 | ```csharp
22 | public static Task AM(T1 input1, T2 input2);
23 | ```
24 |
25 | ### ArtificialSplit AS
26 | Splits a single object into two separate types using structured inference.
27 |
28 | ```csharp
29 | public static Task<(Tuple)> AS(TIn input);
30 | ```
31 |
32 | ## ArtificialQuery AQ
33 | Performs a natural language query on an object or array, returning a plausible result.
34 |
35 | ```csharp
36 | public static Task AQ(TIn input, string query);
37 | ```
38 |
39 | ## ArtificialCast Configuration
40 | ```csharp
41 | // This is required to be set to a model (like gemma3:4b)
42 | public static string Model { get; set; } = "";
43 |
44 | // These are optional
45 | public static string Host { get; set; } = "http://localhost:11434";
46 | public static string SystemPrompt { get; set; } = "...";
47 | ```
--------------------------------------------------------------------------------
/src/ArtificialCast.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31903.59
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArtificialCast", "ArtificialCast\ArtificialCast.csproj", "{D2484EDC-E207-4A1E-91FB-1ADE4BC9000F}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArtificialCast.Tests", "ArtificialCast.Tests\ArtificialCast.Tests.csproj", "{42833AF1-742B-4BAC-8A78-B7F23EE835A9}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArtificialApi", "ArtificialApi\ArtificialApi.csproj", "{400208BB-42AD-4B43-98B8-694B02CC257D}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {D2484EDC-E207-4A1E-91FB-1ADE4BC9000F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {D2484EDC-E207-4A1E-91FB-1ADE4BC9000F}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {D2484EDC-E207-4A1E-91FB-1ADE4BC9000F}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 | {D2484EDC-E207-4A1E-91FB-1ADE4BC9000F}.Release|Any CPU.Build.0 = Release|Any CPU
25 | {42833AF1-742B-4BAC-8A78-B7F23EE835A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 | {42833AF1-742B-4BAC-8A78-B7F23EE835A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 | {42833AF1-742B-4BAC-8A78-B7F23EE835A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {42833AF1-742B-4BAC-8A78-B7F23EE835A9}.Release|Any CPU.Build.0 = Release|Any CPU
29 | {400208BB-42AD-4B43-98B8-694B02CC257D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30 | {400208BB-42AD-4B43-98B8-694B02CC257D}.Debug|Any CPU.Build.0 = Debug|Any CPU
31 | {400208BB-42AD-4B43-98B8-694B02CC257D}.Release|Any CPU.ActiveCfg = Release|Any CPU
32 | {400208BB-42AD-4B43-98B8-694B02CC257D}.Release|Any CPU.Build.0 = Release|Any CPU
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/src/ArtificialApi/Program.cs:
--------------------------------------------------------------------------------
1 | global using static ArtificialCast.ArtificialCast;
2 |
3 | using System.Text;
4 | using System.Text.Json;
5 | using System.Text.Json.Serialization;
6 |
7 | var builder = WebApplication.CreateBuilder(args);
8 |
9 | builder.Services.ConfigureHttpJsonOptions(options =>
10 | {
11 | options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
12 | });
13 |
14 | var app = builder.Build();
15 |
16 | app.Map("{**catchall}", async (HttpContext context) =>
17 | {
18 | try
19 | {
20 | var apiRequest = new WebRequest
21 | {
22 | Method = context.Request.Method,
23 | Path = context.Request.Path + context.Request.QueryString,
24 | Headers = context.Request.Headers.ToDictionary(h => h.Key, h => h.Value.ToString()),
25 | Body = await new StreamReader(context.Request.Body).ReadToEndAsync()
26 | };
27 |
28 | Console.WriteLine($"Request: {apiRequest.Method} {apiRequest.Path}");
29 | try
30 | {
31 | var apiResponse = await AC(apiRequest);
32 |
33 | context.Response.StatusCode = apiResponse.StatusCode;
34 |
35 | if (apiResponse.Headers != null)
36 | {
37 | foreach (var kvp in apiResponse.Headers)
38 | context.Response.Headers[kvp.Key] = kvp.Value;
39 | }
40 |
41 | if (!string.IsNullOrWhiteSpace(apiResponse.GeneratedBody))
42 | {
43 | context.Response.Headers.Remove("Content-Length");
44 | await context.Response.WriteAsync(apiResponse.GeneratedBody);
45 | }
46 | }
47 | catch (Exception acEx)
48 | {
49 | Console.Error.WriteLine($"Error in AC function: {acEx.Message}");
50 | context.Response.StatusCode = StatusCodes.Status500InternalServerError;
51 | await context.Response.WriteAsync("An error occurred while processing the request.");
52 | }
53 | }
54 | catch (Exception ex)
55 | {
56 | Console.Error.WriteLine($"Error: {ex.Message}");
57 | context.Response.StatusCode = StatusCodes.Status500InternalServerError;
58 | await context.Response.WriteAsync("An internal server error occurred.");
59 | }
60 | });
61 |
62 | app.Run();
63 |
64 | public class WebRequest
65 | {
66 | public string AdditionalModelInstructions = "In case css is used, it must be inline or appended as a