2024-05-04 10:58:18 +02:00
using AIStudio.Chat ;
2025-01-02 14:50:54 +01:00
using AIStudio.Settings ;
2024-05-04 10:58:18 +02:00
2024-04-20 17:06:50 +02:00
namespace AIStudio.Provider ;
2024-05-04 10:55:00 +02:00
/// <summary>
/// A common interface for all providers.
/// </summary>
2024-04-20 17:06:50 +02:00
public interface IProvider
{
2025-12-30 18:30:32 +01:00
/// <summary>
/// The provider type.
/// </summary>
public LLMProviders Provider { get ; }
2024-05-04 10:55:00 +02:00
/// <summary>
/// The provider's ID.
/// </summary>
2024-04-20 17:06:50 +02:00
public string Id { get ; }
2026-06-21 15:16:37 +02:00
/// <summary>
/// The ID of the configured provider instance.
/// </summary>
public string ConfiguredProviderId { get ; }
2024-05-04 10:55:00 +02:00
/// <summary>
/// The provider's instance name. Useful for multiple instances of the same provider,
/// e.g., to distinguish between different OpenAI API keys.
/// </summary>
2024-12-03 15:24:40 +01:00
public string InstanceName { get ; }
2024-04-20 17:06:50 +02:00
2025-11-13 18:13:16 +01:00
/// <summary>
/// The additional API parameters.
/// </summary>
public string AdditionalJsonApiParameters { get ; }
2026-04-16 11:24:22 +02:00
2026-09-09 18:43:37 +02:00
/// <summary>
/// The tokenizer path associated with this provider configuration.
/// </summary>
public string TokenizerPath { get ; }
2026-04-16 11:24:22 +02:00
/// <summary>
/// Whether this provider instance can load available models from the backend/API.
/// This capability may differ by provider type, host, or modality.
/// </summary>
public bool HasModelLoadingCapability { get ; }
2025-11-13 18:13:16 +01:00
2024-05-04 10:58:18 +02:00
/// <summary>
/// Starts a chat completion stream.
/// </summary>
/// <param name="chatModel">The model to use for chat completion.</param>
/// <param name="chatThread">The chat thread to continue.</param>
2025-01-02 14:50:54 +01:00
/// <param name="settingsManager">The settings manager instance to use.</param>
2024-05-04 10:58:18 +02:00
/// <param name="token">The cancellation token.</param>
/// <returns>The chat completion stream.</returns>
2025-08-31 14:27:35 +02:00
public IAsyncEnumerable < ContentStreamChunk > StreamChatCompletion ( Model chatModel , ChatThread chatThread , SettingsManager settingsManager , CancellationToken token = default );
2024-05-04 10:58:18 +02:00
/// <summary>
/// Starts an image completion stream.
/// </summary>
/// <param name="imageModel">The model to use for image completion.</param>
/// <param name="promptPositive">The positive prompt.</param>
/// <param name="promptNegative">The negative prompt.</param>
/// <param name="referenceImageURL">The reference image URL.</param>
/// <param name="token">The cancellation token.</param>
/// <returns>The image completion stream.</returns>
2024-09-01 20:10:03 +02:00
public IAsyncEnumerable < ImageURL > StreamImageCompletion ( Model imageModel , string promptPositive , string promptNegative = FilterOperator . String . Empty , ImageURL referenceImageURL = default , CancellationToken token = default );
2024-04-20 17:06:50 +02:00
2026-01-11 16:02:28 +01:00
/// <summary>
/// Transcribe an audio file.
/// </summary>
/// <param name="transcriptionModel">The model to use for transcription.</param>
/// <param name="audioFilePath">The audio file path.</param>
/// <param name="settingsManager">The settings manager instance to use.</param>
/// <param name="token">The cancellation token.</param>
/// <returns>>The transcription result.</returns>
2026-05-23 11:25:18 +02:00
public Task < TranscriptionResult > TranscribeAudioAsync ( Model transcriptionModel , string audioFilePath , SettingsManager settingsManager , CancellationToken token = default );
2026-02-20 15:32:54 +01:00
/// <summary>
/// Embed a text file.
/// </summary>
2026-09-04 15:48:07 +02:00
/// <remarks>
/// The cancellation token is not the last parameter, unlike everywhere else in this codebase:
/// C# demands that a params parameter comes last, and every implementation inherits that order.
/// </remarks>
2026-02-20 15:32:54 +01:00
/// <param name="embeddingModel">The model to use for embedding.</param>
/// <param name="settingsManager">The settings manager instance to use.</param>
/// <param name="token">The cancellation token.</param>
2026-09-04 15:48:07 +02:00
/// <param name="texts">A single string or a list of strings to embed.</param>
2026-02-20 15:32:54 +01:00
/// <returns>>The embedded text as a single vector or as a list of vectors.</returns>
public Task < IReadOnlyList < IReadOnlyList < float >>> EmbedTextAsync ( Model embeddingModel , SettingsManager settingsManager , CancellationToken token = default , params List < string > texts );
2026-01-11 16:02:28 +01:00
2024-05-04 10:58:18 +02:00
/// <summary>
/// Load all possible text models that can be used with this provider.
/// </summary>
2024-06-03 19:42:53 +02:00
/// <param name="apiKeyProvisional">The provisional API key to use. Useful when the user is adding a new provider. When null, the stored API key is used.</param>
2024-05-04 10:58:18 +02:00
/// <param name="token">The cancellation token.</param>
/// <returns>The list of text models.</returns>
2026-04-14 13:39:11 +02:00
public Task < ModelLoadResult > GetTextModels ( string? apiKeyProvisional = null , CancellationToken token = default );
2024-06-03 19:42:53 +02:00
2024-05-04 10:58:18 +02:00
/// <summary>
/// Load all possible image models that can be used with this provider.
/// </summary>
2024-06-03 19:42:53 +02:00
/// <param name="apiKeyProvisional">The provisional API key to use. Useful when the user is adding a new provider. When null, the stored API key is used.</param>
2024-05-04 10:58:18 +02:00
/// <param name="token">The cancellation token.</param>
/// <returns>The list of image models.</returns>
2026-04-14 13:39:11 +02:00
public Task < ModelLoadResult > GetImageModels ( string? apiKeyProvisional = null , CancellationToken token = default );
2024-12-03 15:24:40 +01:00
/// <summary>
/// Load all possible embedding models that can be used with this provider.
/// </summary>
/// <param name="apiKeyProvisional">The provisional API key to use. Useful when the user is adding a new provider. When null, the stored API key is used.</param>
/// <param name="token">The cancellation token.</param>
/// <returns>The list of embedding models.</returns>
2026-04-14 13:39:11 +02:00
public Task < ModelLoadResult > GetEmbeddingModels ( string? apiKeyProvisional = null , CancellationToken token = default );
2025-05-11 12:51:35 +02:00
2026-01-09 12:45:21 +01:00
/// <summary>
/// Load all possible transcription models that can be used with this provider.
/// </summary>
/// <param name="apiKeyProvisional">The provisional API key to use. Useful when the user is adding a new provider. When null, the stored API key is used.</param>
/// <param name="token">>The cancellation token.</param>
/// <returns>>The list of transcription models.</returns>
2026-04-14 13:39:11 +02:00
public Task < ModelLoadResult > GetTranscriptionModels ( string? apiKeyProvisional = null , CancellationToken token = default );
2024-04-20 17:06:50 +02:00
}