Skip to content

Commit db8c70c

Browse files
committed
Merge branch 'release/0.1.2-alpha'
2 parents df51978 + 62ee91d commit db8c70c

18 files changed

Lines changed: 126 additions & 63 deletions

MapperAI.sln.DotSettings.user

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AHttpClient_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc439425da351c75ac7d966a1cc8324b51a9c471865af79d2f2f3fcb65e392_003FHttpClient_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
3-
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=5ca51f47_002De3fa_002D40db_002D8e16_002D940aee47c197/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Test_Should_Create_4_Files_With_CSharp_Extension" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
3+
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=5ca51f47_002De3fa_002D40db_002D8e16_002D940aee47c197/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="Test_Should_Create_4_Files_With_CSharp_Extension" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
44
&lt;TestAncestor&gt;&#xD;
55
&lt;TestId&gt;xUnit::8B3E109D-96CA-4B6D-B379-6AF70646DC25::net8.0::MapperAI.Test.FileMapperTests.Test_Should_Create_4_Files_With_CSharp_Extension&lt;/TestId&gt;&#xD;
66
&lt;TestId&gt;xUnit::8B3E109D-96CA-4B6D-B379-6AF70646DC25::net8.0::MapperAI.Test.ClassMapperTests.Test1&lt;/TestId&gt;&#xD;
77
&lt;TestId&gt;xUnit::8B3E109D-96CA-4B6D-B379-6AF70646DC25::net8.0::MapperAI.Test.PdfMapperTests.Test1&lt;/TestId&gt;&#xD;
88
&lt;TestId&gt;xUnit::8B3E109D-96CA-4B6D-B379-6AF70646DC25::net8.0::MapperAI.Test.FileMapperTests.Test_Should_Create_4_Files_With_Go_Extension&lt;/TestId&gt;&#xD;
99
&lt;/TestAncestor&gt;&#xD;
1010
&lt;/SessionState&gt;</s:String>
11-
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=ee3fe810_002Dfb62_002D402b_002Db9c5_002D8dab803c815e/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="Test1" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
11+
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=ee3fe810_002Dfb62_002D402b_002Db9c5_002D8dab803c815e/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Test1" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
1212
&lt;TestAncestor&gt;&#xD;
1313
&lt;TestId&gt;xUnit::8B3E109D-96CA-4B6D-B379-6AF70646DC25::net8.0::MapperAI.Test.ClassMapperTests.Test1&lt;/TestId&gt;&#xD;
1414
&lt;TestId&gt;xUnit::8B3E109D-96CA-4B6D-B379-6AF70646DC25::net8.0::MapperAI.Test.FileMapperTests.Test1&lt;/TestId&gt;&#xD;
1515
&lt;TestId&gt;xUnit::8B3E109D-96CA-4B6D-B379-6AF70646DC25::net8.0::MapperAI.Test.FileMapperTests.Test_Should_Create_1_File_With_CSharp_Extension&lt;/TestId&gt;&#xD;
1616
&lt;TestId&gt;xUnit::8B3E109D-96CA-4B6D-B379-6AF70646DC25::net8.0::MapperAI.Test.PdfMapperTests.Test1&lt;/TestId&gt;&#xD;
1717
&lt;TestId&gt;xUnit::8B3E109D-96CA-4B6D-B379-6AF70646DC25::net8.0::MapperAI.Test.FileMapperTests.Test_Should_Create_4_Files_With_Go_Extension&lt;/TestId&gt;&#xD;
1818
&lt;TestId&gt;xUnit::8B3E109D-96CA-4B6D-B379-6AF70646DC25::net8.0::MapperAI.Test.FileMapperTests.Test_Should_Create_4_Files_With_CSharp_Extension&lt;/TestId&gt;&#xD;
19+
&lt;TestId&gt;xUnit::8B3E109D-96CA-4B6D-B379-6AF70646DC25::net8.0::MapperAI.Test.DI.DependencyInjectionTests.AddMapperAI_ShouldRegisterServices&lt;/TestId&gt;&#xD;
20+
&lt;TestId&gt;xUnit::8B3E109D-96CA-4B6D-B379-6AF70646DC25::net8.0::MapperAI.Test.FileMapperTests&lt;/TestId&gt;&#xD;
1921
&lt;/TestAncestor&gt;&#xD;
2022
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>

src/MapperAI.Core/Clients/GeminiMapperMapperClient.cs renamed to src/MapperAI.Core/Clients/GeminiMapperClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
namespace MapperAI.Core.Clients;
88

9-
public class GeminiMapperMapperClient : MapperClientBase, IMapperClient
9+
public class GeminiMapperClient : MapperClientBase, IMapperClient
1010
{
1111
private const string EndpointBase = "https://generativelanguage.googleapis.com/v1beta";
1212

13-
public GeminiMapperMapperClient(MapperClientConfiguration mapperClientConfiguration, IMapperSerializer serializer) : base(
14-
mapperClientConfiguration, serializer)
13+
14+
public GeminiMapperClient(MapperClientConfiguration mapperClientConfiguration, IMapperSerializer serializer, HttpClient httpClient) : base(mapperClientConfiguration, serializer, httpClient)
1515
{
1616
}
1717

src/MapperAI.Core/Clients/MapperClientBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public abstract class MapperClientBase
1212
private readonly HttpClient _httpClient;
1313
private readonly IMapperSerializer _serializer;
1414

15-
protected MapperClientBase(MapperClientConfiguration mapperClientConfiguration, IMapperSerializer serializer)
15+
protected MapperClientBase(MapperClientConfiguration mapperClientConfiguration, IMapperSerializer serializer, HttpClient httpClient)
1616
{
1717
MapperClientConfiguration = mapperClientConfiguration;
18-
_httpClient = new HttpClient();
1918
_serializer = serializer;
19+
_httpClient = httpClient;
2020
}
2121

2222
protected async Task<JsonDocument> GetAsync(string endpoint, object body, CancellationToken cancellationToken = default)
@@ -31,7 +31,7 @@ protected async Task<JsonDocument> GetAsync(string endpoint, object body, Cancel
3131
throw new MapperRequestStatusException($"Request failed with status: {response.StatusCode}");
3232
}
3333

34-
string result = await response.Content.ReadAsStringAsync();
34+
string result = await response.Content.ReadAsStringAsync(cancellationToken);
3535
return JsonDocument.Parse(result);
3636
}
3737
catch (Exception ex)

src/MapperAI.Core/Clients/MapperClientFactory.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,17 @@
55

66
namespace MapperAI.Core.Clients;
77

8-
public class MapperClientFactory : IMapperClientFactory
8+
public class MapperClientFactory(IMapperSerializer serializer, HttpClient httpClient) : IMapperClientFactory
99
{
10-
private readonly IMapperSerializer _serializer;
11-
12-
public MapperClientFactory(IMapperSerializer serializer)
13-
{
14-
_serializer = serializer;
15-
}
16-
1710
public IMapperClient CreateClient(MapperClientConfiguration configuration)
1811
{
1912
switch (configuration.Type)
2013
{
2114
case ModelType.Ollama:
22-
return new OllamaMapperMapperClient(configuration, _serializer);
15+
return new OllamaMapperClient(configuration, serializer, httpClient);
2316

2417
default:
25-
return new GeminiMapperMapperClient(configuration, _serializer);
18+
return new GeminiMapperClient(configuration, serializer, httpClient);
2619
}
2720
}
2821
}
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
using MapperAI.Core.Enums;
2+
using MapperAI.Core.Extensions.Enums;
23

34
namespace MapperAI.Core.Clients.Models;
45

56
public class MapperClientConfiguration
67
{
7-
public string Model { get; set; }
88
public string? ApiKey { get; set; }
99
public ModelType Type { get; set; }
10-
11-
public MapperClientConfiguration(string model, string? apiKey, ModelType type)
10+
public string Model => Type.GetEnumDescriptionValue();
11+
12+
public MapperClientConfiguration( string? apiKey, ModelType type)
1213
{
13-
Model = model;
1414
ApiKey = apiKey;
1515
Type = type;
1616
}
1717

18-
public MapperClientConfiguration(string model, ModelType type)
19-
{
20-
Model = model;
21-
Type = type;
22-
}
2318
}

src/MapperAI.Core/Clients/OllamaMapperMapperClient.cs renamed to src/MapperAI.Core/Clients/OllamaMapperClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
namespace MapperAI.Core.Clients;
99

10-
public class OllamaMapperMapperClient : MapperClientBase ,IMapperClient
10+
public class OllamaMapperClient : MapperClientBase ,IMapperClient
1111
{
1212
private const string Endpoint = "http://localhost:11434/api/generate";
1313

14-
public OllamaMapperMapperClient(MapperClientConfiguration mapperClientConfiguration, IMapperSerializer serializer) : base(mapperClientConfiguration, serializer)
14+
15+
public OllamaMapperClient(MapperClientConfiguration mapperClientConfiguration, IMapperSerializer serializer, HttpClient httpClient) : base(mapperClientConfiguration, serializer, httpClient)
1516
{
1617
}
1718

18-
1919
public async Task<MapperClientResponse> SendAsync(string prompt, CancellationToken cancellationToken)
2020
{
2121
dynamic payload = CreatePayload(prompt);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using MapperAI.Core.Clients;
2+
using MapperAI.Core.Clients.Interfaces;
3+
using MapperAI.Core.Clients.Models;
4+
using MapperAI.Core.Enums;
5+
using MapperAI.Core.Mappers;
6+
using MapperAI.Core.Mappers.Interfaces;
7+
using MapperAI.Core.Serializers;
8+
using MapperAI.Core.Serializers.Interfaces;
9+
using Microsoft.Extensions.DependencyInjection;
10+
11+
namespace MapperAI.Core.DI;
12+
13+
public static class DependencyInjection
14+
{
15+
public static IServiceCollection AddMapperAI(this IServiceCollection services, string apiKey, ModelType modelType)
16+
{
17+
services.AddMapperClientConfiguration(apiKey, modelType);
18+
services.AddHttpClient();
19+
services.AddSingleton<IMapperSerializer, MapperSerializer>();
20+
services.AddSingleton<IMapperClientFactory, MapperClientFactory>();
21+
services.AddScoped<IClassMapper, ClassMapper>();
22+
23+
services.AddScoped<IClassMapper, ClassMapper>();
24+
services.AddScoped<IFileMapper, FileMapper>();
25+
services.AddScoped<IPDFMapper, PdfMapper>();
26+
27+
return services;
28+
}
29+
30+
private static void AddMapperClientConfiguration(this IServiceCollection services, string apiKey, ModelType modelType)
31+
{
32+
MapperClientConfiguration configuration = new(apiKey, modelType);
33+
services.AddSingleton<MapperClientConfiguration>(s => configuration);
34+
35+
}
36+
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
namespace MapperAI.Core.Enums;
1+
using System.ComponentModel;
2+
3+
namespace MapperAI.Core.Enums;
24

35
public enum ModelType
46
{
5-
6-
Gemini,
7+
[Description("gemini-2.0-flash")]
8+
GeminiFlash2_0,
79
ChatGpt,
810
Ollama
911
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.ComponentModel;
2+
using System.Reflection;
3+
4+
namespace MapperAI.Core.Extensions.Enums;
5+
6+
public static class EnumExtension
7+
{
8+
public static string GetEnumDescriptionValue(this Enum data)
9+
{
10+
FieldInfo? field = data.GetType().GetField(data.ToString());
11+
var attribute = field?.GetCustomAttribute<DescriptionAttribute>();
12+
return attribute?.Description ?? throw new InvalidEnumArgumentException();
13+
}
14+
}

src/MapperAI.Core/Initializers/DependencyInitializer.cs renamed to src/MapperAI.Core/Extensions/Initializers/InitializerExtension.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using System.Reflection;
1+
using System.Reflection;
22

3-
namespace MapperAI.Core.Initializers;
3+
namespace MapperAI.Core.Extensions.Initializers;
44

5-
public class DependencyInitializer
5+
public static class InitializerExtension
66
{
7-
8-
public static void Initialize(object obj)
7+
public static void Initialize(this object obj)
98
{
109
var properties = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
1110
var genericProperties = properties.Where(x => x.PropertyType.IsGenericType);
@@ -17,6 +16,7 @@ public static void Initialize(object obj)
1716
}
1817
}
1918
}
19+
2020
private static void InitializeDependencyProperties(Type? itemType, PropertyInfo property, object obj)
2121
{
2222
if (itemType == null)
@@ -47,5 +47,4 @@ private static void InitializeDependencyProperties(Type? itemType, PropertyInfo
4747

4848
property.SetValue(obj, listInstance);
4949
}
50-
5150
}

0 commit comments

Comments
 (0)