From 0bca07f09932c86bb612ccbb4b3105a06ea02ca6 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 1 Nov 2023 21:22:45 +0000 Subject: [PATCH] adding dotnet support on text gen app --- .../dotnet/notebook-azure-openai.dib | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 06-text-generation-apps/dotnet/notebook-azure-openai.dib diff --git a/06-text-generation-apps/dotnet/notebook-azure-openai.dib b/06-text-generation-apps/dotnet/notebook-azure-openai.dib new file mode 100644 index 000000000..85a18127d --- /dev/null +++ b/06-text-generation-apps/dotnet/notebook-azure-openai.dib @@ -0,0 +1,59 @@ +#!meta + +{"kernelInfo":{"defaultKernelName":"csharp","items":[{"aliases":[],"name":"csharp"}]}} + +#!csharp + +#r "nuget: Azure.AI.OpenAI, 1.0.0-beta.8" + +#!csharp + +using Azure; +using Azure.AI.OpenAI; +using static System.Environment; + +string endpoint = ""; +string key = ""; + +// Enter the deployment name you chose when you deployed the model. +string engine = ""; + +OpenAIClient client = new(new Uri(endpoint), new AzureKeyCredential(key)); + +string prompt = "Complete the following: Once upon a time there was a"; +Console.Write($"Input: {prompt}\n"); + +Response completionsResponse = + await client.GetCompletionsAsync(engine, prompt); +string completion = completionsResponse.Value.Choices[0].Text; +Console.WriteLine($"Chatbot: {completion}"); + +#!csharp + +Console.Write("No of recipes (for example, 5): "); +string no_recipes = "2"; + +Console.Write("List of ingredients (for example, chicken, potatoes, and carrots): "); +string ingredients = "chocolate"; + +Console.Write("Filter (for example, vegetarian, vegan, or gluten-free): "); +string filter = "peanuts"; + +// interpolate the number of recipes into the prompt an ingredients +string prompt = $"Show me {no_recipes} recipes for a dish with the following ingredients: {ingredients}. Per recipe, list all the ingredients used, no {filter}: "; + +#!csharp + +// engine, prompt, max_tokens, temperature +CompletionsOptions options = new() +{ + MaxTokens = 150, + Temperature = 0.1f, +}; +options.Prompts.Add(prompt); + +Response completionsResponse = + await client.GetCompletionsAsync(engine, options); +string completion = completionsResponse.Value.Choices[0].Text; +Console.WriteLine("==== Recipes ===="); +Console.WriteLine($"Chatbot: {completion}");