Skip to content

Commit c315233

Browse files
committed
Move supported content type into ChatCompletionService layer, fix gemini-2.0-flash-exp
1 parent 93961c4 commit c315233

4 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/BE/Services/Models/ChatServices/ChatService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected virtual async Task<ChatMessage[]> FEPreprocess(IReadOnlyList<ChatMessa
6464
SetReasoningEffort(options, feOptions.ReasoningEffort);
6565
}
6666

67-
if (!string.IsNullOrEmpty(feOptions.ImageSize))
67+
if (!string.IsNullOrEmpty(feOptions.ImageSize) && Model.GetSupportedImageSizesAsArray(Model.SupportedImageSizes).Any())
6868
{
6969
SetImageSize(options, feOptions.ImageSize);
7070
}

src/BE/Services/Models/ChatServices/ChatServiceExtensions.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ public async IAsyncEnumerable<InternalChatSegment> ChatStreamedSimulated(bool su
7676
protected virtual bool SupportsVisionLink => true;
7777
protected virtual HashSet<string> SupportedContentTypes =>
7878
[
79-
"image/jpeg",
80-
"image/png",
81-
"image/gif",
82-
"image/webp",
79+
"*"
8380
];
8481

8582
protected virtual async Task<ChatMessage> FilterVision(bool allowVision, ChatMessage message, FileUrlProvider fup, CancellationToken cancellationToken)
@@ -95,7 +92,7 @@ protected virtual async Task<ChatMessage> FilterVision(bool allowVision, ChatMes
9592
{
9693
true => scfp.File.FileContentType.ContentType switch
9794
{
98-
var x when SupportedContentTypes.Contains(x) => SupportsVisionLink switch
95+
var x when SupportedContentTypes.Contains("*") || SupportedContentTypes.Contains(x) => SupportsVisionLink switch
9996
{
10097
true => await fup.CreateOpenAIImagePart(scfp.File, cancellationToken),
10198
false => await fup.CreateOpenAIImagePartForceDownload(scfp.File, cancellationToken),

src/BE/Services/Models/ChatServices/GoogleAI/GoogleAI2ChatService.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class GoogleAI2ChatService : ChatService
2323
new SafetySetting { Category = HarmCategory.HarmCategoryDangerousContent, Threshold = HarmBlockThreshold.BlockNone },
2424
new SafetySetting { Category = HarmCategory.HarmCategoryHarassment, Threshold = HarmBlockThreshold.BlockNone },
2525
];
26-
private DBReasoningEffort _reasoningEffort = default;
2726

2827
protected override bool SupportsVisionLink => false;
2928

@@ -61,9 +60,9 @@ public override async IAsyncEnumerable<ChatSegment> ChatStreamed(IReadOnlyList<C
6160
{
6261
gc.ThinkingConfig = new ThinkingConfig
6362
{
64-
ThinkingBudget = _reasoningEffort switch
63+
ThinkingBudget = options.ReasoningEffortLevel switch
6564
{
66-
var x when x.IsLowOrMinimal() => 1024,
65+
var x when x == ChatReasoningEffortLevel.Minimal || x == ChatReasoningEffortLevel.Low => 1024,
6766
_ => null,
6867
},
6968
IncludeThoughts = true,
@@ -90,7 +89,7 @@ var x when x.IsLowOrMinimal() => 1024,
9089
SystemInstruction = OpenAIChatMessageToGoogleContent(messages.Where(x => x is SystemChatMessage)) switch { [] => null, var x => x[0] },
9190
GenerationConfig = gc,
9291
SafetySettings = _safetySettings,
93-
Tools = tool == null ? null : [tool],
92+
Tools = Model.AllowToolCall && tool != null ? [tool] : null,
9493
};
9594
Stopwatch codeExecutionSw = new();
9695
string? codeExecutionId = null;

src/BE/Services/Models/ChatServices/OpenAI/ChatCompletionService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ public ChatCompletionService(Model model, Uri? suggestedApiUrl = null, params Pi
1515
{
1616
}
1717

18+
protected override HashSet<string> SupportedContentTypes =>
19+
[
20+
"image/jpeg",
21+
"image/png",
22+
"image/gif",
23+
"image/webp",
24+
];
25+
1826
private static ChatClient CreateChatClient(Model model, Uri? suggestedApiUrl, PipelinePolicy[] perCallPolicies)
1927
{
2028
OpenAIClient api = CreateOpenAIClient(model.ModelKey, suggestedApiUrl, perCallPolicies);

0 commit comments

Comments
 (0)