efc4e9dadf
- Normalize IF/Abs/Pow/etc. to lowercase before evaluation so AI-generated or manually typed uppercase function names no longer cause "Function not found" errors - Add NormalizeAndValidate() which normalizes then does a parse-only check on save — invalid formulas are rejected with a clear error before storing - Update AI system prompt to list all functions in lowercase and explicitly call out case-sensitivity; add if() to the supported function list - Add collapsible NCalc quick-reference panel in the formula editor showing all operators, functions (lowercase), built-in variables, and an example Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31 lines
1.3 KiB
C#
31 lines
1.3 KiB
C#
using PowderCoating.Application.DTOs.Company;
|
|
|
|
namespace PowderCoating.Application.Interfaces;
|
|
|
|
public interface ICustomFormulaAiService
|
|
{
|
|
/// <summary>
|
|
/// Generates a NCalc formula, field list, and notes from a natural-language description
|
|
/// and an optional diagram image. Returns a <see cref="GenerateFormulaFromAiResponse"/>
|
|
/// ready to pre-fill the template editor.
|
|
/// </summary>
|
|
Task<GenerateFormulaFromAiResponse> GenerateFormulaAsync(
|
|
GenerateFormulaFromAiRequest request,
|
|
byte[]? imageBytes = null,
|
|
string? imageContentType = null);
|
|
|
|
/// <summary>
|
|
/// Evaluates a NCalc formula with the supplied variable map and returns the numeric result.
|
|
/// Safe server-side only — no user-controlled code execution.
|
|
/// </summary>
|
|
EvaluateFormulaResponse EvaluateFormula(EvaluateFormulaRequest request);
|
|
|
|
/// <summary>
|
|
/// Normalizes NCalc built-in function names to lowercase (IF→if, Abs→abs, etc.) then
|
|
/// attempts a parse-only evaluation to catch syntax errors before the formula is saved.
|
|
/// Returns the normalized formula string and a null error on success, or the original
|
|
/// formula and an error message on failure.
|
|
/// </summary>
|
|
(string NormalizedFormula, string? Error) NormalizeAndValidate(string formula);
|
|
}
|