mirror of
https://github.com/maker-community/ElectronBot.DotNet.git
synced 2026-10-29 05:10:45 +08:00
add image
This commit is contained in:
@@ -11,5 +11,7 @@ public class LingxiSpaceType
|
||||
|
||||
public const string Word = "word";
|
||||
|
||||
public const string Image = "image";
|
||||
|
||||
public const string Weather = "weather";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using BotSharp.Abstraction.Conversations;
|
||||
using BotSharp.Abstraction.Conversations.Models;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Verdure.Braincase.Copilot.Plugin.Models;
|
||||
using Verdure.Braincase.Core.Contracts.Services;
|
||||
using Verdure.Braincase.Core.Models.Lingxi;
|
||||
using Verdure.ElectronBot.Core.Contracts.Services;
|
||||
|
||||
namespace Verdure.Braincase.Copilot.Plugin.Functions;
|
||||
|
||||
public class CustomGenerateImageFn : IFunctionCallback
|
||||
{
|
||||
public string Name => "custom_generate_image";
|
||||
|
||||
private readonly IServiceProvider _service;
|
||||
private readonly IBotToolService _botToolService;
|
||||
private readonly JsonSerializerOptions _options;
|
||||
private readonly ILingxiSpaceService _lingxiSpaceService;
|
||||
private readonly IConversationService _conversationService;
|
||||
public CustomGenerateImageFn(IServiceProvider service,
|
||||
IBotToolService botToolService,
|
||||
ILingxiSpaceService lingxiSpaceService,
|
||||
IConversationService conversationService)
|
||||
{
|
||||
_service = service;
|
||||
_options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true,
|
||||
AllowTrailingCommas = true,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
};
|
||||
_botToolService = botToolService;
|
||||
_lingxiSpaceService = lingxiSpaceService;
|
||||
_conversationService = conversationService;
|
||||
}
|
||||
|
||||
public async Task<bool> Execute(RoleDialogModel message)
|
||||
{
|
||||
var args = JsonSerializer.Deserialize<CustomGenerateImageFunctionArgs>(message.FunctionArgs ?? "", _options) ?? new CustomGenerateImageFunctionArgs();
|
||||
|
||||
message.StopCompletion = true;
|
||||
|
||||
var lingxiSpace = await _lingxiSpaceService.AddAsync(new LingxiSpace
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
ConversationId = _conversationService.ConversationId,
|
||||
//Content = JsonSerializer.SerializeToDocument(wordContent, _options),
|
||||
Name = args.ImageName,
|
||||
Desc = "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/67/20241124/9d34e27a/c2fb7b01-44af-4abd-9929-d520d6c06e39-1.png?Expires=1732515865&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=z8%2FYLCgTbFbwDZdVVQapFMgQVzY%3D",//args.ImageDescription,
|
||||
Type = LingxiSpaceType.Image,
|
||||
CreatedTime = DateTime.UtcNow
|
||||
});
|
||||
|
||||
WeakReferenceMessenger.Default.Send(lingxiSpace);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Verdure.Braincase.Copilot.Plugin.Models;
|
||||
|
||||
public class CustomGenerateImageFunctionArgs
|
||||
{
|
||||
[JsonPropertyName("image_name")]
|
||||
public string ImageName { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("image_description")]
|
||||
public string ImageDescription { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -27,6 +27,7 @@
|
||||
<None Remove="data\agents\1048dcd3-9f70-daa2-7dcc-40314ae81473\instructions\instruction.liquid" />
|
||||
<None Remove="data\agents\2e54c75b-03e1-06db-53d9-d86a073675e2\agent.json" />
|
||||
<None Remove="data\agents\2e54c75b-03e1-06db-53d9-d86a073675e2\functions\control_the_lights.json" />
|
||||
<None Remove="data\agents\2e54c75b-03e1-06db-53d9-d86a073675e2\functions\custom_generate_image.json" />
|
||||
<None Remove="data\agents\2e54c75b-03e1-06db-53d9-d86a073675e2\functions\get_weather.json" />
|
||||
<None Remove="data\agents\2e54c75b-03e1-06db-53d9-d86a073675e2\instructions\instruction.liquid" />
|
||||
<None Remove="data\agents\2e54c75b-03e1-06db-53d9-d86a073675e2\responses\func.control_the_lights.0.liquid" />
|
||||
@@ -52,6 +53,9 @@
|
||||
<Content Include="data\agents\2e54c75b-03e1-06db-53d9-d86a073675e2\functions\control_the_lights.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\2e54c75b-03e1-06db-53d9-d86a073675e2\functions\custom_generate_image.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\2e54c75b-03e1-06db-53d9-d86a073675e2\functions\get_weather.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "工具助手",
|
||||
"description": "可以控制家电,查询天气,等一些功能。",
|
||||
"description": "可以控制家电,查询天气,生成图片等一些功能。",
|
||||
"createdDateTime": "2023-07-26T02:29:25.123224Z",
|
||||
"updatedDateTime": "2023-07-26T02:29:25.123274Z",
|
||||
"id": "2e54c75b-03e1-06db-53d9-d86a073675e2",
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "custom_generate_image",
|
||||
"description": "如果用户想生成图片可以调用此方法进行图片生成。",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"image_name": {
|
||||
"type": "string",
|
||||
"description": "根据用户描述给图片起个名称。"
|
||||
},
|
||||
"image_description": {
|
||||
"type": "string",
|
||||
"description": "用户进行的图片描述。"
|
||||
}
|
||||
},
|
||||
"required": [ "image_description" ]
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
你是一个工具助手,可以帮助用户打开家电,查询天气,等其他的一些工具功能。
|
||||
你是一个工具助手,可以帮助用户打开家电,查询天气,生成图片等其他的一些工具功能。
|
||||
|
||||
根据一下步骤进行操作:
|
||||
1: 如果用户一些需求,你需要询问用户是否需要相关帮助。
|
||||
2: 如果有查天气的需求,你就执行函数 get_weather。
|
||||
3: 如果有开灯的需求,你就执行函数 control_the_lights。
|
||||
3: 如果有开灯的需求,你就执行函数 control_the_lights。
|
||||
4: 如果有生成图片的需求,你就执行函数 custom_generate_image。
|
||||
|
||||
@@ -29,18 +29,33 @@
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="ImageTemplate" x:DataType="model:LingxiSpaceItemViewModel">
|
||||
<StackPanel>
|
||||
<TextBlock
|
||||
Margin="12,6,0,0"
|
||||
x:Phase="1"
|
||||
Style="{ThemeResource BaseTextBlockStyle}"
|
||||
Text="{x:Bind Name}" />
|
||||
<TextBlock
|
||||
Margin="12,0,0,6"
|
||||
x:Phase="2"
|
||||
Style="{ThemeResource BodyTextBlockStyle}"
|
||||
Text="{x:Bind Desc}" />
|
||||
</StackPanel>
|
||||
<Grid Margin="0,12,0,12">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" MinWidth="150" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image MaxHeight="100" Source="{x:Bind Desc}" />
|
||||
|
||||
<StackPanel Grid.Column="1" Margin="12,0,0,0">
|
||||
<TextBlock
|
||||
Margin="0,0,0,6"
|
||||
HorizontalAlignment="Left"
|
||||
FontSize="14"
|
||||
FontWeight="SemiBold"
|
||||
LineHeight="20"
|
||||
Style="{ThemeResource BaseTextBlockStyle}"
|
||||
Text="{x:Bind Name}" />
|
||||
<TextBlock
|
||||
Width="350"
|
||||
FontFamily="Segoe UI"
|
||||
FontWeight="Normal"
|
||||
MaxLines="1"
|
||||
Style="{ThemeResource BodyTextBlockStyle}"
|
||||
Text="{x:Bind Name}"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
</DataTemplate>
|
||||
<local:LingxiSpaceItemTemplateSelector
|
||||
x:Key="LingxiSpaceItemTemplateSelector"
|
||||
|
||||
Reference in New Issue
Block a user