diff --git a/sample/Cnblogs.DashScope.Sample/Multimodal/OcrKeyInformationExtractionSample.cs b/sample/Cnblogs.DashScope.Sample/Multimodal/OcrKeyInformationExtractionSample.cs index f8507ad..e1ab7e7 100644 --- a/sample/Cnblogs.DashScope.Sample/Multimodal/OcrKeyInformationExtractionSample.cs +++ b/sample/Cnblogs.DashScope.Sample/Multimodal/OcrKeyInformationExtractionSample.cs @@ -64,7 +64,7 @@ public async Task RunAsync(IDashScopeClient client) } } -internal class ReceiptModel() +internal class ReceiptModel { [JsonPropertyName("乘车日期")] public string? Date { get; init; } diff --git a/src/Cnblogs.DashScope.AI/DashScopeChatClient.cs b/src/Cnblogs.DashScope.AI/DashScopeChatClient.cs index c8a0d0f..ab0007c 100644 --- a/src/Cnblogs.DashScope.AI/DashScopeChatClient.cs +++ b/src/Cnblogs.DashScope.AI/DashScopeChatClient.cs @@ -29,8 +29,8 @@ private static readonly TextGenerationParameters /// public DashScopeChatClient(IDashScopeClient dashScopeClient, string modelId) { - ArgumentNullException.ThrowIfNull(dashScopeClient, nameof(dashScopeClient)); - ArgumentNullException.ThrowIfNull(modelId, nameof(modelId)); + ArgumentNullException.ThrowIfNull(dashScopeClient); + ArgumentNullException.ThrowIfNull(modelId); _dashScopeClient = dashScopeClient; _modelId = modelId; diff --git a/src/Cnblogs.DashScope.AI/DashScopeTextEmbeddingGenerator.cs b/src/Cnblogs.DashScope.AI/DashScopeTextEmbeddingGenerator.cs index f735844..6c5209c 100644 --- a/src/Cnblogs.DashScope.AI/DashScopeTextEmbeddingGenerator.cs +++ b/src/Cnblogs.DashScope.AI/DashScopeTextEmbeddingGenerator.cs @@ -23,8 +23,8 @@ public sealed class DashScopeTextEmbeddingGenerator /// The number of dimensions produced by the generator. public DashScopeTextEmbeddingGenerator(IDashScopeClient dashScopeClient, string modelId, int? dimensions = null) { - ArgumentNullException.ThrowIfNull(dashScopeClient, nameof(dashScopeClient)); - ArgumentNullException.ThrowIfNull(modelId, nameof(modelId)); + ArgumentNullException.ThrowIfNull(dashScopeClient); + ArgumentNullException.ThrowIfNull(modelId); _dashScopeClient = dashScopeClient; _modelId = modelId; diff --git a/src/Cnblogs.DashScope.Sdk/DeepSeek/DeepSeekLlm.cs b/src/Cnblogs.DashScope.Sdk/DeepSeek/DeepSeekLlm.cs deleted file mode 100644 index b5ce953..0000000 --- a/src/Cnblogs.DashScope.Sdk/DeepSeek/DeepSeekLlm.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Cnblogs.DashScope.Sdk.DeepSeek; - -/// -/// DeepSeek models. -/// -public enum DeepSeekLlm -{ - /// - /// deepseek-v3 model. - /// - DeepSeekV3 = 1, - - /// - /// deepseek-r1 model. - /// - DeepSeekR1 = 2 -} diff --git a/src/Cnblogs.DashScope.Sdk/DeepSeek/DeepSeekLlmName.cs b/src/Cnblogs.DashScope.Sdk/DeepSeek/DeepSeekLlmName.cs deleted file mode 100644 index f0c8bfa..0000000 --- a/src/Cnblogs.DashScope.Sdk/DeepSeek/DeepSeekLlmName.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Cnblogs.DashScope.Sdk.DeepSeek; - -internal static class DeepSeekLlmName -{ - public static string GetModelName(this DeepSeekLlm model) - { - return model switch - { - DeepSeekLlm.DeepSeekR1 => "deepseek-r1", - DeepSeekLlm.DeepSeekV3 => "deepseek-v3", - _ => ThrowHelper.UnknownModelName(nameof(model), model) - }; - } -} diff --git a/src/Cnblogs.DashScope.Sdk/DeepSeek/DeepSeekTextGenerationApi.cs b/src/Cnblogs.DashScope.Sdk/DeepSeek/DeepSeekTextGenerationApi.cs deleted file mode 100644 index a3002db..0000000 --- a/src/Cnblogs.DashScope.Sdk/DeepSeek/DeepSeekTextGenerationApi.cs +++ /dev/null @@ -1,156 +0,0 @@ -using Cnblogs.DashScope.Core; - -namespace Cnblogs.DashScope.Sdk.DeepSeek; - -/// -/// Extensions for calling DeepSeek models, see: https://help.aliyun.com/zh/model-studio/developer-reference/deepseek -/// -[Obsolete("Use generic GetTextStreamCompletionAsync instead")] -public static class DeepSeekTextGenerationApi -{ - private static TextGenerationParameters StreamingParameters { get; } = new() { IncrementalOutput = true }; - - /// - /// Get text completion from deepseek model. - /// - /// The . - /// The model name. - /// The context messages. - /// - /// - /// Migrate from - /// - /// client.GetDeepSeekChatCompletionAsync(DeepSeekLlm.DeepSeekV3, messages); - /// - /// to - /// - /// client.GetTextCompletionAsync( - /// new ModelRequest<TextGenerationInput, ITextGenerationParameters> - /// { - /// Model = "deepseek-v3", - /// Input = new TextGenerationInput { Messages = messages }, - /// Parameters = StreamingParameters - /// }); - /// - /// - [Obsolete("Use GetTextCompletionAsync() instead, check remarks section.")] - public static async Task> - GetDeepSeekChatCompletionAsync( - this IDashScopeClient client, - DeepSeekLlm model, - IEnumerable messages) - { - return await client.GetDeepSeekChatCompletionAsync(model.GetModelName(), messages); - } - - /// - /// Get text completion from deepseek model. - /// - /// The . - /// The model name. - /// The context messages. - /// - /// - /// Migrate from - /// - /// client.GetDeepSeekChatCompletionAsync(model, messages); - /// - /// to - /// - /// client.GetTextCompletionAsync( - /// new ModelRequest<TextGenerationInput, ITextGenerationParameters> - /// { - /// Model = model, - /// Input = new TextGenerationInput { Messages = messages }, - /// Parameters = StreamingParameters - /// }); - /// - /// - [Obsolete("Use GetTextCompletionAsync() instead, check remarks section.")] - public static async Task> - GetDeepSeekChatCompletionAsync( - this IDashScopeClient client, - string model, - IEnumerable messages) - { - return await client.GetTextCompletionAsync( - new ModelRequest - { - Model = model, - Input = new TextGenerationInput { Messages = messages }, - Parameters = null - }); - } - - /// - /// Get streamed completion from deepseek model. - /// - /// - /// - /// - /// - /// - /// Migrate from - /// - /// client.GetDeepSeekChatCompletionStreamAsync(DeepSeekLlm.DeepSeekV3, messages); - /// - /// to - /// - /// client.GetTextCompletionStreamAsync( - /// new ModelRequest<TextGenerationInput, ITextGenerationParameters> - /// { - /// Model = "deepseek-v3", - /// Input = new TextGenerationInput { Messages = messages }, - /// Parameters = StreamingParameters - /// }); - /// - /// - [Obsolete("Use GetTextCompletionStreamAsync() instead, check remarks section.")] - public static IAsyncEnumerable> - GetDeepSeekChatCompletionStreamAsync( - this IDashScopeClient client, - DeepSeekLlm model, - IEnumerable messages) - { - return client.GetDeepSeekChatCompletionStreamAsync(model.GetModelName(), messages); - } - - /// - /// Get streamed completion from deepseek model. - /// - /// - /// - /// - /// - /// - /// Migrate from - /// - /// client.GetDeepSeekChatCompletionStreamAsync(model, messages); - /// - /// to - /// - /// client.GetTextCompletionStreamAsync( - /// new ModelRequest<TextGenerationInput, ITextGenerationParameters> - /// { - /// Model = model, - /// Input = new TextGenerationInput { Messages = messages }, - /// Parameters = StreamingParameters - /// }); - /// - /// - [Obsolete("Use GetTextCompletionStreamAsync() instead, check remarks section.")] - public static IAsyncEnumerable> - GetDeepSeekChatCompletionStreamAsync( - this IDashScopeClient client, - string model, - IEnumerable messages) - { - return client.GetTextCompletionStreamAsync( - new ModelRequest - { - Model = model, - Input = new TextGenerationInput { Messages = messages }, - Parameters = StreamingParameters - }); - } -} diff --git a/src/Cnblogs.DashScope.Sdk/QWen/QWenLlm.cs b/src/Cnblogs.DashScope.Sdk/QWen/QWenLlm.cs deleted file mode 100644 index 99beadd..0000000 --- a/src/Cnblogs.DashScope.Sdk/QWen/QWenLlm.cs +++ /dev/null @@ -1,142 +0,0 @@ -namespace Cnblogs.DashScope.Sdk.QWen; - -/// -/// Available models for QWen. -/// -public enum QWenLlm -{ - /// - /// qwen-turbo, input token limit is 6k. - /// - QWenTurbo = 1, - - /// - /// qwen-plus, input token limit is 30k. - /// - QWenPlus = 2, - - /// - /// qwen-max, input token limit is 6k. - /// - QWenMax = 3, - - /// - /// qwen-max-1201, snapshot version of qwen-max, input token limit is 6k. - /// - QWenMax1201 = 4, - - /// - /// qwen-max-longcontext, input token limit is 28k. - /// - QWenMaxLongContext = 5, - - /// - /// qwen1.5-72b-chat, input token limit is 30k. - /// - // ReSharper disable once InconsistentNaming - QWen1_5_72BChat = 6, - - /// - /// qwen1.5-14b-chat, input token limit is 6k. - /// - // ReSharper disable once InconsistentNaming - QWen1_5_14BChat = 7, - - /// - /// qwen1.5-7b-chat, input token limit is 6k. - /// - // ReSharper disable once InconsistentNaming - QWen1_5_7BChat = 8, - - /// - /// qwen-72b-chat, input token limit is 30k. - /// - QWen72BChat = 9, - - /// - /// qwen-14b-chat, input token limit is 6k. - /// - QWen14BChat = 10, - - /// - /// qwen-7b-chat, input token limit is 6k. - /// - QWen7BChat = 11, - - /// - /// qwen-1.8b-longcontext-chat, input token limit is 30k. - /// - // ReSharper disable once InconsistentNaming - QWen1_8BLongContextChat = 12, - - /// - /// qwen-1.8b-chat, input token limit is 6k. - /// - // ReSharper disable once InconsistentNaming - QWen1_8Chat = 13, - - /// - /// qwen-long, input limit 10,000,000 token - /// - QWenLong = 14, - - /// - /// qwen-coder-turbo - /// - QWenCoderTurbo = 15, - - /// - /// qwen-math-plus - /// - QWenMath = 16, - - /// - /// qwen-coder-plus - /// - QWenCoderPlus = 17, - - /// - /// qwen-max-latest - /// - QWenMaxLatest = 18, - - /// - /// qwen-turbo-latest - /// - QWenTurboLatest = 19, - - /// - /// qwen-plus-latest - /// - QWenPlusLatest = 20, - - /// - /// qwq-32b-preview - /// - QwQ32BPreview = 21, - - /// - /// qwen-math-plus-latest - /// - QWenMathLatest = 22, - - /// - /// qwen-coder-plus-latest - /// - QWenCoderPlusLatest = 23, - - /// - /// qwen-coder-turbo-latest - /// - QWenCoderTurboLatest = 24, - - /// - /// qvq-72b-preview - /// - QvQ72BPreview = 25, - - /// - /// qwq-32b - /// - QwQ32B = 26 -} diff --git a/src/Cnblogs.DashScope.Sdk/QWen/QWenLlmNames.cs b/src/Cnblogs.DashScope.Sdk/QWen/QWenLlmNames.cs deleted file mode 100644 index a433baf..0000000 --- a/src/Cnblogs.DashScope.Sdk/QWen/QWenLlmNames.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace Cnblogs.DashScope.Sdk.QWen; - -internal static class QWenLlmNames -{ - public static string GetModelName(this QWenLlm llm) - { - return llm switch - { - QWenLlm.QWenTurbo => "qwen-turbo", - QWenLlm.QWenPlus => "qwen-plus", - QWenLlm.QWenMax => "qwen-max", - QWenLlm.QWenMax1201 => "qwen-max-1201", - QWenLlm.QWenMaxLongContext => "qwen-max-longcontext", - QWenLlm.QWen1_5_72BChat => "qwen1.5-72b-chat", - QWenLlm.QWen1_5_14BChat => "qwen1.5-14b-chat", - QWenLlm.QWen1_5_7BChat => "qwen1.5-7b-chat", - QWenLlm.QWen72BChat => "qwen-72b-chat", - QWenLlm.QWen14BChat => "qwen-14b-chat", - QWenLlm.QWen7BChat => "qwen-7b-chat", - QWenLlm.QWen1_8BLongContextChat => "qwen-1.8b-longcontext-chat", - QWenLlm.QWen1_8Chat => "qwen-1.8b-chat", - QWenLlm.QWenLong => "qwen-long", - QWenLlm.QWenCoderPlus => "qwen-coder-plus", - QWenLlm.QWenCoderPlusLatest => "qwen-coder-plus-latest", - QWenLlm.QWenCoderTurbo => "qwen-coder-turbo", - QWenLlm.QWenCoderTurboLatest => "qwen-coder-turbo-latest", - QWenLlm.QWenMath => "qwen-math-plus", - QWenLlm.QWenMathLatest => "qwen-math-plus-latest", - QWenLlm.QWenMaxLatest => "qwen-max-latest", - QWenLlm.QWenPlusLatest => "qwen-plus-latest", - QWenLlm.QWenTurboLatest => "qwen-turbo-latest", - QWenLlm.QwQ32BPreview => "qwq-32b-preview", - QWenLlm.QvQ72BPreview => "qvq-72b-preview", - QWenLlm.QwQ32B => "qwq-32b", - _ => ThrowHelper.UnknownModelName(nameof(llm), llm) - }; - } -} diff --git a/src/Cnblogs.DashScope.Sdk/QWen/QWenTextGenerationApi.cs b/src/Cnblogs.DashScope.Sdk/QWen/QWenTextGenerationApi.cs deleted file mode 100644 index 07e1ff1..0000000 --- a/src/Cnblogs.DashScope.Sdk/QWen/QWenTextGenerationApi.cs +++ /dev/null @@ -1,347 +0,0 @@ -using Cnblogs.DashScope.Core; - -namespace Cnblogs.DashScope.Sdk.QWen; - -/// -/// Extension methods for QWen text generation api, docs: https://help.aliyun.com/zh/dashscope/developer-reference/api-details -/// -public static class QWenTextGenerationApi -{ - /// - /// Begin a completions request and get an async enumerable of response. - /// - /// The - /// The model to use. - /// The collection of context messages associated with this chat completions request. - /// The optional parameters for this completion request. - /// The cancellation token to use. - /// Request for generation is failed. - /// - /// - /// Migrate from - /// - /// client.GetQWenChatCompletionAsync("qwen-plus", messages, parameters); - /// - /// to - /// - /// client.GetTextCompletionStreamAsync( - /// new ModelRequest<TextGenerationInput, ITextGenerationParameters> - /// { - /// Model = "qwen-plus", - /// Input = new TextGenerationInput { Messages = messages }, - /// Parameters = parameters - /// }); - /// - /// - [Obsolete("Use GetTextCompletionStreamAsync instead")] - public static IAsyncEnumerable> GetQWenChatStreamAsync( - this IDashScopeClient dashScopeClient, - QWenLlm model, - IEnumerable messages, - TextGenerationParameters? parameters = null, - CancellationToken cancellationToken = default) - { - // does not allow empty history array - return dashScopeClient.GetTextCompletionStreamAsync( - new ModelRequest - { - Model = model.GetModelName(), - Input = new TextGenerationInput { Messages = messages }, - Parameters = parameters - }, - cancellationToken); - } - - /// - /// Begin a completions request and get an async enumerable of response. - /// - /// The - /// The model to use. - /// The collection of context messages associated with this chat completions request. - /// The optional parameters for this completion request. - /// The cancellation token to use. - /// Request for generation is failed. - /// - /// - /// Migrate from - /// - /// client.GetQWenChatCompletionAsync("qwen-plus", messages, parameters); - /// - /// to - /// - /// client.GetTextCompletionStreamAsync( - /// new ModelRequest<TextGenerationInput, ITextGenerationParameters> - /// { - /// Model = "qwen-plus", - /// Input = new TextGenerationInput { Messages = messages }, - /// Parameters = parameters - /// }); - /// - /// - [Obsolete("Use GetTextCompletionStreamAsync instead")] - public static IAsyncEnumerable> GetQWenChatStreamAsync( - this IDashScopeClient dashScopeClient, - string model, - IEnumerable messages, - TextGenerationParameters? parameters = null, - CancellationToken cancellationToken = default) - { - return dashScopeClient.GetTextCompletionStreamAsync( - new ModelRequest - { - Model = model, - Input = new TextGenerationInput { Messages = messages }, - Parameters = parameters - }, - cancellationToken); - } - - /// - /// Request chat completion with QWen models. - /// - /// The . - /// The model to use. - /// The collection of context messages associated with this chat completions request. - /// The optional parameters for this completion request. - /// The cancellation token to use. - /// Request for generation is failed. - /// - /// - /// Migrate from - /// - /// client.GetQWenChatCompletionAsync(QWenLlm.QwQ32B, messages, parameters); - /// - /// to - /// - /// client.GetTextCompletionAsync( - /// new ModelRequest<TextGenerationInput, ITextGenerationParameters> - /// { - /// Model = "qwq-32b", - /// Input = new TextGenerationInput { Messages = messages }, - /// Parameters = parameters - /// }); - /// - /// - [Obsolete("Use GetTextCompletionAsync instead")] - public static Task> GetQWenChatCompletionAsync( - this IDashScopeClient dashScopeClient, - QWenLlm model, - IEnumerable messages, - TextGenerationParameters? parameters = null, - CancellationToken cancellationToken = default) - { - return dashScopeClient.GetQWenChatCompletionAsync( - model.GetModelName(), - messages, - parameters, - cancellationToken); - } - - /// - /// Request chat completion with QWen models. - /// - /// The . - /// The model to use. - /// The collection of context messages associated with this chat completions request. - /// The optional parameters for this completion request. - /// The cancellation token to use. - /// Request for generation is failed. - /// - /// - /// Migrate from - /// - /// client.GetQWenChatCompletionAsync("qwen-plus", messages, parameters); - /// - /// to - /// - /// client.GetTextCompletionAsync( - /// new ModelRequest<TextGenerationInput, ITextGenerationParameters> - /// { - /// Model = "qwen-plus", - /// Input = new TextGenerationInput { Messages = messages }, - /// Parameters = parameters - /// }); - /// - /// - [Obsolete("Use GetTextCompletionAsync instead")] - public static Task> GetQWenChatCompletionAsync( - this IDashScopeClient dashScopeClient, - string model, - IEnumerable messages, - TextGenerationParameters? parameters = null, - CancellationToken cancellationToken = default) - { - return dashScopeClient.GetTextCompletionAsync( - new ModelRequest - { - Model = model, - Input = new TextGenerationInput { Messages = messages }, - Parameters = parameters - }, - cancellationToken); - } - - /// - /// Begin a completions request and get an async enumerable of response. - /// - /// The . - /// The model to use. - /// The prompt to generate completion from. - /// The optional parameters for this completion request. - /// The cancellation token to use. - /// Request for generation is failed. - /// - /// Migrate from - /// - /// client.GetQWenCompletionStreamAsync(QWenLlm.QwQ32B, "prompt", parameters); - /// - /// to - /// - /// client.GetTextCompletionStreamAsync( - /// new ModelRequest<TextGenerationInput, ITextGenerationParameters> - /// { - /// Model = "qwq-32b", - /// Input = new TextGenerationInput { Messages = [TextChatMessage.User("prompt")] }, - /// Parameters = parameters - /// }); - /// - /// - [Obsolete("Use GetTextCompletionStreamAsync instead")] - public static IAsyncEnumerable> - GetQWenCompletionStreamAsync( - this IDashScopeClient dashScopeClient, - QWenLlm model, - string prompt, - TextGenerationParameters? parameters, - CancellationToken cancellationToken = default) - { - return dashScopeClient.GetQWenCompletionStreamAsync( - model.GetModelName(), - prompt, - parameters, - cancellationToken); - } - - /// - /// Begin a completions request and get an async enumerable of response. - /// - /// The . - /// The model to use. - /// The prompt to generate completion from. - /// The optional parameters for this completion request. - /// The cancellation token to use. - /// Request for generation is failed. - /// - /// Migrate from - /// - /// client.GetQWenCompletionStreamAsync("qwq-32b", "prompt", parameters); - /// - /// to - /// - /// client.GetTextCompletionStreamAsync( - /// new ModelRequest<TextGenerationInput, ITextGenerationParameters> - /// { - /// Model = "qwq-32b", - /// Input = new TextGenerationInput { Messages = [TextChatMessage.User("prompt")] }, - /// Parameters = parameters - /// }); - /// - /// - [Obsolete("Use GetTextCompletionStreamAsync instead")] - public static IAsyncEnumerable> - GetQWenCompletionStreamAsync( - this IDashScopeClient dashScopeClient, - string model, - string prompt, - TextGenerationParameters? parameters, - CancellationToken cancellationToken = default) - { - return dashScopeClient.GetTextCompletionStreamAsync( - new ModelRequest - { - Model = model, - Input = new TextGenerationInput { Prompt = prompt }, - Parameters = parameters - }, - cancellationToken); - } - - /// - /// Request completion with QWen models. - /// - /// The . - /// The QWen model to use. - /// The prompt to generate completion from. - /// The optional parameters for this completion request. - /// The cancellation token to use. - /// Request for generation is failed. - /// - /// Migrate from - /// - /// client.GetQWenCompletionAsync(QWenLlm.QwQ32B, "prompt", parameters); - /// - /// to - /// - /// client.GetTextCompletionAsync( - /// new ModelRequest<TextGenerationInput, ITextGenerationParameters> - /// { - /// Model = "qwq-32b", - /// Input = new TextGenerationInput { Messages = [TextChatMessage.User("prompt")] }, - /// Parameters = parameters - /// }); - /// - /// - [Obsolete("Use GetTextCompletionAsync instead")] - public static Task> GetQWenCompletionAsync( - this IDashScopeClient dashScopeClient, - QWenLlm model, - string prompt, - TextGenerationParameters? parameters = null, - CancellationToken cancellationToken = default) - { - return dashScopeClient.GetQWenCompletionAsync(model.GetModelName(), prompt, parameters, cancellationToken); - } - - /// - /// Request completion with QWen models. - /// - /// The . - /// The QWen model to use. - /// The prompt to generate completion from. - /// The optional parameters for this completion request. - /// The cancellation token to use. - /// Request for generation is failed. - /// - /// Migrate from - /// - /// client.GetQWenCompletionAsync("qwq-32b", "prompt", parameters); - /// - /// to - /// - /// client.GetTextCompletionAsync( - /// new ModelRequest<TextGenerationInput, ITextGenerationParameters> - /// { - /// Model = "qwq-32b", - /// Input = new TextGenerationInput { Messages = [TextChatMessage.User("prompt")] }, - /// Parameters = parameters - /// }); - /// - /// - [Obsolete("Use GetTextCompletionAsync instead")] - public static Task> GetQWenCompletionAsync( - this IDashScopeClient dashScopeClient, - string model, - string prompt, - TextGenerationParameters? parameters = null, - CancellationToken cancellationToken = default) - { - return dashScopeClient.GetTextCompletionAsync( - new ModelRequest - { - Model = model, - Input = new TextGenerationInput { Prompt = prompt }, - Parameters = parameters - }, - cancellationToken); - } -} diff --git a/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalGenerationApi.cs b/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalGenerationApi.cs deleted file mode 100644 index e2447fd..0000000 --- a/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalGenerationApi.cs +++ /dev/null @@ -1,173 +0,0 @@ -using Cnblogs.DashScope.Core; - -namespace Cnblogs.DashScope.Sdk.QWenMultimodal; - -/// -/// Extension methods for qwen-vl and qwen-audio: https://help.aliyun.com/zh/dashscope/developer-reference/tongyi-qianwen-vl-plus-api?spm=a2c4g.11186623.0.0.6cd412b09sQtru#8f79b5d0f8ker -/// -public static class QWenMultimodalGenerationApi -{ - /// - /// Request completion with qWen-vl models. - /// - /// The . - /// The requesting model's name. - /// The messages to complete. - /// The optional configuration for this request. - /// The to use. - /// - /// - /// Migrate from - /// - /// client.GetQWenMultimodalCompletionAsync(QWenMultimodalModel.QWenVlPlus, messages, parameters); - /// - /// to - /// - /// client.GetMultimodalGenerationAsync( - /// new ModelRequest<MultimodalInput, IMultimodalParameters> - /// { - /// Model = "qwen-vl-plus", - /// Input = new MultimodalInput { Messages = messages }, - /// Parameters = parameters - /// }); - /// - /// - [Obsolete("Use GetMultimodalGenerationAsync instead")] - public static Task> GetQWenMultimodalCompletionAsync( - this IDashScopeClient client, - QWenMultimodalModel model, - IEnumerable messages, - MultimodalParameters? parameters = null, - CancellationToken cancellationToken = default) - { - return client.GetQWenMultimodalCompletionAsync(model.GetModelName(), messages, parameters, cancellationToken); - } - - /// - /// Request completion with qWen-vl models. - /// - /// The . - /// The requesting model's name. - /// The messages to complete. - /// The optional configuration for this request. - /// The to use. - /// - /// - /// Migrate from - /// - /// client.GetQWenMultimodalCompletionAsync("qwen-vl-plus", messages, parameters); - /// - /// to - /// - /// client.GetMultimodalGenerationAsync( - /// new ModelRequest<MultimodalInput, IMultimodalParameters> - /// { - /// Model = "qwen-vl-plus", - /// Input = new MultimodalInput { Messages = messages }, - /// Parameters = parameters - /// }); - /// - /// - [Obsolete("Use GetMultimodalGenerationAsync instead")] - public static Task> GetQWenMultimodalCompletionAsync( - this IDashScopeClient client, - string model, - IEnumerable messages, - MultimodalParameters? parameters = null, - CancellationToken cancellationToken = default) - { - return client.GetMultimodalGenerationAsync( - new ModelRequest - { - Model = model, - Input = new MultimodalInput { Messages = messages }, - Parameters = parameters - }, - cancellationToken); - } - - /// - /// Request completion with qWen-vl models. - /// - /// The . - /// The requesting model's name. - /// The messages to complete. - /// The optional configuration for this request. - /// The to use. - /// - /// - /// Migrate from - /// - /// client.GetQWenMultimodalCompletionStreamAsync("qwen-vl-plus", messages, parameters); - /// - /// to - /// - /// client.GetMultimodalGenerationStreamAsync( - /// new ModelRequest<MultimodalInput, IMultimodalParameters> - /// { - /// Model = "qwen-vl-plus", - /// Input = new MultimodalInput { Messages = messages }, - /// Parameters = parameters - /// }); - /// - /// - [Obsolete("Use GetMultimodalGenerationStreamAsync instead")] - public static IAsyncEnumerable> - GetQWenMultimodalCompletionStreamAsync( - this IDashScopeClient client, - QWenMultimodalModel model, - IEnumerable messages, - MultimodalParameters? parameters = null, - CancellationToken cancellationToken = default) - { - return client.GetQWenMultimodalCompletionStreamAsync( - model.GetModelName(), - messages, - parameters, - cancellationToken); - } - - /// - /// Request completion with qWen-vl models. - /// - /// The . - /// The requesting model's name. - /// The messages to complete. - /// The optional configuration for this request. - /// The to use. - /// - /// - /// Migrate from - /// - /// client.GetQWenMultimodalCompletionStreamAsync("qwen-vl-plus", messages, parameters); - /// - /// to - /// - /// client.GetMultimodalGenerationStreamAsync( - /// new ModelRequest<MultimodalInput, IMultimodalParameters> - /// { - /// Model = "qwen-vl-plus", - /// Input = new MultimodalInput { Messages = messages }, - /// Parameters = parameters - /// }); - /// - /// - [Obsolete("Use GetMultimodalGenerationStreamAsync instead")] - public static IAsyncEnumerable> - GetQWenMultimodalCompletionStreamAsync( - this IDashScopeClient client, - string model, - IEnumerable messages, - MultimodalParameters? parameters = null, - CancellationToken cancellationToken = default) - { - return client.GetMultimodalGenerationStreamAsync( - new ModelRequest - { - Model = model, - Input = new MultimodalInput { Messages = messages }, - Parameters = parameters - }, - cancellationToken); - } -} diff --git a/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModel.cs b/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModel.cs deleted file mode 100644 index abeeade..0000000 --- a/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModel.cs +++ /dev/null @@ -1,82 +0,0 @@ -namespace Cnblogs.DashScope.Sdk.QWenMultimodal; - -/// -/// Available models for multimodal generation. -/// -public enum QWenMultimodalModel -{ - /// - /// qwen-vl-plus - /// - QWenVlPlus = 1, - - /// - /// qwen-vl-max - /// - QWenVlMax = 2, - - /// - /// qwen-audio-turbo - /// - QWenAudioTurbo = 3, - - /// - /// qwen-vl-v1 - /// - QWenVlV1 = 4, - - /// - /// qwen-vl-chat-v1 - /// - QWenVlChatV1 = 5, - - /// - /// qwen-audio-chat - /// - QWenAudioChat = 6, - - /// - /// qwen-vl-ocr - /// - QWenVlOcr = 7, - - /// - /// qwen-vl-max-latest - /// - QWenVlMaxLatest = 8, - - /// - /// qwen-vl-plus-latest - /// - QWenVlPlusLatest = 9, - - /// - /// qwen-vl-ocr-latest - /// - QWenVlOcrLatest = 10, - - /// - /// qwen-audio-turbo-latest - /// - QWenAudioTurboLatest = 11, - - /// - /// qvq-max - /// - QvQMax = 12, - - /// - /// qvq-max-latest - /// - QvQMaxLatest = 13, - - /// - /// qvq-plus - /// - QvQPlus = 14, - - /// - /// qvq-plus-latest - /// - QvQPlusLatest = 15 -} diff --git a/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModelNames.cs b/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModelNames.cs deleted file mode 100644 index e22aeda..0000000 --- a/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModelNames.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Cnblogs.DashScope.Sdk.QWenMultimodal; - -internal static class QWenMultimodalModelNames -{ - public static string GetModelName(this QWenMultimodalModel multimodalModel) - { - return multimodalModel switch - { - QWenMultimodalModel.QWenVlPlus => "qwen-vl-plus", - QWenMultimodalModel.QWenVlMax => "qwen-vl-max", - QWenMultimodalModel.QWenAudioTurbo => "qwen-audio-turbo", - QWenMultimodalModel.QWenVlV1 => "qwen-vl-v1", - QWenMultimodalModel.QWenVlChatV1 => "qwen-vl-chat-v1", - QWenMultimodalModel.QWenAudioChat => "qwen-audio-chat", - QWenMultimodalModel.QWenVlOcr => "qwen-vl-ocr", - QWenMultimodalModel.QWenVlMaxLatest => "qwen-vl-max-latest", - QWenMultimodalModel.QWenVlPlusLatest => "qwen-vl-plus-latest", - QWenMultimodalModel.QWenVlOcrLatest => "qwen-vl-ocr-latest", - QWenMultimodalModel.QWenAudioTurboLatest => "qwen-audio-turbo-latest", - QWenMultimodalModel.QvQMax => "qvq-max", - QWenMultimodalModel.QvQMaxLatest => "qvq-max-latest", - QWenMultimodalModel.QvQPlus => "qvq-plus", - QWenMultimodalModel.QvQPlusLatest => "qvq-plus-latest", - _ => ThrowHelper.UnknownModelName(nameof(multimodalModel), multimodalModel) - }; - } -} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/DeepSeekTextGenerationApiTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/DeepSeekTextGenerationApiTests.cs deleted file mode 100644 index 87643dd..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/DeepSeekTextGenerationApiTests.cs +++ /dev/null @@ -1,95 +0,0 @@ -using Cnblogs.DashScope.Core; -using Cnblogs.DashScope.Sdk.DeepSeek; -using NSubstitute; - -namespace Cnblogs.DashScope.Sdk.UnitTests; - -public class DeepSeekTextGenerationApiTests -{ - [Fact] - public async Task TextCompletion_UseEnum_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - - // Act - await client.GetDeepSeekChatCompletionAsync( - DeepSeekLlm.DeepSeekR1, - new List { TextChatMessage.User("你好") }.AsReadOnly()); - - // Assert - await client.Received().GetTextCompletionAsync( - Arg.Is>(x - => x.Model == "deepseek-r1" && x.Input.Messages!.First().Content == "你好" && x.Parameters == null)); - } - - [Fact] - public async Task TextCompletion_UseInvalidEnum_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - - // Act - var act = async () => await client.GetDeepSeekChatCompletionAsync( - (DeepSeekLlm)(-1), - new List { TextChatMessage.User("你好") }.AsReadOnly()); - - // Assert - await Assert.ThrowsAsync(act); - } - - [Fact] - public async Task TextCompletion_UseCustomModel_SuccessAsync() - { - // Arrange - const string customModel = "deepseek-v3"; - var client = Substitute.For(); - - // Act - await client.GetDeepSeekChatCompletionAsync( - customModel, - new List { TextChatMessage.User("你好") }.AsReadOnly()); - - // Assert - await client.Received().GetTextCompletionAsync( - Arg.Is>(x - => x.Model == customModel && x.Input.Messages!.First().Content == "你好" && x.Parameters == null)); - } - - [Fact] - public void StreamCompletion_UseEnum_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - - // Act - _ = client.GetDeepSeekChatCompletionStreamAsync( - DeepSeekLlm.DeepSeekV3, - new List { TextChatMessage.User("你好") }.AsReadOnly()); - - // Assert - _ = client.Received().GetTextCompletionStreamAsync( - Arg.Is>(x => x.Model == "deepseek-v3" - && x.Input.Messages!.First().Content == "你好" - && x.Parameters!.IncrementalOutput == true)); - } - - [Fact] - public void StreamCompletion_CustomModel_SuccessAsync() - { - // Arrange - const string customModel = "deepseek-v3"; - var client = Substitute.For(); - - // Act - _ = client.GetDeepSeekChatCompletionStreamAsync( - customModel, - new List { TextChatMessage.User("你好") }.AsReadOnly()); - - // Assert - _ = client.Received().GetTextCompletionStreamAsync( - Arg.Is>(x => x.Model == customModel - && x.Input.Messages!.First().Content == "你好" - && x.Parameters!.IncrementalOutput == true)); - } -} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/QWenMultimodalApiTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/QWenMultimodalApiTests.cs deleted file mode 100644 index 8e7a553..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/QWenMultimodalApiTests.cs +++ /dev/null @@ -1,99 +0,0 @@ -using Cnblogs.DashScope.Core; -using Cnblogs.DashScope.Sdk.QWenMultimodal; -using Cnblogs.DashScope.Tests.Shared.Utils; -using NSubstitute; - -namespace Cnblogs.DashScope.Sdk.UnitTests; - -public class QWenMultimodalApiTests -{ - private static readonly List Messages = - new() - { - MultimodalMessage.User( - new List - { - MultimodalMessageContent.ImageContent("https://cdn.example.com/image.jpg"), - MultimodalMessageContent.TextContent("说明一下这张图片的内容") - }.AsReadOnly()) - }; - - [Fact] - public async Task Multimodal_UseEnum_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - var parameters = new MultimodalParameters { Seed = 6666 }; - - // Act - _ = await client.GetQWenMultimodalCompletionAsync(QWenMultimodalModel.QWenVlMax, Messages, parameters); - - // Assert - _ = client.Received().GetMultimodalGenerationAsync( - Arg.Is>(s - => s.Model == "qwen-vl-max" && s.Input.Messages == Messages && s.Parameters == parameters)); - } - - [Fact] - public async Task Multimodal_UseInvalidEnum_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - var parameters = new MultimodalParameters { Seed = 6666 }; - - // Act - var act = async () - => await client.GetQWenMultimodalCompletionAsync((QWenMultimodalModel)(-1), Messages, parameters); - - // Assert - await Assert.ThrowsAsync(act); - } - - [Fact] - public async Task Multimodal_CustomModel_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - var parameters = new MultimodalParameters { Seed = 6666 }; - - // Act - _ = await client.GetQWenMultimodalCompletionAsync(Cases.CustomModelName, Messages, parameters); - - // Assert - _ = client.Received().GetMultimodalGenerationAsync( - Arg.Is>(s - => s.Model == Cases.CustomModelName && s.Input.Messages == Messages && s.Parameters == parameters)); - } - - [Fact] - public void MultimodalStream_UseEnum_Success() - { - // Arrange - var client = Substitute.For(); - var parameters = new MultimodalParameters { Seed = 6666 }; - - // Act - _ = client.GetQWenMultimodalCompletionStreamAsync(QWenMultimodalModel.QWenVlPlus, Messages, parameters); - - // Assert - _ = client.Received().GetMultimodalGenerationStreamAsync( - Arg.Is>(s - => s.Model == "qwen-vl-plus" && s.Input.Messages == Messages && s.Parameters == parameters)); - } - - [Fact] - public void Multimodal_CustomModel_Success() - { - // Arrange - var client = Substitute.For(); - var parameters = new MultimodalParameters { Seed = 6666 }; - - // Act - _ = client.GetQWenMultimodalCompletionStreamAsync(Cases.CustomModelName, Messages, parameters); - - // Assert - _ = client.Received().GetMultimodalGenerationStreamAsync( - Arg.Is>(s - => s.Model == Cases.CustomModelName && s.Input.Messages == Messages && s.Parameters == parameters)); - } -} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTextGenerationApiTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTextGenerationApiTests.cs deleted file mode 100644 index 5fb1f6f..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTextGenerationApiTests.cs +++ /dev/null @@ -1,168 +0,0 @@ -using Cnblogs.DashScope.Core; -using Cnblogs.DashScope.Sdk.QWen; -using Cnblogs.DashScope.Tests.Shared.Utils; -using NSubstitute; - -namespace Cnblogs.DashScope.Sdk.UnitTests; - -public class QWenTextGenerationApiTests -{ - private const string CustomModel = "custom-model"; - - private static readonly TextGenerationParameters IncrementalOutputParameters = new() - { - EnableSearch = true, - Seed = 1234, - IncrementalOutput = true - }; - - [Fact] - public async Task QWenCompletion_UseEnum_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - var parameters = new TextGenerationParameters { EnableSearch = true, Seed = 1234 }; - - // Act - await client.GetQWenCompletionAsync(QWenLlm.QWenMax, Cases.Prompt, parameters); - - // Assert - await client.Received() - .GetTextCompletionAsync( - Arg.Is>( - s => s.Input.Prompt == Cases.Prompt && s.Parameters == parameters && s.Model == "qwen-max")); - } - - [Fact] - public async Task QWenCompletion_CustomModel_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - var parameters = new TextGenerationParameters { EnableSearch = true, Seed = 1234 }; - - // Act - await client.GetQWenCompletionAsync(CustomModel, Cases.Prompt, parameters); - - // Assert - await client.Received() - .GetTextCompletionAsync( - Arg.Is>( - s => s.Input.Prompt == Cases.Prompt && s.Parameters == parameters && s.Model == CustomModel)); - } - - [Fact] - public void QWenCompletionStream_UseEnum_Success() - { - // Arrange - var client = Substitute.For(); - - // Act - _ = client.GetQWenCompletionStreamAsync(QWenLlm.QWenPlus, Cases.Prompt, IncrementalOutputParameters); - - // Assert - _ = client.Received() - .GetTextCompletionStreamAsync( - Arg.Is>( - s => s.Input.Prompt == Cases.Prompt - && s.Parameters == IncrementalOutputParameters - && s.Model == "qwen-plus")); - } - - [Fact] - public void QWenCompletionStream_UseCustomModel_Success() - { - // Arrange - var client = Substitute.For(); - - // Act - _ = client.GetQWenCompletionStreamAsync(CustomModel, Cases.Prompt, IncrementalOutputParameters); - - // Assert - _ = client.Received() - .GetTextCompletionStreamAsync( - Arg.Is>( - s => s.Input.Prompt == Cases.Prompt - && s.Parameters == IncrementalOutputParameters - && s.Model == CustomModel)); - } - - [Fact] - public async Task QWenChatCompletion_UseEnum_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - var parameters = new TextGenerationParameters { EnableSearch = true, ResultFormat = ResultFormats.Message }; - - // Act - await client.GetQWenChatCompletionAsync(QWenLlm.QWenMax1201, Cases.TextMessages, parameters); - - // Assert - await client.Received().GetTextCompletionAsync( - Arg.Is>( - s => s.Input.Messages == Cases.TextMessages && s.Parameters == parameters && s.Model == "qwen-max-1201")); - } - - [Fact] - public async Task QWenChatCompletion_UseInvalidEnum_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - var parameters = new TextGenerationParameters { EnableSearch = true, ResultFormat = ResultFormats.Message }; - - // Act - var act = async () => await client.GetQWenChatCompletionAsync((QWenLlm)(-1), Cases.TextMessages, parameters); - - // Assert - await Assert.ThrowsAsync(act); - } - - [Fact] - public async Task QWenChatCompletion_CustomModel_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - var parameters = new TextGenerationParameters { EnableSearch = true, ResultFormat = ResultFormats.Message }; - - // Act - await client.GetQWenChatCompletionAsync(CustomModel, Cases.TextMessages, parameters); - - // Assert - await client.Received().GetTextCompletionAsync( - Arg.Is>( - s => s.Input.Messages == Cases.TextMessages && s.Parameters == parameters && s.Model == CustomModel)); - } - - [Fact] - public void QWenChatCompletionStream_UseEnum_Success() - { - // Arrange - var client = Substitute.For(); - var parameters = new TextGenerationParameters { EnableSearch = true, ResultFormat = ResultFormats.Message }; - - // Act - _ = client.GetQWenChatStreamAsync(QWenLlm.QWenMaxLongContext, Cases.TextMessages, parameters); - - // Assert - _ = client.Received().GetTextCompletionStreamAsync( - Arg.Is>( - s => s.Input.Messages == Cases.TextMessages - && s.Parameters == parameters - && s.Model == "qwen-max-longcontext")); - } - - [Fact] - public void QWenChatCompletionStream_CustomModel_Success() - { - // Arrange - var client = Substitute.For(); - var parameters = new TextGenerationParameters { EnableSearch = true, ResultFormat = ResultFormats.Message }; - - // Act - _ = client.GetQWenChatStreamAsync(CustomModel, Cases.TextMessages, parameters); - - // Assert - _ = client.Received().GetTextCompletionStreamAsync( - Arg.Is>( - s => s.Input.Messages == Cases.TextMessages && s.Parameters == parameters && s.Model == CustomModel)); - } -}