Travers-Smith / YCNBot

MIT License
18 stars 6 forks source link

YCNBot.Data issue #3

Open nick-choudhary opened 1 year ago

nick-choudhary commented 1 year ago

When using dotnet ef database update getting the following error.

No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.

Here is the appsettings.json configuration:

{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", "ApplicationInsights": { "ConnectionString": "InstrumentationKey=fcafc72e-4d94-483f-xxxx;IngestionEndpoint=https://xxxx-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.xxxxx.monitor.azure.com/" }, "ConnectionStrings": { "YCNBotContext": "Server=tcp:xxxxx.database.windows.net,1433;Initial Catalog=xxxxbotdata;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication=\"Active Directory Default\";" }, Encrypt=True;" "AzureAd": { "Instance": "https://login.microsoftonline.com/", "ClientId": "ee9859c0-xxxxx-49f4-8a1b-xxxxx", "TenantId": "xxxx-bf31-xxxx-bb25-c2f930124211", "SignedOutCallbackPath": "/auth/signout-oidc", "CallbackPath": "/signin-oidc" }, "ChatModel": "gpt-4", "PageSize": 100, "AzureKeyVaultUri": "https://xxxx.vault.azure.net/", "AzureADCertThumbprint": "xxxxx", "AllowPersonalMode": "false", "OpenAIBaseUrl": "https://api.openai.com/v1/", "AzureOpenAIBaseUrl": "https://api.openai.com/v1/", "ChatCompletionType": "OpenAI", "AzureApiVersion": "2023-03-15-preview", "AzureModelDeploymentName": "chatgpt3", "SplitNamesDirectoryPath": "", "StopWordsFilepath": "" }

samlansleyts commented 1 year ago

Hi,

Sorry for the delayed response.

So there are a couple of things that could be causing the problem.

(1) Make sure that the application successfully runs, as it may be that something in the program.cs file is broken. E.g. you may have not set up the Microsoft Graph authentication stuff. If you don't need the Microsoft Graph features just remove it from the UnitOfWork class in the Data project (2) Run 'dotnet ef database update --project "YCNBot\YCNBot.Data\YCNBot.Data.csproj"' inside the "YCNBot/YCNBot" directory where the 'YCNBot.csroj' file is located.

nick-choudhary commented 1 year ago

Hey,

I appreciate you taking time to respond to this, I couldn't make none of the options work:

I have found some issues also, I'll give all the changes here for your review.

YCNBotContext.cs

Added the following, not sure why it was not taking ConnectionString from Program.cs file

public partial class YCNBotContext : DbContext, IDesignTimeDbContextFactory { public YCNBotContext() { }

public YCNBotContext(DbContextOptions<YCNBotContext> options)
    : base(options)
{
}

public YCNBotContext CreateDbContext(string[] args)
{
    var optionsBuilder = new DbContextOptionsBuilder<YCNBotContext>();
    optionsBuilder.UseSqlServer("Server=tcp:irocketbotserver.database.windows.net,1433;Initial Catalog=irocketbotdata;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication=\"Active Directory Default\";");

    return new YCNBotContext(optionsBuilder.Options);
}

public virtual DbSet<Chat> Chats { get; set; }

EVERYTHING ELSE IS SAME

}

nick-choudhary commented 1 year ago

"OpenAiKey" and "AzureOpenAIKey" key was missing from appsettings.json

MessageController.cs

DateAdded = DateTime.Now, ContainsCaseLaw = containsCaseLaw

Above Columns are missing from InitialCreate Migration file, which causes the error while updating the SQL

After making all the above changes I was able to run the app successfully.

I hope this helps, please review and make changes

nick-choudhary commented 1 year ago

Lastly, app seems to be taking long time in generating the output. Any reason why so?

samlansleyts commented 1 year ago

"OpenAiKey" and "AzureOpenAIKey" key was missing from appsettings.json

MessageController.cs

DateAdded = DateTime.Now, ContainsCaseLaw = containsCaseLaw

Above Columns are missing from InitialCreate Migration file, which causes the error while updating the SQL

After making all the above changes I was able to run the app successfully.

I hope this helps, please review and make changes

Thanks I'll update the migration to the latest version. The "OpenAIKey" and "AzureOpenAIKey" are not in the appsettings.json file on purpose. You should NEVER store secrets in plain text in a config file, especially a file that gets checked into version control. We used Azure KeyVault to inject the secrets into the configuration object in a secure way. You can use 'User Secrets' in Visual Studio for development.

samlansleyts commented 1 year ago

Lastly, app seems to be taking long time in generating the output. Any reason why so?

I'm guessing you are using OpenAI?

Its nothing to do with our application, its the OpenAI API that takes a while to generate the output.

Nothing we can do about that.