diff --git a/src/SKIT.FlurlHttpClient.Wechat.OpenAI/Extensions/WechatOpenAIClientExecuteAsyncExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.OpenAI/Extensions/WechatOpenAIClientExecuteAsyncExtensions.cs new file mode 100644 index 00000000..7658afec --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.OpenAI/Extensions/WechatOpenAIClientExecuteAsyncExtensions.cs @@ -0,0 +1,34 @@ +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 WechatOpenAIClientExecuteAsyncExtensions + { + /// + /// 异步调用 [GET] /v1/async/fetch 接口。 + /// REF: https://developers.weixin.qq.com/doc/aispeech/openapi/api/v1/task_fetch.html + /// + /// + /// + /// + /// + public static async Task ExecuteAsyncFetchAsync(this WechatOpenAIClient client, Models.AsyncFetchRequest 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.Get, "v1", "async", "fetch") + .SetQueryParam("task_id", request.TaskId); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.OpenAI/Models/Async/AsyncFetchRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.OpenAI/Models/Async/AsyncFetchRequest.cs new file mode 100644 index 00000000..5a4f03f8 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.OpenAI/Models/Async/AsyncFetchRequest.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models +{ + /// + /// 表示 [GET] /v1/async/fetch 接口的请求。 + /// + public class AsyncFetchRequest : WechatOpenAIRequest + { + /// + /// 获取或设置任务 ID。 + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + public string TaskId { get; set; } = string.Empty; + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.OpenAI/Models/Async/AsyncFetchResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.OpenAI/Models/Async/AsyncFetchResponse.cs new file mode 100644 index 00000000..e3fc6edc --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.OpenAI/Models/Async/AsyncFetchResponse.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models +{ + /// + /// 表示 [GET] /v1/async/fetch 接口的响应。 + /// + public class AsyncFetchResponse : WechatOpenAIResponse + { + public static class Types + { + public class Data + { + /// + /// 获取或设置任务状态。 + /// + [Newtonsoft.Json.JsonProperty("state")] + [System.Text.Json.Serialization.JsonPropertyName("state")] + public int State { get; set; } + + /// + /// 获取或设置任务进度。 + /// + [Newtonsoft.Json.JsonProperty("progress")] + [System.Text.Json.Serialization.JsonPropertyName("progress")] + public string Progress { get; set; } = default!; + + /// + /// 获取或设置任务耗时。 + /// + [Newtonsoft.Json.JsonProperty("cost")] + [System.Text.Json.Serialization.JsonPropertyName("cost")] + public string Cost { get; set; } = default!; + + /// + /// 获取或设置导出任务的下载链接。 + /// + [Newtonsoft.Json.JsonProperty("url")] + [System.Text.Json.Serialization.JsonPropertyName("url")] + public string? Url { get; set; } + + /// + /// 获取或设置接口访问令牌。 + /// + [Newtonsoft.Json.JsonProperty("success_skill_info")] + [System.Text.Json.Serialization.JsonPropertyName("success_skill_info")] + public IDictionary? SuccessSkillMap { get; set; } + } + } + } +} diff --git a/test/SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests/ModelSamples/Async/AsyncFetchRequest.json b/test/SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests/ModelSamples/Async/AsyncFetchRequest.json new file mode 100644 index 00000000..22fdca1b --- /dev/null +++ b/test/SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests/ModelSamples/Async/AsyncFetchRequest.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests/ModelSamples/Async/AsyncFetchResponse.json b/test/SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests/ModelSamples/Async/AsyncFetchResponse.json new file mode 100644 index 00000000..fbbab33e --- /dev/null +++ b/test/SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests/ModelSamples/Async/AsyncFetchResponse.json @@ -0,0 +1,10 @@ +{ + "code": 0, + "msg": "", + "data": { + "cost": "22496769ms", + "progress": "100/100", + "state": 2, + "url": "http://openai-75050.gzc.vod.tencent-cloud.com/40238_knowledge1588562918359.csv" + } +} \ No newline at end of file