mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-12-29 18:04:42 +08:00
feat(openai): 新增语义槽相关接口
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl;
|
||||
using Flurl.Http;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
{
|
||||
public static class WechatOpenAIClientExecuteSlotExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /v2/slot/save 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/openapi/api/v2/slot/save.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.SlotSaveResponse> ExecuteSlotSaveAsync(this WechatOpenAIClient client, Models.SlotSaveRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "v2", "slot", "save");
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.SlotSaveResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /v2/slot/get_list 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/openapi/api/v2/slot/get_list.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.SlotGetListResponse> ExecuteSlotGetListAsync(this WechatOpenAIClient client, Models.SlotGetListRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "v2", "slot", "get_list");
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.SlotGetListResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /v2/slot/delete 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/openapi/api/v2/slot/delete.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.SlotDeleteResponse> ExecuteSlotDeleteAsync(this WechatOpenAIClient client, Models.SlotDeleteRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "v2", "slot", "delete");
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.SlotDeleteResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/slot/delete 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class SlotDeleteRequest : WechatOpenAIRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置语义槽 ID 列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("id_list")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("id_list")]
|
||||
public IList<long> SlotIdList { get; set; } = new List<long>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置意图 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("intent_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("intent_id")]
|
||||
public long? IntentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置是否删除语义槽。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("auto_delete_slot")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("auto_delete_slot")]
|
||||
public bool? AutoDeleteSlot { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/slot/delete 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class SlotDeleteResponse : WechatOpenAIResponse
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/slot/get_list 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class SlotGetListRequest : WechatOpenAIRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置意图 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("intent_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("intent_id")]
|
||||
public long? IntentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置语义槽类型。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("type")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("type")]
|
||||
public int? SlotType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置分页页数。
|
||||
/// <para>默认值:1</para>
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("page")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("page")]
|
||||
public int Page { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置分页每页数量。
|
||||
/// <para>默认值:10</para>
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("size")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("size")]
|
||||
public int Limit { get; set; } = 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/slot/get_list 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class SlotGetListResponse : WechatOpenAIResponse<SlotGetListResponse.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Slot
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置语义槽 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("id")]
|
||||
public long SlotId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置语义槽名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("name")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("name")]
|
||||
public string Name { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置语义槽类型。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("type")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("type")]
|
||||
public int SlotType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置词典名称列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("dicts")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("dicts")]
|
||||
public string[] DictionaryNameList { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置追问话术列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("ask_content")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("ask_content")]
|
||||
public string[] AskContentList { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置语义槽列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("list")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("list")]
|
||||
public Types.Slot[] SlotList { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置语义槽总数量。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("count")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("count")]
|
||||
public int TotalCount { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/slot/save 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class SlotSaveRequest : WechatOpenAIRequest
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Slot
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置语义槽 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("id")]
|
||||
public long? SlotId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置语义槽名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("name")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("name")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置词典名称列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("dicts")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("dicts")]
|
||||
public IList<string> DictionaryNameList { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置追问话术列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("ask_content")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("ask_content")]
|
||||
public IList<string> AskContentList { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置关联的意图 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("intent_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("intent_id")]
|
||||
public long? IntentId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置语义槽列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("data")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public IList<Types.Slot> SlotList { get; set; } = new List<Types.Slot>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/slot/save 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class SlotSaveResponse : WechatOpenAIResponse<SlotSaveResponse.Types.Slot[]>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Slot
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置语义槽 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("id")]
|
||||
public long SlotId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置语义槽名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("name")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("name")]
|
||||
public string Name { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
/// 表示微信智能对话 API 响应的泛型基类。
|
||||
/// </summary>
|
||||
public abstract class WechatOpenAIResponse<TData> : WechatOpenAIResponse
|
||||
where TData : class, new()
|
||||
where TData : class
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取微信智能对话 API 返回的数据。
|
||||
|
||||
Reference in New Issue
Block a user