improve formatting
This commit is contained in:
@@ -33,7 +33,11 @@ public class DaemonService
|
|||||||
|
|
||||||
if (File.Exists(socketPath))
|
if (File.Exists(socketPath))
|
||||||
{
|
{
|
||||||
try { File.Delete(socketPath); } catch { }
|
try { File.Delete(socketPath); }
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var configManager = new ConfigManager();
|
var configManager = new ConfigManager();
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using System.Text;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Hush.Providers.Interfaces;
|
using Hush.Providers.Interfaces;
|
||||||
using Hush.Providers.Models.Request;
|
using Hush.Providers.Models.Request;
|
||||||
using Hush.Providers.Models.Response;
|
|
||||||
using Hush.Providers.Serialization;
|
using Hush.Providers.Serialization;
|
||||||
|
|
||||||
namespace Hush.Providers.Providers;
|
namespace Hush.Providers.Providers;
|
||||||
@@ -13,8 +12,8 @@ namespace Hush.Providers.Providers;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class GroqProvider : IAudioToTextProvider, ITextStreamingProvider
|
public class GroqProvider : IAudioToTextProvider, ITextStreamingProvider
|
||||||
{
|
{
|
||||||
private const string ChatCompletionEndpoint = "https://api.groq.com/openai/v1/chat/completions";
|
private const string CHAT_COMPLETION_ENDPOINT = "https://api.groq.com/openai/v1/chat/completions";
|
||||||
private const string TranscriptionEndpoint = "https://api.groq.com/openai/v1/audio/transcriptions";
|
private const string TRANSCRIPTION_ENDPOINT = "https://api.groq.com/openai/v1/audio/transcriptions";
|
||||||
|
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
private readonly string _apiKey;
|
private readonly string _apiKey;
|
||||||
@@ -36,8 +35,7 @@ public class GroqProvider : IAudioToTextProvider, ITextStreamingProvider
|
|||||||
string modelName,
|
string modelName,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (audioStream == null)
|
ArgumentNullException.ThrowIfNull(audioStream);
|
||||||
throw new ArgumentNullException(nameof(audioStream));
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(modelName))
|
if (string.IsNullOrWhiteSpace(modelName))
|
||||||
throw new ArgumentException("Model name is required", nameof(modelName));
|
throw new ArgumentException("Model name is required", nameof(modelName));
|
||||||
@@ -56,7 +54,7 @@ public class GroqProvider : IAudioToTextProvider, ITextStreamingProvider
|
|||||||
if (request.Temperature.HasValue)
|
if (request.Temperature.HasValue)
|
||||||
content.Add(new StringContent(request.Temperature.Value.ToString(System.Globalization.CultureInfo.InvariantCulture)), "temperature");
|
content.Add(new StringContent(request.Temperature.Value.ToString(System.Globalization.CultureInfo.InvariantCulture)), "temperature");
|
||||||
|
|
||||||
var httpRequest = new HttpRequestMessage(HttpMethod.Post, TranscriptionEndpoint)
|
var httpRequest = new HttpRequestMessage(HttpMethod.Post, TRANSCRIPTION_ENDPOINT)
|
||||||
{
|
{
|
||||||
Content = content
|
Content = content
|
||||||
};
|
};
|
||||||
@@ -94,7 +92,7 @@ public class GroqProvider : IAudioToTextProvider, ITextStreamingProvider
|
|||||||
var request = new ChatCompletionRequest
|
var request = new ChatCompletionRequest
|
||||||
{
|
{
|
||||||
Model = modelName,
|
Model = modelName,
|
||||||
Messages = new List<Hush.Providers.Models.Request.Message> { new Hush.Providers.Models.Request.Message { Role = "user", Content = prompt } }
|
Messages = new List<Models.Request.Message> { new() { Role = "user", Content = prompt } }
|
||||||
};
|
};
|
||||||
|
|
||||||
var jsonContent = new StringContent(
|
var jsonContent = new StringContent(
|
||||||
@@ -102,7 +100,7 @@ public class GroqProvider : IAudioToTextProvider, ITextStreamingProvider
|
|||||||
Encoding.UTF8,
|
Encoding.UTF8,
|
||||||
"application/json");
|
"application/json");
|
||||||
|
|
||||||
var httpRequest = new HttpRequestMessage(HttpMethod.Post, ChatCompletionEndpoint)
|
var httpRequest = new HttpRequestMessage(HttpMethod.Post, CHAT_COMPLETION_ENDPOINT)
|
||||||
{
|
{
|
||||||
Content = jsonContent
|
Content = jsonContent
|
||||||
};
|
};
|
||||||
@@ -139,7 +137,7 @@ public class GroqProvider : IAudioToTextProvider, ITextStreamingProvider
|
|||||||
{
|
{
|
||||||
Model = modelName,
|
Model = modelName,
|
||||||
Stream = true,
|
Stream = true,
|
||||||
Messages = new List<Hush.Providers.Models.Request.Message> { new Hush.Providers.Models.Request.Message { Role = "user", Content = prompt } }
|
Messages = new List<Models.Request.Message> { new() { Role = "user", Content = prompt } }
|
||||||
};
|
};
|
||||||
|
|
||||||
var jsonContent = new StringContent(
|
var jsonContent = new StringContent(
|
||||||
@@ -147,7 +145,7 @@ public class GroqProvider : IAudioToTextProvider, ITextStreamingProvider
|
|||||||
Encoding.UTF8,
|
Encoding.UTF8,
|
||||||
"application/json");
|
"application/json");
|
||||||
|
|
||||||
var httpRequest = new HttpRequestMessage(HttpMethod.Post, ChatCompletionEndpoint)
|
var httpRequest = new HttpRequestMessage(HttpMethod.Post, CHAT_COMPLETION_ENDPOINT)
|
||||||
{
|
{
|
||||||
Content = jsonContent
|
Content = jsonContent
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user