Skip to content

Commit

Permalink
3.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
karamem0 committed Oct 15, 2024
1 parent 7700056 commit ea1552f
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 48 deletions.
28 changes: 8 additions & 20 deletions source/server/Karamem0.Commistant.Bot/Bots/ActivityBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,15 @@ protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivi
{
if (dc.ActiveDialog is null)
{
var result = await new Func<Task<DialogTurnResult?>>(async () =>
var arguments = await this.openAIService.GetArgumentsAsync(command, cancellationToken: cancellationToken);
var result = arguments?.Type switch
{
var message = await this.openAIService.ChatCompletionAsync(command, cancellationToken: cancellationToken);
if (message.FinishReason == ChatFinishReason.ToolCalls)
{
var arguments = message.ToolCalls.Select(item => item.FunctionArguments).First();
var content = JsonSerializer.Deserialize<ConversationPropertyArguments>(arguments?.ToString());
return content?.Type switch
{
"会議開始後" => await dc.BeginDialogAsync(nameof(StartMeetingDialog), content, cancellationToken: cancellationToken),
"会議終了前" => await dc.BeginDialogAsync(nameof(EndMeetingDialog), content, cancellationToken: cancellationToken),
"会議中" => await dc.BeginDialogAsync(nameof(InMeetingDialog), content, cancellationToken: cancellationToken),
"初期化" => await dc.BeginDialogAsync(nameof(ResetDialog), cancellationToken: cancellationToken),
_ => null,
};
}
else
{
return null;
}
})();
"会議開始後" => await dc.BeginDialogAsync(nameof(StartMeetingDialog), arguments, cancellationToken: cancellationToken),
"会議終了前" => await dc.BeginDialogAsync(nameof(EndMeetingDialog), arguments, cancellationToken: cancellationToken),
"会議中" => await dc.BeginDialogAsync(nameof(InMeetingDialog), arguments, cancellationToken: cancellationToken),
"初期化" => await dc.BeginDialogAsync(nameof(ResetDialog), cancellationToken: cancellationToken),
_ => null,
};
if (result is null)
{
_ = await turnContext.SendActivityAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private async Task<DialogTurnResult> BeforeConfirmAsync(WaterfallStepContext ste
new AdaptiveTextInput()
{
Id = "Message",
IsMultiline = true,
Label = "メッセージ",
Placeholder = "会議後に表示されるメッセージ",
Style = AdaptiveTextInputStyle.Text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private async Task<DialogTurnResult> BeforeConfirmAsync(WaterfallStepContext ste
new AdaptiveTextInput()
{
Id = "Message",
IsMultiline = true,
Label = "メッセージ",
Placeholder = "会議中に表示されるメッセージ",
Style = AdaptiveTextInputStyle.Text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private async Task<DialogTurnResult> BeforeConfirmAsync(WaterfallStepContext ste
new AdaptiveTextInput()
{
Id = "Message",
IsMultiline = true,
Label = "メッセージ",
Placeholder = "開始後に表示されるメッセージ",
Style = AdaptiveTextInputStyle.Text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public static async Task<BlobContent<T>> GetObjectAsync<T>(this BlobClient targe

public static async Task SetObjectAsync<T>(this BlobClient target, BlobContent<T> value)
{
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(value.Data)));
var content = BinaryData.FromString(JsonSerializer.Serialize(value.Data));
_ = await target.UploadAsync(
stream,
content,
new BlobUploadOptions()
{
Conditions = new BlobRequestConditions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@ public static class JsonSerializer

public static T? Deserialize<T>(string? value)
{
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
_ = value ?? throw new ArgumentNullException(nameof(value));
return JsonConvert.DeserializeObject<T>(value, settings);
}

public static string Serialize<T>(T? value)
{
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
_ = value ?? throw new ArgumentNullException(nameof(value));
return JsonConvert.SerializeObject(value, settings);
}

Expand Down
14 changes: 11 additions & 3 deletions source/server/Karamem0.Commistant.Common/Services/OpenAIService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

using Azure.AI.OpenAI;
using Karamem0.Commistant.Models;
using Karamem0.Commistant.Resources;
using OpenAI;
using OpenAI.Chat;
Expand All @@ -22,7 +23,7 @@ namespace Karamem0.Commistant.Services;
public interface IOpenAIService
{

Task<ChatCompletion> ChatCompletionAsync(string text, CancellationToken cancellationToken = default);
Task<ConversationPropertyArguments?> GetArgumentsAsync(string text, CancellationToken cancellationToken = default);

}

Expand All @@ -33,7 +34,7 @@ public class OpenAIService(OpenAIClient openAIClient, string openAIModelName) :

private readonly string openAIModelName = openAIModelName;

public async Task<ChatCompletion> ChatCompletionAsync(string text, CancellationToken cancellationToken = default)
public async Task<ConversationPropertyArguments?> GetArgumentsAsync(string text, CancellationToken cancellationToken = default)
{
var chatCompletionsOptions = new ChatCompletionOptions()
{
Expand Down Expand Up @@ -69,7 +70,14 @@ public async Task<ChatCompletion> ChatCompletionAsync(string text, CancellationT
chatCompletionsOptions,
cancellationToken
);
return chatCompletion.Value;
if (chatCompletion.Value.FinishReason == ChatFinishReason.ToolCalls)
{
return chatCompletion.Value.ToolCalls
.Select(item => item.FunctionArguments)
.First()
.ToObjectFromJson<ConversationPropertyArguments>();
}
return null;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override async Task ExecuteAsync(
CancellationToken cancellationToken = default
)
{
if (property.InMeeting is not true)
if (property.InMeeting is false)
{
return;
}
Expand Down Expand Up @@ -79,24 +79,29 @@ public override async Task ExecuteAsync(
{
this.logger.EndMeetingMessageNotifying(reference, property);
var card = new AdaptiveCard("1.3");
if (string.IsNullOrEmpty(property.EndMeetingMessage) is not true)
if (string.IsNullOrEmpty(property.EndMeetingMessage) is false)
{
card.Body.Add(new AdaptiveTextBlock()
{
Text = property.EndMeetingMessage,
Wrap = true
});
}
if (string.IsNullOrEmpty(property.EndMeetingUrl) is not true)
if (Uri.TryCreate(property.EndMeetingUrl, UriKind.Absolute, out var url))
{
var bytes = await this.qrCodeService.CreateAsync(property.EndMeetingUrl, cancellationToken);
var bytes = await this.qrCodeService.CreateAsync(url.ToString(), cancellationToken);
var base64 = Convert.ToBase64String(bytes);
card.Body.Add(new AdaptiveImage()
{
AltText = property.InMeetingUrl,
AltText = url.ToString(),
Size = AdaptiveImageSize.Stretch,
Url = new Uri($"data:image/png;base64,{base64}")
});
card.Actions.Add(new AdaptiveOpenUrlAction()
{
Title = "URL を開く",
Url = url,
});
}
var activity = MessageFactory.Attachment(new Attachment()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override async Task ExecuteAsync(
CancellationToken cancellationToken = default
)
{
if (property.InMeeting is not true)
if (property.InMeeting is false)
{
return;
}
Expand All @@ -75,24 +75,29 @@ public override async Task ExecuteAsync(
{
this.logger.InMeetingMessageNotifying(reference, property);
var card = new AdaptiveCard("1.3");
if (string.IsNullOrEmpty(property.InMeetingMessage) is not true)
if (string.IsNullOrEmpty(property.InMeetingMessage) is false)
{
card.Body.Add(new AdaptiveTextBlock()
{
Text = property.InMeetingMessage,
Wrap = true
});
}
if (string.IsNullOrEmpty(property.InMeetingUrl) is not true)
if (Uri.TryCreate(property.InMeetingUrl, UriKind.Absolute, out var url))
{
var bytes = await this.qrCodeService.CreateAsync(property.InMeetingUrl);
var bytes = await this.qrCodeService.CreateAsync(url.ToString(), cancellationToken);
var base64 = Convert.ToBase64String(bytes);
card.Body.Add(new AdaptiveImage()
{
AltText = property.InMeetingUrl,
AltText = url.ToString(),
Size = AdaptiveImageSize.Stretch,
Url = new Uri($"data:image/png;base64,{base64}")
});
card.Actions.Add(new AdaptiveOpenUrlAction()
{
Title = "URL を開く",
Url = url,
});
}
var activity = MessageFactory.Attachment(new Attachment()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override async Task ExecuteAsync(
CancellationToken cancellationToken = default
)
{
if (property.InMeeting is not true)
if (property.InMeeting is false)
{
return;
}
Expand Down Expand Up @@ -79,24 +79,29 @@ public override async Task ExecuteAsync(
{
this.logger.StartMeetingMessageNotifying(reference, property);
var card = new AdaptiveCard("1.3");
if (string.IsNullOrEmpty(property.StartMeetingMessage) is not true)
if (string.IsNullOrEmpty(property.StartMeetingMessage) is false)
{
card.Body.Add(new AdaptiveTextBlock()
{
Text = property.StartMeetingMessage,
Wrap = true
});
}
if (string.IsNullOrEmpty(property.StartMeetingUrl) is not true)
if (Uri.TryCreate(property.StartMeetingUrl, UriKind.Absolute, out var url))
{
var bytes = await this.qrCodeService.CreateAsync(property.StartMeetingUrl);
var bytes = await this.qrCodeService.CreateAsync(url.ToString(), cancellationToken);
var base64 = Convert.ToBase64String(bytes);
card.Body.Add(new AdaptiveImage()
{
AltText = property.InMeetingUrl,
AltText = url.ToString(),
Size = AdaptiveImageSize.Stretch,
Url = new Uri($"data:image/png;base64,{base64}")
});
card.Actions.Add(new AdaptiveOpenUrlAction()
{
Title = "URL を開く",
Url = url,
});
}
var activity = MessageFactory.Attachment(new Attachment()
{
Expand Down

0 comments on commit ea1552f

Please sign in to comment.