mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-15 15:01:37 +00:00
Improve transcription API key handling and error logging
This commit is contained in:
parent
332f948b09
commit
74d3dfd3b4
@ -562,14 +562,33 @@ public abstract class BaseProvider : IProvider, ISecretId
|
|||||||
using var request = new HttpRequestMessage(HttpMethod.Post, host.TranscriptionURL());
|
using var request = new HttpRequestMessage(HttpMethod.Post, host.TranscriptionURL());
|
||||||
request.Content = form;
|
request.Content = form;
|
||||||
|
|
||||||
|
// Handle the authorization header based on the provider:
|
||||||
|
switch (this.Provider)
|
||||||
|
{
|
||||||
|
case LLMProviders.SELF_HOSTED:
|
||||||
if(requestedSecret.Success)
|
if(requestedSecret.Success)
|
||||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", await requestedSecret.Secret.Decrypt(ENCRYPTION));
|
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", await requestedSecret.Secret.Decrypt(ENCRYPTION));
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if(!requestedSecret.Success)
|
||||||
|
{
|
||||||
|
this.logger.LogError("No valid API key available for transcription request.");
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
using var response = await this.httpClient.SendAsync(request, token);
|
using var response = await this.httpClient.SendAsync(request, token);
|
||||||
var responseBody = response.Content.ReadAsStringAsync(token).Result;
|
var responseBody = response.Content.ReadAsStringAsync(token).Result;
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
this.logger.LogError("Transcription request failed with status code {ResponseStatusCode} and body: '{ResponseBody}'.", response.StatusCode, responseBody);
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
var transcriptionResponse = JsonSerializer.Deserialize<TranscriptionResponse>(responseBody, JSON_SERIALIZER_OPTIONS);
|
var transcriptionResponse = JsonSerializer.Deserialize<TranscriptionResponse>(responseBody, JSON_SERIALIZER_OPTIONS);
|
||||||
if(transcriptionResponse is null)
|
if(transcriptionResponse is null)
|
||||||
|
|||||||
@ -85,7 +85,7 @@ public class ProviderFireworks() : BaseProvider(LLMProviders.FIREWORKS, "https:/
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<string> TranscribeAudioAsync(Model transcriptionModel, string audioFilePath, SettingsManager settingsManager, CancellationToken token = default)
|
public override async Task<string> TranscribeAudioAsync(Model transcriptionModel, string audioFilePath, SettingsManager settingsManager, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var requestedSecret = await RUST_SERVICE.GetAPIKey(this, isTrying: true);
|
var requestedSecret = await RUST_SERVICE.GetAPIKey(this);
|
||||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -84,7 +84,7 @@ public sealed class ProviderGWDG() : BaseProvider(LLMProviders.GWDG, "https://ch
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<string> TranscribeAudioAsync(Model transcriptionModel, string audioFilePath, SettingsManager settingsManager, CancellationToken token = default)
|
public override async Task<string> TranscribeAudioAsync(Model transcriptionModel, string audioFilePath, SettingsManager settingsManager, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var requestedSecret = await RUST_SERVICE.GetAPIKey(this, isTrying: true);
|
var requestedSecret = await RUST_SERVICE.GetAPIKey(this);
|
||||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -85,7 +85,7 @@ public sealed class ProviderMistral() : BaseProvider(LLMProviders.MISTRAL, "http
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<string> TranscribeAudioAsync(Provider.Model transcriptionModel, string audioFilePath, SettingsManager settingsManager, CancellationToken token = default)
|
public override async Task<string> TranscribeAudioAsync(Provider.Model transcriptionModel, string audioFilePath, SettingsManager settingsManager, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var requestedSecret = await RUST_SERVICE.GetAPIKey(this, isTrying: true);
|
var requestedSecret = await RUST_SERVICE.GetAPIKey(this);
|
||||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -221,7 +221,7 @@ public sealed class ProviderOpenAI() : BaseProvider(LLMProviders.OPEN_AI, "https
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<string> TranscribeAudioAsync(Model transcriptionModel, string audioFilePath, SettingsManager settingsManager, CancellationToken token = default)
|
public override async Task<string> TranscribeAudioAsync(Model transcriptionModel, string audioFilePath, SettingsManager settingsManager, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var requestedSecret = await RUST_SERVICE.GetAPIKey(this, isTrying: true);
|
var requestedSecret = await RUST_SERVICE.GetAPIKey(this);
|
||||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user