diff --git a/DotPrompt.Sql.Cli/DotPrompt.Sql.Cli.csproj b/DotPrompt.Sql.Cli/DotPrompt.Sql.Cli.csproj
index 40b513c..49c9587 100644
--- a/DotPrompt.Sql.Cli/DotPrompt.Sql.Cli.csproj
+++ b/DotPrompt.Sql.Cli/DotPrompt.Sql.Cli.csproj
@@ -26,7 +26,7 @@
-
+
diff --git a/DotPrompt.Sql.Test/TestSqlPromptEntity.cs b/DotPrompt.Sql.Test/TestSqlPromptEntity.cs
index 4785049..f8e86d1 100644
--- a/DotPrompt.Sql.Test/TestSqlPromptEntity.cs
+++ b/DotPrompt.Sql.Test/TestSqlPromptEntity.cs
@@ -81,16 +81,17 @@ public async Task AddSqlPrompt_ValidPrompt_InsertsSuccessfully()
Model = "gpt4",
OutputFormat = "json",
MaxTokens = 500,
+ Temperature = 0.7f,
SystemPrompt = "Optimize SQL queries.",
UserPrompt = "Suggest indexing improvements.",
Parameters = new Dictionary
{
- { "Temperature", "0.7" },
- { "TopP", "0.9" }
+ { "query", "string" },
+ { "topP", "number" }
},
Default = new Dictionary
{
- { "Temperature", "0.5" }
+ { "topP", "0.9" }
}
};
@@ -111,16 +112,17 @@ public async Task AddSqlPrompt_SamePromptNoChanges_DoesNotInsertNewVersion()
Model = "gpt4",
OutputFormat = "json",
MaxTokens = 200,
+ Temperature = 0.5f,
SystemPrompt = "Optimize SQL queries.",
UserPrompt = "Suggest indexing improvements.",
Parameters = new Dictionary
{
- { "Temperature", "0.7" },
- { "TopP", "0.9" }
+ { "query", "string" },
+ { "topP", "number" }
},
Default = new Dictionary
{
- { "Temperature", "0.5" }
+ { "topP", "0.9" }
}
};
@@ -145,8 +147,8 @@ public async Task AddSqlPrompt_WhenMaxTokensChanges_ShouldInsertNewVersion()
MaxTokens = 500,
SystemPrompt = "Optimize SQL queries.",
UserPrompt = "Suggest indexing improvements.",
- Parameters = new Dictionary { { "Temperature", "0.7" } },
- Default = new Dictionary { { "Temperature", "0.5" } }
+ Parameters = new Dictionary { { "query", "string" } },
+ Default = new Dictionary { { "query", "SELECT 1" } }
};
var entity2 = new SqlPromptEntity
@@ -157,8 +159,8 @@ public async Task AddSqlPrompt_WhenMaxTokensChanges_ShouldInsertNewVersion()
MaxTokens = 512, // Changed value
SystemPrompt = "Optimize SQL queries.",
UserPrompt = "Suggest indexing improvements.",
- Parameters = new Dictionary { { "Temperature", "0.7" } },
- Default = new Dictionary { { "Temperature", "0.5" } }
+ Parameters = new Dictionary { { "query", "string" } },
+ Default = new Dictionary { { "query", "SELECT 1" } }
};
await _repository.AddSqlPrompt(entity1); // Insert first version
@@ -182,8 +184,8 @@ public async Task GetSqlPromptByName_GivenTwoPromptsOfTheSameNameAreAdded_Should
MaxTokens = 500,
SystemPrompt = "Optimize SQL queries.",
UserPrompt = "Suggest indexing improvements.",
- Parameters = new Dictionary { { "Temperature", "0.7" } },
- Default = new Dictionary { { "Temperature", "0.5" } }
+ Parameters = new Dictionary { { "query", "string" } },
+ Default = new Dictionary { { "query", "SELECT 1" } }
};
var entity2 = new SqlPromptEntity
@@ -194,8 +196,8 @@ public async Task GetSqlPromptByName_GivenTwoPromptsOfTheSameNameAreAdded_Should
MaxTokens = 512, // Changed value
SystemPrompt = "Optimize SQL queries 2.", // changed value
UserPrompt = "Suggest indexing improvements.",
- Parameters = new Dictionary { { "Temperature", "0.7" } },
- Default = new Dictionary { { "Temperature", "0.5" } }
+ Parameters = new Dictionary { { "query", "string" } },
+ Default = new Dictionary { { "query", "SELECT 1" } }
};
await _repository.AddSqlPrompt(entity1); // Insert first version
diff --git a/DotPrompt.Sql/DotPrompt.Sql.csproj b/DotPrompt.Sql/DotPrompt.Sql.csproj
index d26a7b7..387c50a 100644
--- a/DotPrompt.Sql/DotPrompt.Sql.csproj
+++ b/DotPrompt.Sql/DotPrompt.Sql.csproj
@@ -27,7 +27,7 @@
-
+
diff --git a/DotPrompt.Sql/Resources/SqlQueries/AddSqlPrompt.sql b/DotPrompt.Sql/Resources/SqlQueries/AddSqlPrompt.sql
index 87912a7..89ab57d 100644
--- a/DotPrompt.Sql/Resources/SqlQueries/AddSqlPrompt.sql
+++ b/DotPrompt.Sql/Resources/SqlQueries/AddSqlPrompt.sql
@@ -2,9 +2,12 @@ CREATE OR ALTER PROCEDURE sp_AddSqlPrompt
@PromptName VARCHAR(255),
@Model VARCHAR(255),
@OutputFormat VARCHAR(255),
+ @OutputSchema NVARCHAR(MAX),
@MaxTokens INT,
+ @Temperature FLOAT,
@SystemPrompt NVARCHAR(MAX),
@UserPrompt NVARCHAR(MAX),
+ @FewShots NVARCHAR(MAX),
@Parameters PromptParameterType READONLY, -- Table-Valued Parameter
@Defaults ParameterDefaultType READONLY, -- Table-Valued Parameter
@IsNewVersion BIT OUTPUT -- New Output Parameter
@@ -34,9 +37,12 @@ SET @NewVersion = ISNULL(@ExistingVersion, 0) + 1;
WHERE PromptId = @ExistingPromptId
AND Model = @Model
AND OutputFormat = @OutputFormat
- AND MaxTokens = @MaxTokens
+ AND (OutputSchema = @OutputSchema OR (OutputSchema IS NULL AND @OutputSchema IS NULL))
+ AND (MaxTokens = @MaxTokens OR (MaxTokens IS NULL AND @MaxTokens IS NULL))
+ AND (Temperature = @Temperature OR (Temperature IS NULL AND @Temperature IS NULL))
AND SystemPrompt = @SystemPrompt
AND UserPrompt = @UserPrompt
+ AND (FewShots = @FewShots OR (FewShots IS NULL AND @FewShots IS NULL))
)
OR EXISTS (
-- Parameters changed?
@@ -64,8 +70,8 @@ SET @NewVersion = ISNULL(@ExistingVersion, 0) + 1;
)
BEGIN
-- Insert new version of the prompt
-INSERT INTO PromptFile (PromptName, VersionNumber, CreatedAt, ModifiedAt, Model, OutputFormat, MaxTokens, SystemPrompt, UserPrompt)
-VALUES (@PromptName, @NewVersion, GETUTCDATE(), GETUTCDATE(), @Model, @OutputFormat, @MaxTokens, @SystemPrompt, @UserPrompt);
+INSERT INTO PromptFile (PromptName, VersionNumber, CreatedAt, ModifiedAt, Model, OutputFormat, OutputSchema, MaxTokens, Temperature, SystemPrompt, UserPrompt, FewShots)
+VALUES (@PromptName, @NewVersion, GETUTCDATE(), GETUTCDATE(), @Model, @OutputFormat, @OutputSchema, @MaxTokens, @Temperature, @SystemPrompt, @UserPrompt, @FewShots);
SET @NewPromptId = SCOPE_IDENTITY();
diff --git a/DotPrompt.Sql/Resources/SqlQueries/CreateDefaultPromptTables.sql b/DotPrompt.Sql/Resources/SqlQueries/CreateDefaultPromptTables.sql
index 4ec0843..3569c66 100644
--- a/DotPrompt.Sql/Resources/SqlQueries/CreateDefaultPromptTables.sql
+++ b/DotPrompt.Sql/Resources/SqlQueries/CreateDefaultPromptTables.sql
@@ -9,9 +9,12 @@ CREATE TABLE PromptFile (
ModifiedAt DATETIMEOFFSET NULL,
Model VARCHAR(255) NULL,
OutputFormat VARCHAR(255) NOT NULL DEFAULT '',
- MaxTokens INT NOT NULL,
+ OutputSchema NVARCHAR(MAX) NULL,
+ MaxTokens INT NULL,
+ Temperature FLOAT NULL,
SystemPrompt NVARCHAR(MAX) NOT NULL DEFAULT '',
UserPrompt NVARCHAR(MAX) NOT NULL DEFAULT '',
+ FewShots NVARCHAR(MAX) NULL,
CONSTRAINT UQ_PromptName_Version UNIQUE (PromptName, VersionNumber)
);
END;
@@ -27,6 +30,33 @@ ALTER TABLE PromptFile ADD CONSTRAINT UQ_PromptName_Version UNIQUE (PromptName,
END;
END;
+-- Add OutputSchema column to PromptFile (if not exists)
+IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'PromptFile' AND COLUMN_NAME = 'OutputSchema')
+BEGIN
+ALTER TABLE PromptFile ADD OutputSchema NVARCHAR(MAX) NULL;
+END;
+
+-- Make MaxTokens nullable (if currently NOT NULL)
+IF EXISTS (
+ SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
+ WHERE TABLE_NAME = 'PromptFile' AND COLUMN_NAME = 'MaxTokens' AND IS_NULLABLE = 'NO'
+)
+BEGIN
+ALTER TABLE PromptFile ALTER COLUMN MaxTokens INT NULL;
+END;
+
+-- Add Temperature column to PromptFile (if not exists)
+IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'PromptFile' AND COLUMN_NAME = 'Temperature')
+BEGIN
+ALTER TABLE PromptFile ADD Temperature FLOAT NULL;
+END;
+
+-- Add FewShots column to PromptFile (if not exists)
+IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'PromptFile' AND COLUMN_NAME = 'FewShots')
+BEGIN
+ALTER TABLE PromptFile ADD FewShots NVARCHAR(MAX) NULL;
+END;
+
-- Create the PromptParameters table if it doesn't exist
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'PromptParameters')
BEGIN
diff --git a/DotPrompt.Sql/Resources/SqlQueries/GetLatestPromptByName.sql b/DotPrompt.Sql/Resources/SqlQueries/GetLatestPromptByName.sql
index 1cfa6ec..65c05c2 100644
--- a/DotPrompt.Sql/Resources/SqlQueries/GetLatestPromptByName.sql
+++ b/DotPrompt.Sql/Resources/SqlQueries/GetLatestPromptByName.sql
@@ -7,9 +7,12 @@ WITH LatestPrompts AS (
ModifiedAt,
Model,
OutputFormat,
+ OutputSchema,
MaxTokens,
+ Temperature,
SystemPrompt,
UserPrompt,
+ FewShots,
ROW_NUMBER() OVER (PARTITION BY PromptName ORDER BY VersionNumber DESC) AS RowNum
FROM PromptFile
)
@@ -21,8 +24,11 @@ SELECT
lp.ModifiedAt,
lp.Model,
lp.OutputFormat,
+ lp.OutputSchema,
lp.MaxTokens,
+ lp.Temperature,
lp.SystemPrompt,
- lp.UserPrompt
+ lp.UserPrompt,
+ lp.FewShots
FROM LatestPrompts lp
WHERE lp.PromptName = @PromptName AND lp.RowNum = 1;
\ No newline at end of file
diff --git a/DotPrompt.Sql/Resources/SqlQueries/InsertPromptFile.sql b/DotPrompt.Sql/Resources/SqlQueries/InsertPromptFile.sql
index cc0c2b6..251adb3 100644
--- a/DotPrompt.Sql/Resources/SqlQueries/InsertPromptFile.sql
+++ b/DotPrompt.Sql/Resources/SqlQueries/InsertPromptFile.sql
@@ -1,3 +1,3 @@
-INSERT INTO PromptFile (PromptName, CreatedAt, ModifiedAt, Model, OutputFormat, MaxTokens, SystemPrompt, UserPrompt)
+INSERT INTO PromptFile (PromptName, CreatedAt, ModifiedAt, Model, OutputFormat, OutputSchema, MaxTokens, Temperature, SystemPrompt, UserPrompt, FewShots)
OUTPUT INSERTED.PromptId
-VALUES (@PromptName, @CreatedAt, @ModifiedAt, @Model, @OutputFormat, @MaxTokens, @SystemPrompt, @UserPrompt)
\ No newline at end of file
+VALUES (@PromptName, @CreatedAt, @ModifiedAt, @Model, @OutputFormat, @OutputSchema, @MaxTokens, @Temperature, @SystemPrompt, @UserPrompt, @FewShots)
\ No newline at end of file
diff --git a/DotPrompt.Sql/Resources/SqlQueries/LoadPrompts.sql b/DotPrompt.Sql/Resources/SqlQueries/LoadPrompts.sql
index 0b0865e..6f22dac 100644
--- a/DotPrompt.Sql/Resources/SqlQueries/LoadPrompts.sql
+++ b/DotPrompt.Sql/Resources/SqlQueries/LoadPrompts.sql
@@ -6,9 +6,12 @@ WITH LatestPrompts AS (
ModifiedAt,
Model,
OutputFormat,
+ OutputSchema,
MaxTokens,
+ Temperature,
SystemPrompt,
UserPrompt,
+ FewShots,
VersionNumber,
ROW_NUMBER() OVER (PARTITION BY PromptName ORDER BY VersionNumber DESC) AS RowNum
FROM PromptFile
@@ -20,9 +23,12 @@ SELECT
lp.ModifiedAt,
lp.Model,
lp.OutputFormat,
+ lp.OutputSchema,
lp.MaxTokens,
+ lp.Temperature,
lp.SystemPrompt,
lp.UserPrompt,
+ lp.FewShots,
pp.ParameterId,
pp.ParameterName,
pp.ParameterValue,
diff --git a/DotPrompt.Sql/SqlPromptEntity.cs b/DotPrompt.Sql/SqlPromptEntity.cs
index 6ab1565..ed6633e 100644
--- a/DotPrompt.Sql/SqlPromptEntity.cs
+++ b/DotPrompt.Sql/SqlPromptEntity.cs
@@ -1,3 +1,4 @@
+using System.Text.Json;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
@@ -22,11 +23,17 @@ public class SqlPromptEntity
/// A primary key returned from the database based on autoincrements
///
public int PromptId { get; set; }
+
///
/// A unique name for the prompt
///
public required string PromptName { get; set; }
+ ///
+ /// Gets, sets the prompt version number
+ ///
+ public int Version { get; set; } = 1;
+
///
/// Gets, sets the model to use
///
@@ -37,10 +44,20 @@ public class SqlPromptEntity
///
public string OutputFormat { get; set; } = string.Empty;
+ ///
+ /// Gets, sets the JSON schema for structured output (serialised as JSON). Populated when OutputFormat is JsonSchema.
+ ///
+ public string? OutputSchema { get; set; }
+
///
/// Gets, sets the maximum number of tokens
///
- public int MaxTokens { get; set; }
+ public int? MaxTokens { get; set; }
+
+ ///
+ /// Gets, sets the optional temperature value for the model
+ ///
+ public float? Temperature { get; set; }
///
/// Gets, sets the parameter information which is held as a JSON string value
@@ -62,108 +79,93 @@ public class SqlPromptEntity
///
public string UserPrompt { get; set; } = string.Empty;
+ ///
+ /// Gets, sets the few-shot examples serialised as a JSON array
+ ///
+ public string? FewShots { get; set; }
+
///
/// Returns the prompt entity record into a instance
///
- ///
- public PromptFile? ToPromptFile()
+ public PromptFile ToPromptFile()
{
- // Generate the new prompt file
- Dictionary? parameters = this.Parameters;
- Dictionary? dictionary = this.Default;
- if (parameters != null)
+ var promptFile = new PromptFile
{
- if (dictionary != null)
+ Name = PromptName,
+ Version = Version,
+ Model = Model,
+ Config = new PromptConfig
{
- var promptFile = new PromptFile
+ OutputFormat = Enum.Parse(OutputFormat, true),
+ MaxTokens = MaxTokens,
+ Temperature = Temperature,
+ Output = new Output
+ {
+ Format = Enum.Parse(OutputFormat, true),
+ Schema = string.IsNullOrEmpty(OutputSchema)
+ ? null
+ : JsonSerializer.Deserialize