Skip to content

Commit 2237bbd

Browse files
committed
feat: add logprobs properties
1 parent cbf3089 commit 2237bbd

8 files changed

+85
-1
lines changed

src/Cnblogs.DashScope.Core/ITextGenerationParameters.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ namespace Cnblogs.DashScope.Core;
44
/// The text generation options.
55
/// </summary>
66
public interface ITextGenerationParameters
7-
: IIncrementalOutputParameter, ISeedParameter, IProbabilityParameter, IPenaltyParameter, IMaxTokenParameter, IStopTokenParameter
7+
: IIncrementalOutputParameter, ISeedParameter, IProbabilityParameter, IPenaltyParameter, IMaxTokenParameter,
8+
IStopTokenParameter
89
{
910
/// <summary>
1011
/// The format of the result, must be <c>text</c> or <c>message</c>.
@@ -74,4 +75,9 @@ public interface ITextGenerationParameters
7475
/// Whether to enable parallel tool calling
7576
/// </summary>
7677
public bool? ParallelToolCalls { get; }
78+
79+
/// <summary>
80+
/// Options when using QWen-MT models.
81+
/// </summary>
82+
public TextGenerationTranslationOptions? TranslationOptions { get; set; }
7783
}

src/Cnblogs.DashScope.Core/TextGenerationChoice.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ public class TextGenerationChoice
1414
/// The generated message.
1515
/// </summary>
1616
public TextChatMessage Message { get; set; } = new(Array.Empty<DashScopeFileId>());
17+
18+
/// <summary>
19+
/// Token array with log possibility info.
20+
/// </summary>
21+
public TextGenerationLogProbs? Logprobs { get; set; }
1722
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// Represents a possible choice of token.
5+
/// </summary>
6+
/// <param name="Token">Token content.</param>
7+
/// <param name="Bytes">Token content in UTF-8 byte array.</param>
8+
/// <param name="Logprob">Possibility, <c>null</c> when it's too low.</param>
9+
/// <param name="TopLogprobs">The most possible alternatives.</param>
10+
public record TextGenerationLogProbContent(
11+
string Token,
12+
byte[] Bytes,
13+
float? Logprob,
14+
List<TextGenerationTopLogProbContent> TopLogprobs);
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+
/// Possibilities of token choices.
5+
/// </summary>
6+
/// <param name="Content">The choices with their possibility.</param>
7+
public record TextGenerationLogProbs(List<TextGenerationLogProbContent> Content);

src/Cnblogs.DashScope.Core/TextGenerationParameters.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public class TextGenerationParameters : ITextGenerationParameters
5959
/// <inheritdoc />
6060
public bool? ParallelToolCalls { get; set; }
6161

62+
/// <inheritdoc />
63+
public TextGenerationTranslationOptions? TranslationOptions { get; set; }
64+
6265
/// <inheritdoc />
6366
public bool? IncrementalOutput { get; set; }
6467
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// Represents one choice of most possibility alternative tokens.
5+
/// </summary>
6+
/// <param name="Token">The token content.</param>
7+
/// <param name="Bytes">The token content in UTF-8 byte array.</param>
8+
/// <param name="Logprob">Possibility, <c>null</c> when possibility is too low.</param>
9+
public record TextGenerationTopLogProbContent(string Token, byte[] Bytes, float? Logprob);
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+
/// Configurations when using translation models.
5+
/// </summary>
6+
public class TextGenerationTranslationOptions
7+
{
8+
/// <summary>
9+
/// The language name of the input text. Use 'auto' to enable auto-detection.
10+
/// </summary>
11+
public string SourceLang { get; set; } = "auto";
12+
13+
/// <summary>
14+
/// The language name of the output text.
15+
/// </summary>
16+
public string TargetLang { get; set; } = string.Empty;
17+
18+
/// <summary>
19+
/// Term list for translation.
20+
/// </summary>
21+
public IEnumerable<TranslationReference>? Terms { get; set; }
22+
23+
/// <summary>
24+
/// Sample texts for translation
25+
/// </summary>
26+
public IEnumerable<TranslationReference>? TmList { get; set; }
27+
28+
/// <summary>
29+
/// Domain info about the source text. Only supports English.
30+
/// </summary>
31+
public string? Domains { get; set; }
32+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// A text pair that used for translation reference.
5+
/// </summary>
6+
/// <param name="Source">The text in source language.</param>
7+
/// <param name="Target">The text in target language.</param>
8+
public record TranslationReference(string Source, string Target);

0 commit comments

Comments
 (0)