Skip to content

Commit

Permalink
Code(API::AssistantsSeeder): Add seeding for default assistant in the…
Browse files Browse the repository at this point in the history
… database
  • Loading branch information
ktutak1337 committed Jun 16, 2024
1 parent 3be585b commit f4546d1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Enter the Metaprompt here. This set of instructions will define your assistant's
in every conversation, guiding how it interacts and responds. Keep it concise, clear, and
reflective of the assistant's intended personality and capabilities.";

private const string DefaultAvatarUrl = "https://th.bing.com/th/id/OIG3.PYK1.ctv1ceJsoR9RZxZ?w=270&h=270&c=6&r=0&o=5&dpr=1.1&pid=ImgGn";
private const string DefaultAvatarUrl = "https://github.com/ktutak1337/Stellar-Chat/blob/main/docs/assets/images/_ed19c10c-bbad-4514-8df4-eef37400e218.jpg";

private bool success;

Expand Down Expand Up @@ -122,7 +122,6 @@ reflective of the assistant's intended personality and capabilities.";
Name = assistant.Name,
Metaprompt = assistant.Metaprompt,
Description = assistant.Description,
// TODO: temp solution
AvatarUrl = assistant.AvatarUrl ?? DefaultAvatarUrl,
DefaultModel = assistant.DefaultModel,
DefaultVoice = assistant.DefaultVoice,
Expand All @@ -135,7 +134,6 @@ reflective of the assistant's intended personality and capabilities.";

private void SetupNewAssistantParameters()
{
// TODO: temp solution
Assistant!.AvatarUrl = DefaultAvatarUrl;
Assistant.IsDefault = false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace StellarChat.Server.Api.DAL.Mongo.Seeders;

internal sealed class AssistantsSeeder(ILogger<AssistantsSeeder> logger, TimeProvider clock) : IAppSettingsSeeder
{
private readonly ILogger<AssistantsSeeder> _logger = logger;
private readonly TimeProvider _clock = clock;

public async Task SeedAsync(IMongoDatabase database)
{
var settingsCollection = database.GetCollection<AssistantDocument>("assistants");
var cursor = await settingsCollection.FindAsync(FilterDefinition<AssistantDocument>.Empty);
var documents = await cursor.ToListAsync();

if (documents.Any())
{
return;
}

var now = _clock.GetLocalNow();

string metaprompt = @"
You are an AI assistant designed for ultra-concise, engaging conversations. You are chatting with the user via Stellar Chat app.
RULES:
- Format responses in Markdown or JSON, like `**bold**` or `{""key"": ""value""}`
- Always wrap code with triple backticks and keywords with `single backticks`
Current date: {Date}
";

var document = new AssistantDocument
{
Id = Guid.NewGuid(),
Name = "Sophia",
Description = "An AI assistant for seamless chat and accurate answers",
AvatarUrl = "https://github.com/ktutak1337/Stellar-Chat/blob/main/docs/assets/images/_ed19c10c-bbad-4514-8df4-eef37400e218.jpg",
IsDefault = true,
Metaprompt= metaprompt,
DefaultModel = "gpt-4o",
DefaultVoice = "Nova",
CreatedAt = now,
UpdatedAt = now,
};

_logger.LogInformation("Started seeding 'assistants' collection.");

await settingsCollection.InsertOneAsync(document);

_logger.LogInformation($"Added a default assistant to the database with 'ID': {document.Id}, and 'Name': {document.Name}.");
_logger.LogInformation("Finished seeding 'assistants' collection.");
}
}

0 comments on commit f4546d1

Please sign in to comment.