mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-12-29 18:04:42 +08:00
feat(openai): 新增 NLP 相关接口
This commit is contained in:
@@ -102,5 +102,138 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
|
||||
return await client.SendRequestWithUrlEncodedAsync<Models.OpenApiNLPSensitiveResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/nlp/rank/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/nlp/rank.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiNLPRankResponse> ExecuteOpenApiNLPRankAsync(this WechatOpenAIClient client, Models.OpenApiNLPRankRequest 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, "openapi", "nlp", "rank", client.Credentials.Token!);
|
||||
|
||||
return await client.SendRequestWithUrlEncodedAsync<Models.OpenApiNLPRankResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/nlp/translate_en2cn/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/nlp/translate.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiNLPTranslateEnglish2ChineseResponse> ExecuteOpenApiNLPTranslateEnglish2ChineseAsync(this WechatOpenAIClient client, Models.OpenApiNLPTranslateEnglish2ChineseRequest 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, "openapi", "nlp", "translate_en2cn", client.Credentials.Token!);
|
||||
|
||||
return await client.SendRequestWithUrlEncodedAsync<Models.OpenApiNLPTranslateEnglish2ChineseResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/nlp/translate_cn2en/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/nlp/translate.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiNLPTranslateChinese2EnglishResponse> ExecuteOpenApiNLPTranslateChinese2EnglishAsync(this WechatOpenAIClient client, Models.OpenApiNLPTranslateChinese2EnglishRequest 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, "openapi", "nlp", "translate_cn2en", client.Credentials.Token!);
|
||||
|
||||
return await client.SendRequestWithUrlEncodedAsync<Models.OpenApiNLPTranslateChinese2EnglishResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/nlp/get_similar_query/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/nlp/similar_recommend.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiNLPGetSimilarQueryResponse> ExecuteOpenApiNLPGetSimilarQueryAsync(this WechatOpenAIClient client, Models.OpenApiNLPGetSimilarQueryRequest 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, "openapi", "nlp", "get_similar_query", client.Credentials.Token!);
|
||||
|
||||
return await client.SendRequestWithUrlEncodedAsync<Models.OpenApiNLPGetSimilarQueryResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/nlp/news-abstraction/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/nlp/summarize.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiNLPNewsAbstractionResponse> ExecuteOpenApiNLPNewsAbstractionAsync(this WechatOpenAIClient client, Models.OpenApiNLPNewsAbstractionRequest 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, "openapi", "nlp", "news-abstraction", client.Credentials.Token!);
|
||||
|
||||
return await client.SendRequestWithUrlEncodedAsync<Models.OpenApiNLPNewsAbstractionResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/nlp/document_classify/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/nlp/summarize.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiNLPDocumentClassifyResponse> ExecuteOpenApiNLPDocumentClassifyAsync(this WechatOpenAIClient client, Models.OpenApiNLPDocumentClassifyRequest 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, "openapi", "nlp", "document_classify", client.Credentials.Token!);
|
||||
|
||||
return await client.SendRequestWithUrlEncodedAsync<Models.OpenApiNLPDocumentClassifyResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/nlp/recommend_questions/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/nlp/rec_chat.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiNLPRecommendQuestionsResponse> ExecuteOpenApiNLPRecommendQuestionsAsync(this WechatOpenAIClient client, Models.OpenApiNLPRecommendQuestionsRequest 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, "openapi", "nlp", "recommend_questions", client.Credentials.Token!);
|
||||
|
||||
return await client.SendRequestWithUrlEncodedAsync<Models.OpenApiNLPRecommendQuestionsResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/document_classify/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPDocumentClassifyRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedUrlEncodedFormData
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置文章标题。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("title")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("title")]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置文章正文内容。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("content")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("content")]
|
||||
public string Content { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("uid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("uid")]
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置请求数据。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("data")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public Types.Data Data { get; set; } = new Types.Data();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/document_classify/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPDocumentClassifyResponse : WechatOpenAIResponse<OpenApiNLPDocumentClassifyResponse.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Result
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置一级分类结果。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("level1_cls")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("level1_cls")]
|
||||
public string Level1Classification { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置二级分类结果。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("level2_cls")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("level2_cls")]
|
||||
public string Level2Classification { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置三级分类结果。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("level3_cls")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("level3_cls")]
|
||||
public string Level3lassification { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置文章分类的结果。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("preds")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("preds")]
|
||||
public Types.Result Result { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/get_similar_query/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPGetSimilarQueryRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedUrlEncodedFormData
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置输入文本。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("query")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("query")]
|
||||
public string QueryString { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("uid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("uid")]
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置请求数据。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("data")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public Types.Data Data { get; set; } = new Types.Data();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/get_similar_query/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPGetSimilarQueryResponse : WechatOpenAIResponse<OpenApiNLPGetSimilarQueryResponse.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Result
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置相似问题信息项。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("question")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("question")]
|
||||
public string Sentiment { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置分值(范围:0~1)。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("score")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("score")]
|
||||
public double Score { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置来源。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("source")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("source")]
|
||||
public string Source { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置结果。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("data")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public Types.Result[] ResultList { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置耗时(单位:毫秒)。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("costime")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("costime")]
|
||||
public int CostTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/news-abstraction/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPNewsAbstractionRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedUrlEncodedFormData
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置新闻标题。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("title")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("title")]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置新闻正文内容。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("content")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("content")]
|
||||
public string Content { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置新闻所属的一级类别标签。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("category")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("category")]
|
||||
public string? Category { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置是否在提取摘要前先进行新闻分类标志。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("do_news_classify")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("do_news_classify")]
|
||||
public bool? RequireDoNewsClassify { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("uid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("uid")]
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置请求数据。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("data")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public Types.Data Data { get; set; } = new Types.Data();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/news-abstraction/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPNewsAbstractionResponse : WechatOpenAIResponse<OpenApiNLPNewsAbstractionResponse.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置摘要提取的结果。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("abstraction")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("abstraction")]
|
||||
public string Result { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置是否适合提取摘要的分类标签。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("classification")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("classification")]
|
||||
public bool HasClassification { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置分值(范围:0~1)。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("prob")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("prob")]
|
||||
public double Score { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/rank/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPRankRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedUrlEncodedFormData
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Candidate
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置候选词。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("text")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("text")]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置输入文本。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("query")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("query")]
|
||||
public string QueryString { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置候选词列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("candidates")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("candidates")]
|
||||
public IList<Types.Candidate> CandidateList { get; set; } = new List<Types.Candidate>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("uid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("uid")]
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置请求数据。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("data")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public Types.Data Data { get; set; } = new Types.Data();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/rank/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPRankResponse : WechatOpenAIResponse<OpenApiNLPRankResponse.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Result
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置候选词信息项。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("question")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("question")]
|
||||
public string Sentiment { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置分值(范围:0~1)。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("score")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("score")]
|
||||
public double Score { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置结果。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("results")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("results")]
|
||||
public Types.Result[] ResultList { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置是否有 Exact Match 候选。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("exact_match")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("exact_match")]
|
||||
public bool HasExactMatch { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/recommend_questions/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPRecommendQuestionsRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedUrlEncodedFormData
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("uid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("uid")]
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置请求数据。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("data")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public Types.Data Data { get; set; } = new Types.Data();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/recommend_questions/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPRecommendQuestionsResponse : WechatOpenAIResponse<OpenApiNLPRecommendQuestionsResponse.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置推荐的结果。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("results")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("results")]
|
||||
public string[] ResultList { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/translate_cn2en/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPTranslateChinese2EnglishRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedUrlEncodedFormData
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置输入文本。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("q")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("q")]
|
||||
public string QueryString { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("uid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("uid")]
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置请求数据。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("data")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public Types.Data Data { get; set; } = new Types.Data();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/translate_cn2en/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPTranslateChinese2EnglishResponse : WechatOpenAIResponse<OpenApiNLPTranslateChinese2EnglishResponse.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置结果。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("result")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("result")]
|
||||
public string Result { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/translate_en2cn/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPTranslateEnglish2ChineseRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedUrlEncodedFormData
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置输入文本。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("q")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("q")]
|
||||
public string QueryString { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("uid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("uid")]
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置请求数据。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("data")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public Types.Data Data { get; set; } = new Types.Data();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/nlp/translate_en2cn/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiNLPTranslateEnglish2ChineseResponse : WechatOpenAIResponse<OpenApiNLPTranslateEnglish2ChineseResponse.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置结果。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("result")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("result")]
|
||||
public string Result { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
|
||||
Credentials = new Settings.Credentials(options);
|
||||
|
||||
FlurlClient.BaseUrl = options.Endpoints ?? WechatOpenAIEndpoints.DEFAULT;
|
||||
FlurlClient.BaseUrl = options.Endpoints ?? WechatOpenAIEndpoints.PLATFORM;
|
||||
FlurlClient.WithTimeout(TimeSpan.FromMilliseconds(options.Timeout));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置微微信智能对话 API 域名。
|
||||
/// <para>默认值:<see cref="WechatOpenAIEndpoints.DEFAULT"/></para>
|
||||
/// <para>默认值:<see cref="WechatOpenAIEndpoints.PLATFORM"/></para>
|
||||
/// </summary>
|
||||
public string Endpoints { get; set; } = WechatOpenAIEndpoints.DEFAULT;
|
||||
public string Endpoints { get; set; } = WechatOpenAIEndpoints.PLATFORM;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置微信智能对话 ClientId。仅限第三方平台接入时使用。
|
||||
|
||||
@@ -8,8 +8,13 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
public static class WechatOpenAIEndpoints
|
||||
{
|
||||
/// <summary>
|
||||
/// 主域名(默认)。
|
||||
/// 平台接入(默认)。
|
||||
/// </summary>
|
||||
public const string DEFAULT = "https://openaiapi.weixin.qq.com";
|
||||
public const string PLATFORM = "https://openai.weixin.qq.com";
|
||||
|
||||
/// <summary>
|
||||
/// 第三方接入。
|
||||
/// </summary>
|
||||
public const string THIRDPARTY = "https://openaiapi.weixin.qq.com";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,18 +30,11 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
public byte[] RawBytes { get; internal set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取微信智能对话 API 返回的错误码。
|
||||
/// 获取微信智能对话 API 返回的请求唯一标识。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("errcode")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("errcode")]
|
||||
public virtual int? ErrorCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取微信智能对话 API 返回的错误信息。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("errmsg")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("errmsg")]
|
||||
public virtual string? ErrorMessage { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("request_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("request_id")]
|
||||
public virtual string? RequestId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取微信智能对话 API 返回的状态码。
|
||||
@@ -58,19 +51,44 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
public virtual string? Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取微信智能对话 API 返回的请求唯一标识。
|
||||
/// 获取微信智能对话 API 返回的错误码。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("request_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("request_id")]
|
||||
public virtual string? RequestId { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("errcode")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("errcode")]
|
||||
public virtual int? ErrorCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个值,该值指示调用微信 API 是否成功(即 HTTP 状态码为 200、且 code 和 errcode 值都为 0)。
|
||||
/// 获取微信智能对话 API 返回的错误信息。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("errmsg")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("errmsg")]
|
||||
public virtual string? ErrorMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取微信智能对话 API 返回的错误码。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("ret")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("ret")]
|
||||
public virtual int? ReturnCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取微信智能对话 API 返回的错误信息。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("error")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("error")]
|
||||
public virtual string? ReturnError { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个值,该值指示调用微信 API 是否成功(即 HTTP 状态码为 200、且 code/errcode/ret 值都为 0)。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual bool IsSuccessful()
|
||||
{
|
||||
return RawStatus == 200 && ErrorCode.GetValueOrDefault() == 0 && Code.GetValueOrDefault() == 0;
|
||||
return RawStatus == 200 &&
|
||||
Code.GetValueOrDefault() == 0 &&
|
||||
ErrorCode.GetValueOrDefault() == 0 &&
|
||||
ReturnCode.GetValueOrDefault() == 0 &&
|
||||
string.IsNullOrEmpty(ReturnError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user