add Fireworks AI provider support
This commit is contained in:
@@ -8,11 +8,10 @@ namespace Hush.Daemon;
|
||||
|
||||
public class Orchestrator
|
||||
{
|
||||
private static readonly HttpClient _httpClient = new();
|
||||
|
||||
private readonly ConfigManager _configManager;
|
||||
private readonly IAudioRecorder _recorder;
|
||||
private IAudioToTextProvider? _audioToTextProvider;
|
||||
private ITextStreamingProvider? _textProvider;
|
||||
private ITextInput? _textInput;
|
||||
|
||||
private string? _recordingPath;
|
||||
private DateTime? _recordingStartTime;
|
||||
@@ -149,9 +148,19 @@ public class Orchestrator
|
||||
var provider = GetTextProvider(config);
|
||||
|
||||
var prompt = $"""
|
||||
Process this spoken text for clarity and correctness. Fix any errors, add proper punctuation, and make it read naturally. Keep the original meaning intact.
|
||||
You are a transcription post-processor. Your task is to clean up raw speech-to-text output and return polished, ready-to-type text.
|
||||
|
||||
Text: {text}
|
||||
Rules:
|
||||
- Detect the language of the transcription and process it entirely in that language — do not translate
|
||||
- Fix grammar, spelling, and punctuation errors introduced by the speech recognizer, following the conventions of the detected language
|
||||
- Capitalize sentences and proper nouns appropriately for the detected language
|
||||
- Remove filler words and false starts appropriate to the detected language (e.g. "um", "uh", "like" in English; "euh", "bah" in French; "äh", "ähm" in German; "eh", "tipo" in Spanish/Italian)
|
||||
- Preserve the speaker's original intent, vocabulary choices, and tone
|
||||
- Do not add, remove, or reinterpret content beyond what was said
|
||||
- Do not include any explanation, preamble, or metadata — output only the corrected text
|
||||
- If the input is empty or unintelligible, return an empty string
|
||||
|
||||
Raw transcription: {text}
|
||||
""";
|
||||
|
||||
return await provider.CompleteTextAsync(prompt, config.LlmModel);
|
||||
@@ -163,51 +172,36 @@ public class Orchestrator
|
||||
await input.TypeString(text);
|
||||
}
|
||||
|
||||
private IAudioToTextProvider GetAudioToTextProvider(HushConfig config)
|
||||
{
|
||||
if (_audioToTextProvider != null)
|
||||
return _audioToTextProvider;
|
||||
|
||||
_audioToTextProvider = config.WhisperProvider switch
|
||||
private IAudioToTextProvider GetAudioToTextProvider(HushConfig config) =>
|
||||
config.WhisperProvider switch
|
||||
{
|
||||
"groq" => string.IsNullOrEmpty(config.GroqApiKey)
|
||||
"groq" => string.IsNullOrEmpty(config.GroqApiKey)
|
||||
? throw new InvalidOperationException("Groq API key is required for Whisper transcription")
|
||||
: new GroqProvider(config.GroqApiKey),
|
||||
: new GroqProvider(config.GroqApiKey, _httpClient),
|
||||
"fireworks" => string.IsNullOrEmpty(config.FireworksApiKey)
|
||||
? throw new InvalidOperationException("Fireworks API key is required for Whisper transcription")
|
||||
: new FireworksProvider(config.FireworksApiKey, _httpClient),
|
||||
_ => throw new InvalidOperationException($"Unsupported Whisper provider: {config.WhisperProvider}")
|
||||
};
|
||||
|
||||
return _audioToTextProvider;
|
||||
}
|
||||
|
||||
private ITextStreamingProvider GetTextProvider(HushConfig config)
|
||||
{
|
||||
if (_textProvider != null)
|
||||
return _textProvider;
|
||||
|
||||
_textProvider = config.LlmProvider switch
|
||||
private ITextStreamingProvider GetTextProvider(HushConfig config) =>
|
||||
config.LlmProvider switch
|
||||
{
|
||||
"groq" => string.IsNullOrEmpty(config.GroqApiKey)
|
||||
? throw new InvalidOperationException("Groq API key is required for LLM")
|
||||
: new GroqProvider(config.GroqApiKey),
|
||||
: new GroqProvider(config.GroqApiKey, _httpClient),
|
||||
"fireworks" => string.IsNullOrEmpty(config.FireworksApiKey)
|
||||
? throw new InvalidOperationException("Fireworks API key is required for LLM")
|
||||
: new FireworksProvider(config.FireworksApiKey, _httpClient),
|
||||
_ => throw new InvalidOperationException($"Unsupported LLM provider: {config.LlmProvider}")
|
||||
};
|
||||
|
||||
return _textProvider;
|
||||
}
|
||||
|
||||
private ITextInput GetTextInput(HushConfig config)
|
||||
{
|
||||
if (_textInput != null)
|
||||
return _textInput;
|
||||
|
||||
_textInput = config.TypingBackend switch
|
||||
private static ITextInput GetTextInput(HushConfig config) =>
|
||||
config.TypingBackend switch
|
||||
{
|
||||
"xdotool" => new XdotoolInput(),
|
||||
_ => new WtypeInput()
|
||||
};
|
||||
|
||||
return _textInput;
|
||||
}
|
||||
|
||||
private IAudioRecorder CreateAudioRecorder()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user