45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
namespace MealPlan.Api.Services.AI;
|
|
|
|
public enum OpenAiUseCase
|
|
{
|
|
Default,
|
|
Macros,
|
|
Plan,
|
|
Recipe,
|
|
}
|
|
|
|
public class OpenAiOptions
|
|
{
|
|
public const string SectionName = "OpenAI";
|
|
|
|
public string ApiKey { get; set; } = string.Empty;
|
|
|
|
/// <summary>Fallback when a task-specific model is not set.</summary>
|
|
public string Model { get; set; } = "gpt-4.1-mini";
|
|
|
|
/// <summary>Macro target refinement (diet generator step 2).</summary>
|
|
public string? MacrosModel { get; set; }
|
|
|
|
/// <summary>Weekly meal plan recipe selection (diet generator step 3).</summary>
|
|
public string? PlanModel { get; set; }
|
|
|
|
/// <summary>AI recipe draft generation and partial regen.</summary>
|
|
public string? RecipeModel { get; set; }
|
|
|
|
public int MaxTokens { get; set; } = 4096;
|
|
|
|
public bool IsConfigured => !string.IsNullOrWhiteSpace(ApiKey);
|
|
|
|
public string ResolveModel(OpenAiUseCase useCase) =>
|
|
useCase switch
|
|
{
|
|
OpenAiUseCase.Macros => FirstNonEmpty(MacrosModel, Model),
|
|
OpenAiUseCase.Plan => FirstNonEmpty(PlanModel, Model),
|
|
OpenAiUseCase.Recipe => FirstNonEmpty(RecipeModel, Model),
|
|
_ => Model,
|
|
};
|
|
|
|
private static string FirstNonEmpty(string? preferred, string fallback) =>
|
|
string.IsNullOrWhiteSpace(preferred) ? fallback : preferred;
|
|
}
|