forked from xbotter/PromptPlayground
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add results store (xbotter#36)
- Loading branch information
Showing
8 changed files
with
447 additions
and
137 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
PromptPlayground/Migrations/20240221112923_GenerationResultStore.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
PromptPlayground/Migrations/20240221112923_GenerationResultStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace PromptPlayground.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class GenerationResultStore : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "GenerationResultStores", | ||
columns: table => new | ||
{ | ||
Id = table.Column<long>(type: "INTEGER", nullable: false) | ||
.Annotation("Sqlite:Autoincrement", true), | ||
FunctionPath = table.Column<string>(type: "TEXT", nullable: false), | ||
Text = table.Column<string>(type: "TEXT", nullable: false), | ||
RenderedPrompt = table.Column<string>(type: "TEXT", nullable: false), | ||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false), | ||
Elapsed = table.Column<TimeSpan>(type: "TEXT", nullable: false), | ||
Usage = table.Column<string>(type: "TEXT", nullable: true) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_GenerationResultStores", x => x.Id); | ||
}); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "GenerationResultStores"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// <auto-generated /> | ||
using System; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
using PromptPlayground.Services; | ||
|
||
#nullable disable | ||
|
||
namespace PromptPlayground.Migrations | ||
{ | ||
[DbContext(typeof(DbStore))] | ||
partial class DbStoreModelSnapshot : ModelSnapshot | ||
{ | ||
protected override void BuildModel(ModelBuilder modelBuilder) | ||
{ | ||
#pragma warning disable 612, 618 | ||
modelBuilder.HasAnnotation("ProductVersion", "8.0.2"); | ||
|
||
modelBuilder.Entity("PromptPlayground.Services.Models.GenerationResultStore", b => | ||
{ | ||
b.Property<long>("Id") | ||
.ValueGeneratedOnAdd() | ||
.HasColumnType("INTEGER"); | ||
b.Property<DateTime>("CreatedAt") | ||
.HasColumnType("TEXT"); | ||
b.Property<TimeSpan>("Elapsed") | ||
.HasColumnType("TEXT"); | ||
b.Property<string>("FunctionPath") | ||
.IsRequired() | ||
.HasColumnType("TEXT"); | ||
b.Property<string>("RenderedPrompt") | ||
.IsRequired() | ||
.HasColumnType("TEXT"); | ||
b.Property<string>("Text") | ||
.IsRequired() | ||
.HasColumnType("TEXT"); | ||
b.HasKey("Id"); | ||
b.ToTable("GenerationResultStores"); | ||
}); | ||
|
||
modelBuilder.Entity("PromptPlayground.Services.Models.GenerationResultStore", b => | ||
{ | ||
b.OwnsOne("PromptPlayground.Services.ResultTokenUsage", "Usage", b1 => | ||
{ | ||
b1.Property<long>("GenerationResultStoreId") | ||
.HasColumnType("INTEGER"); | ||
b1.Property<int>("Completion") | ||
.HasColumnType("INTEGER"); | ||
b1.Property<int>("Prompt") | ||
.HasColumnType("INTEGER"); | ||
b1.Property<int>("Total") | ||
.HasColumnType("INTEGER"); | ||
b1.HasKey("GenerationResultStoreId"); | ||
b1.ToTable("GenerationResultStores"); | ||
b1.ToJson("Usage"); | ||
b1.WithOwner() | ||
.HasForeignKey("GenerationResultStoreId"); | ||
}); | ||
b.Navigation("Usage"); | ||
}); | ||
#pragma warning restore 612, 618 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
using PromptPlayground.Services.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PromptPlayground.Services | ||
{ | ||
internal class DbStore : DbContext | ||
{ | ||
static string defaultConnectionString; | ||
public static DbStore NewScoped | ||
{ | ||
get | ||
{ | ||
var options = new DbContextOptionsBuilder<DbStore>() | ||
.UseSqlite(defaultConnectionString) | ||
.Options; | ||
return new DbStore(options); | ||
} | ||
} | ||
|
||
static DbStore() | ||
{ | ||
var path = new ProfileService<DbStore>("store.db").ProfilePath(); | ||
defaultConnectionString = $"Data Source={path};Mode=ReadWriteCreate;Cache=Shared"; | ||
|
||
var db = NewScoped; | ||
db.Database.Migrate(); | ||
} | ||
|
||
public DbStore(DbContextOptions<DbStore> options) : base(options) | ||
{ | ||
|
||
} | ||
|
||
public DbSet<GenerationResultStore> GenerationResultStores { get; set; } | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
base.OnModelCreating(modelBuilder); | ||
|
||
modelBuilder.Entity<GenerationResultStore>( | ||
entity => | ||
{ | ||
entity.OwnsOne(_ => _.Usage, builder => | ||
{ | ||
builder.ToJson(); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
internal class DbStoreContextFactory : IDesignTimeDbContextFactory<DbStore> | ||
{ | ||
public DbStore CreateDbContext(string[] args) | ||
{ | ||
var options = new DbContextOptionsBuilder<DbStore>() | ||
.UseSqlite("Data Source=design.db") | ||
.Options; | ||
return new DbStore(options); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PromptPlayground.Services.Models | ||
{ | ||
internal class GenerationResultStore | ||
{ | ||
public long Id { get; set; } | ||
public required string FunctionPath { get; set; } | ||
public required string Text { get; set; } | ||
public required string RenderedPrompt { get; set; } | ||
public ResultTokenUsage? Usage { get; set; } | ||
public DateTime CreatedAt { get; set; } | ||
public TimeSpan Elapsed { get; set; } | ||
} | ||
} |
Oops, something went wrong.