microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
436972edd2a63f773497d45cdc1de6342c7a1c20

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.AI.Models.OpenAI/Extensions/SystemMessage.cs

28lines · modepreview

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Teams.AI.Messages;

using OpenAI.Chat;

namespace Microsoft.Teams.AI.Models.OpenAI;

public static partial class MessageExtensions
{
    public static DeveloperMessage ToTeams(this SystemChatMessage message)
    {
        var content = message.Content.Select(c =>
        {
            if (c.Kind == ChatMessageContentPartKind.Text) return c.Text;
            if (c.Kind == ChatMessageContentPartKind.Image) return c.ImageUri.ToString();
            return c.Refusal;
        });

        return new DeveloperMessage(string.Join("\n", content));
    }

    public static SystemChatMessage ToOpenAI(this DeveloperMessage message)
    {
        return ChatMessage.CreateSystemMessage(message.Content);
    }
}