Skip to content

Commit

Permalink
Updated the Completion class.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisIvanov committed Jun 3, 2024
1 parent 05637e9 commit d35af6a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 60 deletions.
53 changes: 53 additions & 0 deletions src/server/CookingApp/Common/CompletionConstants/Completions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace CookingApp.Common.CompletionConstants
{
public class Completions
{
public const string Instructions = "You are a helpful assistant that answers questions related to cooking tips, recipes, kitchen tips. \" +" +
"\r\nYou will receive queries containing different questions on cooking thematic or a list of products that you have to make use of and come up with a recipe for the user.\" +" +
"\r\nYou need to take into account the user's dietary needs and their allergies so that you do not suggest a recipe that includes unhealthy or inappropriate contents. \" +" +
"\r\nHere is a list of the user's allergies:";

public const string Suggestion = "I have a list of ingredients and I need to cook something for myself. Suggest a suitable recipe: Fish, Potatoes, Garlic, Dill, Olive oil.";

public const string ExampleResponse = "Given your ingredients—fish, potatoes, garlic, dill, and olive oil—here's a recipe for a delicious and simple dish: Garlic and Dill Baked Fish with Roasted Potatoes." +
"\r\n" +
"\r\nGarlic and Dill Baked Fish with Roasted Potatoes" +
"\r\nIngredients:" +
"\r\nFish fillets (e.g., cod, tilapia, or salmon)" +
"\r\nPotatoes (Yukon Gold or red potatoes work well)" +
"\r\n3-4 cloves of garlic, minced" +
"\r\nFresh dill, chopped" +
"\r\nOlive oil" +
"\r\nSalt and pepper to taste" +
"\r\nOptional: Lemon wedges for serving" +
"\r\nInstructions:" +
"\r\nPreheat the Oven:" +
"\r\n" +
"\r\nPreheat your oven to 400°F (200°C)." +
"\r\nPrepare the Potatoes:" +
"\r\n" +
"\r\nWash and cut the potatoes into small, even-sized chunks or wedges." +
"\r\nPlace the potato pieces on a baking sheet. Drizzle with olive oil, and sprinkle with salt and pepper." +
"\r\nToss the potatoes to coat them evenly." +
"\r\nPlace the baking sheet in the oven and roast for about 25-30 minutes, or until the potatoes are golden and crispy. Stir once halfway through cooking." +
"\r\nPrepare the Fish:" +
"\r\n" +
"\r\nWhile the potatoes are roasting, place the fish fillets on another baking sheet lined with parchment paper or lightly greased with olive oil." +
"\r\nIn a small bowl, mix the minced garlic, chopped dill, a pinch of salt, and a couple of tablespoons of olive oil." +
"\r\nSpoon the garlic and dill mixture over the fish fillets, spreading it evenly." +
"\r\nBake the Fish:" +
"\r\n" +
"\r\nAfter the potatoes have been in the oven for about 15 minutes, place the baking sheet with the fish in the oven." +
"\r\nBake the fish for 10-15 minutes, depending on the thickness of the fillets. The fish should be opaque and flake easily with a fork when done." +
"\r\nServe:" +
"\r\n" +
"\r\nRemove both the fish and potatoes from the oven." +
"\r\nServe the baked fish with a side of roasted potatoes." +
"\r\nOptionally, garnish with additional fresh dill and serve with lemon wedges for an extra burst of flavor." +
"\r\nNotes:" +
"\r\nEnsure the baking sheets are not overcrowded to allow for even cooking." +
"\r\nAdjust the seasoning according to your taste preference." +
"\r\nFeel free to add other herbs or spices that you like." +
"\r\nEnjoy your meal!";
}
}
1 change: 0 additions & 1 deletion src/server/CookingApp/Common/ExceptionMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ public static class ExceptionMessages
{
public const string NullOrEmptyInputValues = "The provided input contains either null or an empty value";
public const string SubscriptionCreationFail = "Failed to create a subscription. {0}";

}
}
20 changes: 9 additions & 11 deletions src/server/CookingApp/Models/RecipeModel.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
namespace CookingApp.Models
{
using CookingApp.Infrastructure.Common;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

public class RecipeModel
public class RecipeModel : MongoEntity
{
class Recipe
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public int Id { get; set; }
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public int Id { get; set; }

[BsonElement("content")]
public string Content { get; set; }
[BsonElement("content")]
public string Content { get; set; }

[BsonElement("created")]
public DateTime Created { get; set; }
[BsonElement("created")]
public DateTime Created { get; set; }

}
}
}
56 changes: 8 additions & 48 deletions src/server/CookingApp/Services/OpenAI/Completions/Recipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
using CookingApp.Infrastructure.Interfaces;
using MongoDB.Bson;
using CookingApp.Models;
using CookingApp.Common.CompletionConstants;

/// <summary>
/// This class it to assist with the personal needs of the user.
/// After defining their dietary/allergic needs the chat completion
/// will fill them in for the chatbot to take into account.
/// </summary>
public class Recipe<T> where T : RecipeModel
public class Recipe
{
// field for UserSettingsDbService
// field for userManagerService
private readonly IRepository _repository;
private readonly IRepository<RecipeModel> _repository;
private readonly IOpenAIService _openAIService;

public Recipe(IOpenAIService openAIService, IRepository repository)
public Recipe(IOpenAIService openAIService, IRepository<RecipeModel> repository)
{
_openAIService = openAIService;
_repository = repository;
Expand All @@ -37,57 +38,16 @@ public async Task<string> CreateCompletion(string message)
Messages = new List<ChatMessage>
{
// Creating a prompt for the chatboot to answer a question about cooking/diatery needs.
ChatMessage.FromSystem("You are a helpful assistant that answers questions related to cooking tips, recipes, kitchen tips. " +
"You will receive queries containing different questions on cooking thematic or a list of products that you have to make use of and come up with a recipe for the user." +
"You need to take into account the user's dietary needs and their allergies so that you do not suggest a recipe that includes unhealthy or inappropriate contents. " +
$"Here is a list of the user's allergies: {userAllergies}."),
ChatMessage.FromUser("I have a list of ingredients and I need to cook something for myself. Suggest a suitable recipe: Fish, Potatoes, Garlic, Dill, Olive oil."),
ChatMessage.FromAssistant("Given your ingredients—fish, potatoes, garlic, dill, and olive oil—here's a recipe for a delicious and simple dish: Garlic and Dill Baked Fish with Roasted Potatoes." +
"\r\n" +
"\r\nGarlic and Dill Baked Fish with Roasted Potatoes" +
"\r\nIngredients:" +
"\r\nFish fillets (e.g., cod, tilapia, or salmon)" +
"\r\nPotatoes (Yukon Gold or red potatoes work well)" +
"\r\n3-4 cloves of garlic, minced" +
"\r\nFresh dill, chopped" +
"\r\nOlive oil" +
"\r\nSalt and pepper to taste" +
"\r\nOptional: Lemon wedges for serving" +
"\r\nInstructions:" +
"\r\nPreheat the Oven:" +
"\r\n" +
"\r\nPreheat your oven to 400°F (200°C)." +
"\r\nPrepare the Potatoes:" +
"\r\n" +
"\r\nWash and cut the potatoes into small, even-sized chunks or wedges." +
"\r\nPlace the potato pieces on a baking sheet. Drizzle with olive oil, and sprinkle with salt and pepper." +
"\r\nToss the potatoes to coat them evenly." +
"\r\nPlace the baking sheet in the oven and roast for about 25-30 minutes, or until the potatoes are golden and crispy. Stir once halfway through cooking." +
"\r\nPrepare the Fish:" +
"\r\n" +
"\r\nWhile the potatoes are roasting, place the fish fillets on another baking sheet lined with parchment paper or lightly greased with olive oil." +
"\r\nIn a small bowl, mix the minced garlic, chopped dill, a pinch of salt, and a couple of tablespoons of olive oil." +
"\r\nSpoon the garlic and dill mixture over the fish fillets, spreading it evenly." +
"\r\nBake the Fish:" +
"\r\n" +
"\r\nAfter the potatoes have been in the oven for about 15 minutes, place the baking sheet with the fish in the oven." +
"\r\nBake the fish for 10-15 minutes, depending on the thickness of the fillets. The fish should be opaque and flake easily with a fork when done." +
"\r\nServe:" +
"\r\n" +
"\r\nRemove both the fish and potatoes from the oven." +
"\r\nServe the baked fish with a side of roasted potatoes." +
"\r\nOptionally, garnish with additional fresh dill and serve with lemon wedges for an extra burst of flavor." +
"\r\nNotes:" +
"\r\nEnsure the baking sheets are not overcrowded to allow for even cooking." +
"\r\nAdjust the seasoning according to your taste preference." +
"\r\nFeel free to add other herbs or spices that you like." +
"\r\nEnjoy your meal!"),
ChatMessage.FromSystem(Completions.Instructions + userAllergies + "."),
ChatMessage.FromUser(Completions.Suggestion),
ChatMessage.FromAssistant(Completions.ExampleResponse),
ChatMessage.FromUser(message)
},
Model = Models.Gpt_4o,
});
if (completionResult.Successful)
{
await _repository.InsertAsync(new RecipeModel());
return completionResult.Choices.First().Message.Content;
}

Expand Down

0 comments on commit d35af6a

Please sign in to comment.