using API.DBAccess; using OpenAI.Chat; namespace API.Services { public class OpenAiRecipes { private readonly IConfiguration _configuration; public OpenAiRecipes(IConfiguration configuration) { _configuration = configuration; } public async Task ChatGPT(string message, string language, int numberOfRecipes = 5) { ChatClient client = new( model: _configuration["OpenAI:Model"], apiKey: _configuration["OpenAI:APIKey"] ); string jsonStructure = "{ name: string, description: string, directions: [string, string, ...], ingredients: [ { amount: number?, unit: string?, name: string }]}"; List messages = [ new SystemChatMessage($"You are a a helpful assistant. You give back {numberOfRecipes} recipes on the dish that you have been given. Answer in the language {language}. " + $"Answer in .json format using this structure {jsonStructure}. " + $"For the ingredients keep the names short ie. 'grated cheese' instead of 'cheese, grated (e.g., cheddar or gouda)'"), new UserChatMessage(message), ]; ChatCompletion chat = await client.CompleteChatAsync(messages); return chat; } } }