-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDashScopeMapper.cs
34 lines (30 loc) · 1.08 KB
/
DashScopeMapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Cnblogs.DashScope.Core;
using Microsoft.SemanticKernel.ChatCompletion;
namespace Cnblogs.SemanticKernel.Connectors.DashScope;
internal static class DashScopeMapper
{
public static List<TextChatMessage> ToChatMessages(this ChatHistory history)
{
return history.Select(
x =>
{
if (x is DashScopeChatMessageContent d)
{
return new TextChatMessage(x.Role.Label, x.Content ?? string.Empty, d.Name, ToolCalls: d.ToolCalls);
}
return new TextChatMessage(x.Role.Label, x.Content ?? string.Empty);
}).ToList();
}
public static Dictionary<string, object?>? ToMetaData<TOutput, TUsage>(
this ModelResponse<TOutput, TUsage>? response)
where TUsage : class
where TOutput : class
{
return response == null
? null
: new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
{
{ "Usage", response.Usage }, { "RequestId", response.RequestId }
};
}
}