2024-07-25 13:29:44 +00:00
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
|
|
using AIStudio.Chat;
|
2025-09-03 08:08:04 +00:00
|
|
|
using AIStudio.Provider.OpenAI;
|
2025-01-02 13:50:54 +00:00
|
|
|
using AIStudio.Settings;
|
2024-07-25 13:29:44 +00:00
|
|
|
|
|
|
|
|
namespace AIStudio.Provider.Fireworks;
|
|
|
|
|
|
2025-12-30 17:30:32 +00:00
|
|
|
public class ProviderFireworks() : BaseProvider(LLMProviders.FIREWORKS, "https://api.fireworks.ai/inference/v1/", LOGGER)
|
2024-07-25 13:29:44 +00:00
|
|
|
{
|
2025-09-03 19:25:17 +00:00
|
|
|
private static readonly ILogger<ProviderFireworks> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderFireworks>();
|
|
|
|
|
|
2024-07-25 13:29:44 +00:00
|
|
|
#region Implementation of IProvider
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2024-12-03 14:24:40 +00:00
|
|
|
public override string Id => LLMProviders.FIREWORKS.ToName();
|
2024-07-25 13:29:44 +00:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2024-12-03 14:24:40 +00:00
|
|
|
public override string InstanceName { get; set; } = "Fireworks.ai";
|
2024-07-25 13:29:44 +00:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2025-08-31 12:27:35 +00:00
|
|
|
public override async IAsyncEnumerable<ContentStreamChunk> StreamChatCompletion(Model chatModel, ChatThread chatThread, SettingsManager settingsManager, [EnumeratorCancellation] CancellationToken token = default)
|
2024-07-25 13:29:44 +00:00
|
|
|
{
|
2026-04-13 11:33:17 +00:00
|
|
|
await foreach (var content in this.StreamOpenAICompatibleChatCompletion<ChatCompletionAPIRequest, ResponseStreamLine, ChatCompletionAnnotationStreamLine>(
|
|
|
|
|
"Fireworks",
|
|
|
|
|
chatModel,
|
|
|
|
|
chatThread,
|
|
|
|
|
settingsManager,
|
|
|
|
|
async (systemPrompt, apiParameters) =>
|
|
|
|
|
{
|
|
|
|
|
// Build the list of messages:
|
|
|
|
|
var messages = await chatThread.Blocks.BuildMessagesUsingNestedImageUrlAsync(this.Provider, chatModel);
|
2024-07-25 13:29:44 +00:00
|
|
|
|
2026-04-13 11:33:17 +00:00
|
|
|
return new ChatCompletionAPIRequest
|
|
|
|
|
{
|
|
|
|
|
Model = chatModel.Id,
|
2024-07-25 13:29:44 +00:00
|
|
|
|
2026-04-13 11:33:17 +00:00
|
|
|
// Build the messages:
|
|
|
|
|
// - First of all the system prompt
|
|
|
|
|
// - Then none-empty user and AI messages
|
|
|
|
|
Messages = [systemPrompt, ..messages],
|
2025-01-01 14:49:27 +00:00
|
|
|
|
2026-04-13 11:33:17 +00:00
|
|
|
// Right now, we only support streaming completions:
|
|
|
|
|
Stream = true,
|
|
|
|
|
AdditionalApiParameters = apiParameters
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
token: token))
|
2025-01-04 13:11:32 +00:00
|
|
|
yield return content;
|
2024-07-25 13:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|
|
|
|
|
/// <inheritdoc />
|
2024-12-03 14:24:40 +00:00
|
|
|
public override async IAsyncEnumerable<ImageURL> StreamImageCompletion(Model imageModel, string promptPositive, string promptNegative = FilterOperator.String.Empty, ImageURL referenceImageURL = default, [EnumeratorCancellation] CancellationToken token = default)
|
2024-07-25 13:29:44 +00:00
|
|
|
{
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
|
2026-01-11 15:02:28 +00:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override async Task<string> TranscribeAudioAsync(Model transcriptionModel, string audioFilePath, SettingsManager settingsManager, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var requestedSecret = await RUST_SERVICE.GetAPIKey(this, SecretStoreType.TRANSCRIPTION_PROVIDER);
|
|
|
|
|
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
|
|
|
|
}
|
2026-02-20 14:32:54 +00:00
|
|
|
|
|
|
|
|
/// <inhertidoc />
|
|
|
|
|
public override Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult<IReadOnlyList<IReadOnlyList<float>>>([]);
|
|
|
|
|
}
|
2024-07-25 13:29:44 +00:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2024-12-03 14:24:40 +00:00
|
|
|
public override Task<IEnumerable<Model>> GetTextModels(string? apiKeyProvisional = null, CancellationToken token = default)
|
2024-07-25 13:29:44 +00:00
|
|
|
{
|
|
|
|
|
return Task.FromResult(Enumerable.Empty<Model>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2024-12-03 14:24:40 +00:00
|
|
|
public override Task<IEnumerable<Model>> GetImageModels(string? apiKeyProvisional = null, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(Enumerable.Empty<Model>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override Task<IEnumerable<Model>> GetEmbeddingModels(string? apiKeyProvisional = null, CancellationToken token = default)
|
2024-07-25 13:29:44 +00:00
|
|
|
{
|
|
|
|
|
return Task.FromResult(Enumerable.Empty<Model>());
|
|
|
|
|
}
|
2025-05-11 10:51:35 +00:00
|
|
|
|
2026-01-09 11:45:21 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override Task<IEnumerable<Model>> GetTranscriptionModels(string? apiKeyProvisional = null, CancellationToken token = default)
|
|
|
|
|
{
|
2026-01-11 15:02:28 +00:00
|
|
|
// Source: https://docs.fireworks.ai/api-reference/audio-transcriptions#param-model
|
2026-01-09 11:45:21 +00:00
|
|
|
return Task.FromResult<IEnumerable<Model>>(
|
|
|
|
|
new List<Model>
|
|
|
|
|
{
|
|
|
|
|
new("whisper-v3", "Whisper v3"),
|
2026-01-11 15:02:28 +00:00
|
|
|
// new("whisper-v3-turbo", "Whisper v3 Turbo"), // does not work
|
2026-01-09 11:45:21 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-25 13:29:44 +00:00
|
|
|
#endregion
|
2026-04-13 11:33:17 +00:00
|
|
|
}
|