Skip to content

Commit 2e108cc

Browse files
committed
feat: add tests for translation model
1 parent 5661b20 commit 2e108cc

12 files changed

+173
-1
lines changed

src/Cnblogs.DashScope.Core/ITextGenerationParameters.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public interface ITextGenerationParameters
4141
/// </summary>
4242
public bool? EnableSearch { get; }
4343

44+
/// <summary>
45+
/// Search options. <see cref="EnableSearch"/> should set to true.
46+
/// </summary>
47+
public TextGenerationSearchOptions? SearchOptions { get; set; }
48+
4449
/// <summary>
4550
/// Thinking option. Valid for supported models.(e.g. qwen3)
4651
/// </summary>

src/Cnblogs.DashScope.Core/TextGenerationOutput.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ public class TextGenerationOutput
1919
/// Not null when <see cref="TextGenerationParameters"/>.<see cref="TextGenerationParameters.ResultFormat"/> is "message".
2020
/// </summary>
2121
public List<TextGenerationChoice>? Choices { get; set; }
22+
23+
/// <summary>
24+
/// Not null when <see cref="TextGenerationParameters"/>.<see cref="TextGenerationParameters.SearchOptions"/> configured to show source.
25+
/// </summary>
26+
public TextGenerationWebSearchInfo? SearchInfo { get; set; }
2227
}

src/Cnblogs.DashScope.Core/TextGenerationParameters.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public class TextGenerationParameters : ITextGenerationParameters
3838
/// <inheritdoc />
3939
public bool? EnableSearch { get; set; }
4040

41+
/// <inheritdoc />
42+
public TextGenerationSearchOptions? SearchOptions { get; set; }
43+
4144
/// <inheritdoc />
4245
public bool? EnableThinking { get; set; }
4346

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// Web search options
5+
/// </summary>
6+
public class TextGenerationSearchOptions
7+
{
8+
/// <summary>
9+
/// Show search result in response. Defaults to false.
10+
/// </summary>
11+
public bool? EnableSource { get; set; }
12+
13+
/// <summary>
14+
/// Include citation in output. Defaults to false.
15+
/// </summary>
16+
public bool? EnableCitation { get; set; }
17+
18+
/// <summary>
19+
/// Citation format. Defaults to "[&lt;number&gt;]"
20+
/// </summary>
21+
public string? CitationFormat { get; set; }
22+
23+
/// <summary>
24+
/// Force model to use web search. Defaults to false.
25+
/// </summary>
26+
public bool? ForcedSearch { get; set; }
27+
28+
/// <summary>
29+
/// How many search records should be provided to model. "standard" - 5 records. "pro" - 10 records.
30+
/// </summary>
31+
public string? SearchStrategy { get; set; }
32+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// Web search information.
5+
/// </summary>
6+
/// <param name="SearchResults">Web search results.</param>
7+
public record TextGenerationWebSearchInfo(List<TextGenerationWebSearchResult> SearchResults);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// Represents one web search record.
5+
/// </summary>
6+
/// <param name="SiteName">Source site name.</param>
7+
/// <param name="Icon">Source site favicon url.</param>
8+
/// <param name="Index">Serial number of search records.</param>
9+
/// <param name="Title">Page title.</param>
10+
/// <param name="Url">Page url.</param>
11+
public record TextGenerationWebSearchResult(string SiteName, string Icon, int Index, string Title, string Url);

test/Cnblogs.DashScope.Sdk.UnitTests/TextGenerationSerializationTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ public async Task ConversationCompletion_MessageFormatSse_SuccessAsync(
156156
Snapshots.TextGeneration.MessageFormat.SingleMessageReasoning,
157157
Snapshots.TextGeneration.MessageFormat.SingleMessageWithTools,
158158
Snapshots.TextGeneration.MessageFormat.SingleMessageJson,
159-
Snapshots.TextGeneration.MessageFormat.SingleMessageLogprobs);
159+
Snapshots.TextGeneration.MessageFormat.SingleMessageLogprobs,
160+
Snapshots.TextGeneration.MessageFormat.SingleMessageTranslation);
160161

161162
public static readonly TheoryData<RequestSnapshot<ModelRequest<TextGenerationInput, ITextGenerationParameters>,
162163
ModelResponse<TextGenerationOutput, TextGenerationTokenUsage>>> SingleGenerationMessageSseFormatData = new(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"model": "qwen-mt-plus",
3+
"input": {
4+
"messages": [
5+
{
6+
"role": "user",
7+
"content": "博客园的理念是代码改变世界"
8+
}
9+
]
10+
},
11+
"parameters": {
12+
"result_format": "message",
13+
"incremental_output": false,
14+
"translation_options": {
15+
"source_lang": "Chinese",
16+
"target_lang": "English",
17+
"terms": [
18+
{
19+
"source": "博客园",
20+
"target": "cnblogs"
21+
}
22+
],
23+
"tm_list": [
24+
{
25+
"source": "代码改变世界",
26+
"target": "Coding changes world"
27+
}
28+
],
29+
"domains": "This text is a promotion."
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
POST /api/v1/services/aigc/text-generation/generation HTTP/1.1
2+
Content-Type: application/json
3+
Accept: */*
4+
Cache-Control: no-cache
5+
Host: dashscope.aliyuncs.com
6+
Accept-Encoding: gzip, deflate, br
7+
Connection: keep-alive
8+
Content-Length: 85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"output":{"finish_reason":"stop","model_name":"qwen-mt-plus","choices":[{"finish_reason":"stop","message":{"role":"assistant","content":"The concept of cnblogs is that coding changes world "}}]},"usage":{"total_tokens":122,"output_tokens":11,"input_tokens":111},"request_id":"bf86e0f9-a8a2-9b32-be8d-ea3cae47c8ea"}

0 commit comments

Comments
 (0)