feat(openai): 新增技能相关接口

This commit is contained in:
Fu Diwei
2021-10-08 15:42:28 +08:00
parent f54b655efc
commit 3e63bdd247
19 changed files with 690 additions and 2 deletions

View File

@@ -0,0 +1,90 @@
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 WechatOpenAIClientExecuteSkillExtensions
{
/// <summary>
/// <para>异步调用 [POST] /v2/skill/save 接口。</para>
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/openapi/api/v2/skill/save.html </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.SkillSaveResponse> ExecuteSkillSaveAsync(this WechatOpenAIClient client, Models.SkillSaveRequest 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", "skill", "save");
return await client.SendRequestWithJsonAsync<Models.SkillSaveResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [POST] /v2/skill/get_list 接口。</para>
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/openapi/api/v2/skill/get_list.html </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.SkillGetListResponse> ExecuteSkillGetListAsync(this WechatOpenAIClient client, Models.SkillGetListRequest 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", "skill", "get_list");
return await client.SendRequestWithJsonAsync<Models.SkillGetListResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [POST] /v2/skill/get_detail 接口。</para>
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/openapi/api/v2/skill/get_detail.html </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.SkillGetDetailResponse> ExecuteSkillGetDetailAsync(this WechatOpenAIClient client, Models.SkillGetDetailRequest 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", "skill", "get_detail");
return await client.SendRequestWithJsonAsync<Models.SkillGetDetailResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [POST] /v2/skill/delete 接口。</para>
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/openapi/api/v2/skill/delete.html </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.SkillDeleteResponse> ExecuteSkillDeleteAsync(this WechatOpenAIClient client, Models.SkillDeleteRequest 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", "skill", "delete");
return await client.SendRequestWithJsonAsync<Models.SkillDeleteResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
{
/// <summary>
/// <para>表示 [POST] /v2/skill/delete 接口的请求。</para>
/// </summary>
public class SkillDeleteRequest : WechatOpenAIRequest
{
/// <summary>
/// 获取或设置技能 ID 列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public IList<long> SkillIdList { get; set; } = new List<long>();
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
{
/// <summary>
/// <para>表示 [POST] /v2/skill/delete 接口的响应。</para>
/// </summary>
public class SkillDeleteResponse : WechatOpenAIResponse
{
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
{
/// <summary>
/// <para>表示 [POST] /v2/skill/get_detail 接口的请求。</para>
/// </summary>
public class SkillGetDetailRequest : WechatOpenAIRequest
{
/// <summary>
/// 获取或设置关键字。
/// </summary>
[Newtonsoft.Json.JsonProperty("keyword")]
[System.Text.Json.Serialization.JsonPropertyName("keyword")]
public string? Keyword { get; set; }
/// <summary>
/// 获取或设置技能 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("skill_id")]
[System.Text.Json.Serialization.JsonPropertyName("skill_id")]
public long SkillId { 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;
}
}

View File

@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
{
/// <summary>
/// <para>表示 [POST] /v2/skill/get_detail 接口的响应。</para>
/// </summary>
public class SkillGetDetailResponse : WechatOpenAIResponse<SkillGetDetailResponse.Types.Data>
{
public static class Types
{
public class Data
{
public static class Types
{
public class Skill : SkillGetListResponse.Types.Data.Types.Skill
{
/// <summary>
/// 获取或设置技能开关。
/// </summary>
[Newtonsoft.Json.JsonProperty("switch")]
[System.Text.Json.Serialization.JsonPropertyName("switch")]
public bool Switch { get; set; }
}
public class IntentItem
{
/// <summary>
/// 获取或设置意图 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public long IntentId { get; set; }
/// <summary>
/// 获取或设置意图名称。
/// </summary>
[Newtonsoft.Json.JsonProperty("name")]
[System.Text.Json.Serialization.JsonPropertyName("name")]
public string Name { get; set; } = default!;
/// <summary>
/// 获取或设置技能 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("skill_id")]
[System.Text.Json.Serialization.JsonPropertyName("skill_id")]
public long SkillId { get; set; }
/// <summary>
/// 获取或设置优先级。
/// </summary>
[Newtonsoft.Json.JsonProperty("rank_level")]
[System.Text.Json.Serialization.JsonPropertyName("rank_level")]
public double RankLevel { get; set; }
/// <summary>
/// 获取或设置相似度。
/// </summary>
[Newtonsoft.Json.JsonProperty("threshold")]
[System.Text.Json.Serialization.JsonPropertyName("threshold")]
public double Threshold { get; set; }
/// <summary>
/// 获取或设置意图开关。
/// </summary>
[Newtonsoft.Json.JsonProperty("switch")]
[System.Text.Json.Serialization.JsonPropertyName("switch")]
public bool Switch { get; set; }
/// <summary>
/// 获取或设置创建时间戳。
/// </summary>
[Newtonsoft.Json.JsonProperty("created_time")]
[System.Text.Json.Serialization.JsonPropertyName("created_time")]
public long CreateTimestamp { get; set; }
/// <summary>
/// 获取或设置修改时间戳。
/// </summary>
[Newtonsoft.Json.JsonProperty("updated_time")]
[System.Text.Json.Serialization.JsonPropertyName("updated_time")]
public long UpdateTimestamp { get; set; }
}
public class IntentList
{
/// <summary>
/// 获取或设置意图列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("list")]
[System.Text.Json.Serialization.JsonPropertyName("list")]
public IntentItem[] Items { get; set; } = default!;
/// <summary>
/// 获取或设置意图数量。
/// </summary>
[Newtonsoft.Json.JsonProperty("count")]
[System.Text.Json.Serialization.JsonPropertyName("count")]
public int Count { get; set; }
}
}
/// <summary>
/// 获取或设置技能信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("skill")]
[System.Text.Json.Serialization.JsonPropertyName("skill")]
public Types.Skill Skill { get; set; } = default!;
/// <summary>
/// 获取或设置意图列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("intents")]
[System.Text.Json.Serialization.JsonPropertyName("intents")]
public Types.IntentList IntentList { get; set; } = default!;
}
}
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
{
/// <summary>
/// <para>表示 [POST] /v2/skill/get_list 接口的请求。</para>
/// </summary>
public class SkillGetListRequest : WechatOpenAIRequest
{
/// <summary>
/// 获取或设置关键字。
/// </summary>
[Newtonsoft.Json.JsonProperty("keyword")]
[System.Text.Json.Serialization.JsonPropertyName("keyword")]
public string? Keyword { get; set; }
/// <summary>
/// 获取或设置技能类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("skill_type")]
[System.Text.Json.Serialization.JsonPropertyName("skill_type")]
public int? SkillType { 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;
}
}

View File

@@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
{
/// <summary>
/// <para>表示 [POST] /v2/skill/get_list 接口的响应。</para>
/// </summary>
public class SkillGetListResponse : WechatOpenAIResponse<SkillGetListResponse.Types.Data>
{
public static class Types
{
public class Data
{
public static class Types
{
public class Skill
{
/// <summary>
/// 获取或设置技能 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public long SkillId { 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 SkillType { get; set; }
/// <summary>
/// 获取或设置意图数量。
/// </summary>
[Newtonsoft.Json.JsonProperty("intent_count")]
[System.Text.Json.Serialization.JsonPropertyName("intent_count")]
public int IntentCount { get; set; }
/// <summary>
/// 获取或设置未配置回答的意图数量。
/// </summary>
[Newtonsoft.Json.JsonProperty("no_answer_intent_count")]
[System.Text.Json.Serialization.JsonPropertyName("no_answer_intent_count")]
public int NoAnswerIntentCount { get; set; }
/// <summary>
/// 获取或设置场景存活的最大轮数。
/// </summary>
[Newtonsoft.Json.JsonProperty("max_round")]
[System.Text.Json.Serialization.JsonPropertyName("max_round")]
public int MaxRound { get; set; }
/// <summary>
/// 获取或设置唤醒开关。
/// </summary>
[Newtonsoft.Json.JsonProperty("wake_open")]
[System.Text.Json.Serialization.JsonPropertyName("wake_open")]
public bool WakeSwitch { get; set; }
/// <summary>
/// 获取或设置唤醒热词。
/// </summary>
[Newtonsoft.Json.JsonProperty("awaken_word")]
[System.Text.Json.Serialization.JsonPropertyName("awaken_word")]
public string? AwakeWord { get; set; }
/// <summary>
/// 获取或设置唤醒的回复语句列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("awaken_answer")]
[System.Text.Json.Serialization.JsonPropertyName("awaken_answer")]
public string[]? AwakeAnswerList { get; set; }
/// <summary>
/// 获取或设置退出热词。
/// </summary>
[Newtonsoft.Json.JsonProperty("exist_word")]
[System.Text.Json.Serialization.JsonPropertyName("exist_word")]
public string? ExistWord { get; set; }
/// <summary>
/// 获取或设置退出的回复语句列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("exist_answer")]
[System.Text.Json.Serialization.JsonPropertyName("exist_answer")]
public string[]? ExitAnswerList { get; set; }
/// <summary>
/// 获取或设置取消意图操作。
/// </summary>
[Newtonsoft.Json.JsonProperty("cancel_intent_operation")]
[System.Text.Json.Serialization.JsonPropertyName("cancel_intent_operation")]
public bool CancelIntentOperation { get; set; }
/// <summary>
/// 获取或设置取消操作的回复列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("cancel_answer")]
[System.Text.Json.Serialization.JsonPropertyName("cancel_answer")]
public string[]? CancelAnswerList { get; set; }
/// <summary>
/// 获取或设置没有可取消意图时的回复列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("no_cancel_answer")]
[System.Text.Json.Serialization.JsonPropertyName("no_cancel_answer")]
public string[]? NoCancelAnswerList { get; set; }
}
}
/// <summary>
/// 获取或设置技能列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("list")]
[System.Text.Json.Serialization.JsonPropertyName("list")]
public Types.Skill[] SkillList { get; set; } = default!;
/// <summary>
/// 获取或设置技能总数量。
/// </summary>
[Newtonsoft.Json.JsonProperty("count")]
[System.Text.Json.Serialization.JsonPropertyName("count")]
public int TotalCount { get; set; }
}
}
}
}

View File

@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
{
/// <summary>
/// <para>表示 [POST] /v2/skill/save 接口的请求。</para>
/// </summary>
public class SkillSaveRequest : WechatOpenAIRequest
{
/// <summary>
/// 获取或设置技能 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public long? SkillId { 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("type")]
[System.Text.Json.Serialization.JsonPropertyName("type")]
public int? SkillType { get; set; }
/// <summary>
/// 获取或设置场景存活的最大轮数。
/// </summary>
[Newtonsoft.Json.JsonProperty("max_round")]
[System.Text.Json.Serialization.JsonPropertyName("max_round")]
public int? MaxRound { get; set; }
/// <summary>
/// 获取或设置唤醒开关。
/// </summary>
[Newtonsoft.Json.JsonProperty("wake_open")]
[System.Text.Json.Serialization.JsonPropertyName("wake_open")]
public bool? WakeSwitch { get; set; }
/// <summary>
/// 获取或设置唤醒热词。
/// </summary>
[Newtonsoft.Json.JsonProperty("awaken_word")]
[System.Text.Json.Serialization.JsonPropertyName("awaken_word")]
public string? AwakeWord { get; set; }
/// <summary>
/// 获取或设置唤醒的回复语句列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("awaken_answer")]
[System.Text.Json.Serialization.JsonPropertyName("awaken_answer")]
public IList<string>? AwakeAnswerList { get; set; }
/// <summary>
/// 获取或设置退出热词。
/// </summary>
[Newtonsoft.Json.JsonProperty("exist_word")]
[System.Text.Json.Serialization.JsonPropertyName("exist_word")]
public string? ExistWord { get; set; }
/// <summary>
/// 获取或设置退出的回复语句列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("exist_answer")]
[System.Text.Json.Serialization.JsonPropertyName("exist_answer")]
public IList<string>? ExitAnswerList { get; set; }
/// <summary>
/// 获取或设置取消意图操作。
/// </summary>
[Newtonsoft.Json.JsonProperty("cancel_intent_operation")]
[System.Text.Json.Serialization.JsonPropertyName("cancel_intent_operation")]
public bool? CancelIntentOperation { get; set; }
/// <summary>
/// 获取或设置取消操作的回复列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("cancel_answer")]
[System.Text.Json.Serialization.JsonPropertyName("cancel_answer")]
public IList<string>? CancelAnswerList { get; set; }
/// <summary>
/// 获取或设置没有可取消意图时的回复列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("no_cancel_answer")]
[System.Text.Json.Serialization.JsonPropertyName("no_cancel_answer")]
public IList<string>? NoCancelAnswerList { get; set; }
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
{
/// <summary>
/// <para>表示 [POST] /v2/skill/save 接口的响应。</para>
/// </summary>
public class SkillSaveResponse : WechatOpenAIResponse<SkillSaveResponse.Types.Data>
{
public static class Types
{
public class Data
{
/// <summary>
/// 获取或设置技能 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public long SkillId { get; set; } = default!;
}
}
}
}

View File

@@ -20,7 +20,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
/// </summary>
[Newtonsoft.Json.JsonProperty("class_id")]
[System.Text.Json.Serialization.JsonPropertyName("class_id")]
public int ClassId { get; set; }
public long ClassId { get; set; }
/// <summary>
/// 获取或设置排序方式。

View File

@@ -21,7 +21,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public int ClassId { get; set; }
public long ClassId { get; set; }
/// <summary>
/// 获取或设置话术名称。