Merge branch 'main' into chunk-data

This commit is contained in:
PaulKoudelka committed 2026-08-04 18:01:25 +02:00
commit 9932b5870b
484 files changed
+45549 -2467

No files matched your search

+15 -57
View File
@@ -1072,7 +1072,11 @@ public abstract class BaseProvider : IProvider, ISecretId
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", await requestedSecret.Secret.Decrypt(Program.ENCRYPTION));
break;
}
this.logger.LogInformation("Uploading transcription media '{FileName}' with content type '{ContentType}' and {FileSize} bytes.",
Path.GetFileName(audioFilePath),
mimeType.TextRepresentation,
fileStream.Length);
using var response = await this.HttpClient.SendAsync(request, token);
var responseBody = await response.Content.ReadAsStringAsync(token);
@@ -1092,6 +1096,10 @@ public abstract class BaseProvider : IProvider, ISecretId
return TranscriptionResult.FromText(transcriptionResponse.Text);
}
catch (OperationCanceledException) when (token.IsCancellationRequested)
{
throw;
}
catch (Exception e)
{
if (this.IsTimeoutException(e, token))
@@ -1194,42 +1202,15 @@ public abstract class BaseProvider : IProvider, ISecretId
protected IDictionary<string, object> ParseAdditionalApiParameters(
params string[] keysToRemove)
{
if(string.IsNullOrWhiteSpace(this.AdditionalJsonApiParameters))
return new Dictionary<string, object>();
try
if (!AdditionalApiParametersParser.TryParse(this.AdditionalJsonApiParameters, out var apiParameters, out var errorMessage))
{
// Wrap the user-provided parameters in curly brackets to form a valid JSON object:
var json = $"{{{this.AdditionalJsonApiParameters}}}";
var jsonDoc = JsonSerializer.Deserialize<JsonElement>(json, JSON_SERIALIZER_OPTIONS);
var dict = ConvertToDictionary(jsonDoc);
// Some keys are always removed because we set them:
var removeSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
if (keysToRemove.Length > 0)
removeSet.UnionWith(keysToRemove);
removeSet.Add("stream");
removeSet.Add("model");
removeSet.Add("messages");
// Remove the specified keys (case-insensitive):
if (removeSet.Count > 0)
{
foreach (var key in dict.Keys.ToList())
{
if (removeSet.Contains(key))
dict.Remove(key);
}
}
return dict;
}
catch (JsonException ex)
{
this.logger.LogError("Failed to parse additional API parameters: {ExceptionMessage}", ex.Message);
this.logger.LogError("Failed to parse additional API parameters: {ExceptionMessage}", errorMessage);
return new Dictionary<string, object>();
}
// Some keys are always removed because AI Studio sets them itself.
var reservedKeys = keysToRemove.Concat(["stream", "model", "messages"]);
return AdditionalApiParametersParser.RemoveKeys(apiParameters, reservedKeys);
}
protected static bool TryPopIntParameter(IDictionary<string, object> parameters, string key, out int value)
@@ -1311,27 +1292,4 @@ public abstract class BaseProvider : IProvider, ISecretId
return true;
}
private static IDictionary<string, object> ConvertToDictionary(JsonElement element)
{
return element.EnumerateObject()
.ToDictionary<JsonProperty, string, object>(
p => p.Name,
p => ConvertJsonValue(p.Value) ?? string.Empty
);
}
private static object? ConvertJsonValue(JsonElement element) => element.ValueKind switch
{
JsonValueKind.String => element.GetString(),
JsonValueKind.Number => element.TryGetInt32(out var i) ? i :
element.TryGetInt64(out var l) ? l :
element.TryGetDouble(out var d) ? d :
element.GetDecimal(),
JsonValueKind.True or JsonValueKind.False => element.GetBoolean(),
JsonValueKind.Null => string.Empty,
JsonValueKind.Object => ConvertToDictionary(element),
JsonValueKind.Array => element.EnumerateArray().Select(ConvertJsonValue).ToList(),
_ => string.Empty,
};
}