Skip to content

Commit e921136

Browse files
Merge pull request #265 from Avanade/feat/newcartridges
feat: creates GenIA interfaces
2 parents 001f573 + b342a87 commit e921136

File tree

14 files changed

+290
-60
lines changed

14 files changed

+290
-60
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Liquid.Core.Exceptions;
2+
using Liquid.Core.Interfaces;
3+
using System;
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Threading.Tasks;
6+
7+
namespace Liquid.Core.AbstractMappers
8+
{
9+
///<inheritdoc/>
10+
[ExcludeFromCodeCoverage]
11+
public abstract class LiquidMapper<TFrom, TTo> : ILiquidMapper<TFrom, TTo>
12+
{
13+
private readonly string _mapperName;
14+
15+
/// <summary>
16+
/// Create a new instance of <see cref="LiquidMapper{TFrom, TTo}"/>
17+
/// </summary>
18+
/// <param name="mapperName">Mapper implementation name.</param>
19+
protected LiquidMapper(string mapperName)
20+
{
21+
_mapperName = mapperName;
22+
}
23+
///<inheritdoc/>
24+
public async Task<TTo> Map(TFrom dataObject, string entityName = null)
25+
{
26+
if (dataObject is null)
27+
{
28+
throw new ArgumentNullException(nameof(dataObject));
29+
}
30+
31+
try
32+
{
33+
return await MapImpl(dataObject, entityName);
34+
}
35+
catch (Exception e)
36+
{
37+
var msg = $"{_mapperName} throw data mapping error: '{e.Message}'";
38+
39+
throw new DataMappingException(msg, e);
40+
}
41+
}
42+
/// <summary>
43+
///
44+
/// </summary>
45+
/// <param name="dataObject"></param>
46+
/// <param name="entityName"></param>
47+
/// <returns></returns>
48+
protected abstract Task<TTo> MapImpl(TFrom dataObject, string entityName = null);
49+
}
50+
}

src/Liquid.Core/AbstractMappers/OcrResultMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public OcrResultMapper(string mapperName)
2525
_mapperName = mapperName;
2626
}
2727
///<inheritdoc/>
28-
public async Task<OcrResult> Map(TFrom dataObject)
28+
public async Task<OcrResult> Map(TFrom dataObject, string entityName = null)
2929
{
3030
if (dataObject is null)
3131
{

src/Liquid.Core/Entities/ChatMessages.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Collections.Generic;
2+
using System.Diagnostics.CodeAnalysis;
3+
4+
namespace Liquid.Core.Entities
5+
{
6+
/// <summary>
7+
/// Set de propriedades referentes à um item do BlobStorage.
8+
/// </summary>
9+
[ExcludeFromCodeCoverage]
10+
public class LiquidBlob
11+
{
12+
/// <summary>
13+
/// Lista de tags referentes ao blob.
14+
/// </summary>
15+
public IDictionary<string, string> Tags { get; set; } = new Dictionary<string, string>();
16+
17+
/// <summary>
18+
/// Conteúdo do blob.
19+
/// </summary>
20+
public byte[] Blob { get; set; }
21+
22+
/// <summary>
23+
/// Nome do arquivo no Storage.
24+
/// </summary>
25+
public string Name { get; set; }
26+
27+
/// <summary>
28+
/// Caminho do blob.
29+
/// </summary>
30+
public string AbsoluteUri { get; set; }
31+
32+
}
33+
}
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23

34
namespace Liquid.Core.Exceptions
45
{
5-
[Serializable]
6-
internal class DataMappingException : LiquidException
6+
/// <summary>
7+
/// Occurs when an exception is raised during data mapping.
8+
/// </summary>
9+
[ExcludeFromCodeCoverage]
10+
public class DataMappingException : Exception
711
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="DataMappingException"/> class.
14+
/// </summary>
815
public DataMappingException()
916
{
1017
}
1118

19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="DataMappingException"/> class with a specified error message.
21+
/// </summary>
22+
/// <param name="message"></param>
1223
public DataMappingException(string message) : base(message)
1324
{
1425
}
1526

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="DataMappingException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
29+
/// </summary>
30+
/// <param name="message"></param>
31+
/// <param name="innerException"></param>
1632
public DataMappingException(string message, Exception innerException) : base(message, innerException)
1733
{
1834
}
19-
2035
}
21-
}
36+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Liquid.Core.GenAi.Enums;
2+
using System;
3+
using System.Diagnostics.CodeAnalysis;
4+
5+
namespace Liquid.Core.GenAi.Entities
6+
{
7+
/// <summary>
8+
/// The content of the chat message.
9+
/// </summary>
10+
[ExcludeFromCodeCoverage]
11+
public class LiquidChatContent
12+
{
13+
/// <summary>
14+
/// The kind of content.
15+
/// </summary>
16+
public LiquidContentKind Kind { get; set; }
17+
18+
/// <summary>
19+
/// The text content of the message.
20+
/// </summary>
21+
public string Text { get; set; }
22+
23+
/// <summary>
24+
/// The image content url of the message.
25+
/// </summary>
26+
public Uri ImageUri { get; set; }
27+
28+
}
29+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace Liquid.Core.GenAi.Entities
4+
{
5+
/// <summary>
6+
/// Context message associated with a chat completions request.
7+
/// </summary>
8+
[ExcludeFromCodeCoverage]
9+
public class LiquidChatMessage
10+
{
11+
/// <summary>
12+
/// The chat role associated with this message.
13+
/// </summary>
14+
public string Role { get; set; }
15+
16+
/// <summary>
17+
/// The contents of the message.
18+
/// </summary>
19+
public LiquidChatContent[] Content { get; set; }
20+
}
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Generic;
2+
using System.Diagnostics.CodeAnalysis;
3+
4+
namespace Liquid.Core.GenAi.Entities
5+
{
6+
/// <summary>
7+
/// The object of context messages associated with a chat completions request
8+
/// </summary>
9+
[ExcludeFromCodeCoverage]
10+
public class LiquidChatMessages
11+
{
12+
/// <summary>
13+
/// The collection of context messages associated with a chat completions request.
14+
/// </summary>
15+
public List<LiquidChatMessage> Messages { get; set; } = new List<LiquidChatMessage>();
16+
}
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Liquid.Core.GenAi.Enums
8+
{
9+
/// <summary>
10+
/// Represents the possibles of underlying data for a chat message's <c>Content</c> property.
11+
/// </summary>
12+
public enum LiquidContentKind
13+
{
14+
/// <summary>
15+
/// Text content
16+
/// </summary>
17+
Text,
18+
/// <summary>
19+
/// Image content
20+
/// </summary>
21+
Image
22+
}
23+
}
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
using Liquid.Core.Entities;
2+
using Liquid.Core.GenAi.Entities;
3+
using Liquid.Core.GenAi.Settings;
24
using Liquid.Core.Settings;
35
using System;
46
using System.Collections.Generic;
57
using System.Threading.Tasks;
68

7-
namespace Liquid.Core.Interfaces
9+
namespace Liquid.Core.GenAi
810
{
911
/// <summary>
1012
/// This service is the hub of Liquid adapter custom completions for Generative AI.
1113
/// </summary>
12-
public interface ILiquidChatCompletions
14+
public interface ILiquidGenAi
1315
{
14-
1516
/// <summary>
1617
/// Get chat completions for provided content and functions.
1718
/// </summary>
1819
/// <param name="messages">Context messages associated with chat completions request.</param>
1920
/// <param name="functions"> A list of functions the model may generate JSON inputs for.</param>
2021
/// <param name="settings">The options for chat completions request.</param>
21-
Task<ChatCompletionResult> FunctionCalling(ChatMessages messages, List<FunctionBody> functions, CompletionsSettings settings);
22+
Task<ChatCompletionResult> FunctionCalling(LiquidChatMessages messages, List<FunctionBody> functions, CompletionsOptions settings);
2223

2324
/// <summary>
2425
/// Get chat completions for provided chat context messages.
@@ -31,15 +32,15 @@ public interface ILiquidChatCompletions
3132
/// Typical usage begins with a chat message for the System role that provides instructions for
3233
/// the behavior of the assistant, followed by alternating messages between the User and
3334
/// Assistant roles.</param>
34-
Task<ChatCompletionResult> ChatCompletions(string content, string prompt, CompletionsSettings settings, ChatMessages? chatHistory = null);
35+
Task<ChatCompletionResult> CompleteChatAsync(string content, string prompt, CompletionsOptions settings, LiquidChatMessages chatHistory = null);
3536

3637
/// <summary>
37-
/// Return the computed embeddings for a given prompt.
38+
/// Get chat completions for provided chat context messages and functions.
3839
/// </summary>
39-
/// <param name="description">Input texts to get embeddings for, encoded as a an array of strings.</param>
40-
/// <param name="modelName"></param>
41-
/// <param name="clientId">Client connection alias to use for a chat completions request.
42-
/// This connection must be configured in application previously <see cref="GenAiSettings"/></param>
43-
Task<ReadOnlyMemory<float>> GetEmbeddings(string description, string modelName, string clientId);
40+
/// <param name="messages">Messages associated with chat completions request.</param>
41+
/// <param name="functions"> A list of functions the model may generate JSON inputs for.</param>
42+
/// <param name="chatHistory"> The collection of context messages associated with this chat completions request. </param>
43+
/// <param name="settings">The options for chat completions request.</param>
44+
Task<ChatCompletionResult> CompleteChatAsync(LiquidChatMessages messages, CompletionsOptions settings, List<FunctionBody> functions = null, LiquidChatMessages chatHistory = null);
4445
}
4546
}

0 commit comments

Comments
 (0)