2025-05-06 17:04:03 +08:00

54 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Flurl;
using Flurl.Http;
using ModelContextProtocol.Server;
using System.ComponentModel;
namespace lazy52API.Tool
{
[McpServerToolType]
public static class Painting
{
/// <summary>
/// 调用豆包绘图接口
/// </summary>
/// <returns></returns>
[McpServerTool(Name = "DouBaoPainting"), Description("调用豆包绘图接口;输出image_url数组(一般是四个)")]
public static string DouBao(
[Description("要生成图片的描述")] string description,
[Description("绘画风格")] string type,
[Description("绘画比例可选9:162:33:44:31:13:216:9。不填默认16:9")] string ratio = "16:9"
)
{
Console.WriteLine($"接收到绘图任务:{description}");
var Painting = new
{
description,
type,
ratio
};
var filteredPainting = new System.Collections.Generic.Dictionary<string, object>();
foreach (var prop in Painting.GetType().GetProperties())
{
var value = prop.GetValue(Painting);
if (value != null)
{
filteredPainting[prop.Name] = value;
}
}
var request = new FlurlRequest("https://npi.lazy52.com/api/doubao")
.WithTimeout(Timeout.InfiniteTimeSpan);
var response = request
.SetQueryParams(filteredPainting).GetAsync().GetAwaiter().GetResult();
if (response != null)
{
var responseString = response.GetStringAsync().GetAwaiter().GetResult();
//JToken rootToken = JToken.Parse(responseString);
//var resultPath = "$.image_url[*]";
//IEnumerable<JToken> resultTokens = rootToken.SelectTokens(resultPath);
return responseString;
}
return "";
}
}
}