diff --git a/samples/Console.HikeBenefitsSummary/Console.HikeBenefitsSummary.csproj b/samples/Console.HikeBenefitsSummary/Console.HikeBenefitsSummary.csproj new file mode 100644 index 0000000..ef4b7d7 --- /dev/null +++ b/samples/Console.HikeBenefitsSummary/Console.HikeBenefitsSummary.csproj @@ -0,0 +1,16 @@ + + + + Exe + net8.0 + enable + bd5c311f-6c35-4d21-badd-1b9d9b76b66b + + + + + + + + + diff --git a/samples/Console.HikeBenefitsSummary/Program.cs b/samples/Console.HikeBenefitsSummary/Program.cs new file mode 100644 index 0000000..a8685a8 --- /dev/null +++ b/samples/Console.HikeBenefitsSummary/Program.cs @@ -0,0 +1,21 @@ +using Microsoft.Extensions.Configuration; +using Mscc.GenerativeAI; + +// Read the API key from the user secrets file. +var config = new ConfigurationBuilder().AddUserSecrets().Build(); +string apiKey = config["GOOGLE_API_KEY"]; + +// Create a new Google AI model client. +var genai = new GoogleAI(apiKey); +var model = genai.GenerativeModel(model: Model.Gemini15Pro); + +// Read the text to be summarized from a Markdown file. +var markdown = System.IO.File.ReadAllText("benefits.md"); + +// Instruct the model to summarize the text in 20 words or less. +var prompt = $"Please summarize the the following text in 20 words or less: {markdown}"; +Console.WriteLine($"\nUser >>> {prompt}"); + +// Generate the summary and display it. +var response = await model.GenerateContent(prompt); +Console.WriteLine($"\nGemini >>> {response.Text}"); \ No newline at end of file diff --git a/samples/Console.HikeBenefitsSummary/README.md b/samples/Console.HikeBenefitsSummary/README.md new file mode 100644 index 0000000..09ae679 --- /dev/null +++ b/samples/Console.HikeBenefitsSummary/README.md @@ -0,0 +1,3 @@ +# Hiking Benefits Summary + +This sample demonstrates how to use Gemini AI with a `gemini-1.5-pro` model, from a .NET 8.0 console application. Use the AI model to summarize a page of text to a few words. It consists of a console application, running locally, that will read the file `benefits.md` and send request to the Gemini API to summarize it. diff --git a/samples/Console.HikeBenefitsSummary/benefits.md b/samples/Console.HikeBenefitsSummary/benefits.md new file mode 100644 index 0000000..8bbc207 --- /dev/null +++ b/samples/Console.HikeBenefitsSummary/benefits.md @@ -0,0 +1,21 @@ +# Hiking Benefits + +**Hiking** is a wonderful activity that offers a plethora of benefits for both your body and mind. Here are some compelling reasons why you should consider starting hiking: +1. **Physical Fitness**: + - **Cardiovascular Health**: Hiking gets your heart pumping, improving cardiovascular fitness. The varied terrain challenges your body and burns calories. + - Strength and Endurance: Uphill climbs and uneven trails engage different muscle groups, enhancing strength and endurance. + - Weight Management: Regular hiking can help you maintain a healthy weight. +2. Mental Well-Being: + - Stress Reduction: Nature has a calming effect. Hiking outdoors reduces stress, anxiety, and promotes relaxation. + - Improved Mood: Fresh air, sunlight, and natural surroundings boost your mood and overall happiness. + - Mindfulness: Disconnect from screens and immerse yourself in the present moment. Hiking encourages mindfulness. +3. Connection with Nature: + - Scenic Views: Explore breathtaking landscapes, from lush forests to mountain peaks. Nature's beauty rejuvenates the soul. + - Wildlife Encounters: Spot birds, animals, and plant life. Connecting with nature fosters appreciation and wonder. +4. Social Interaction: + - Group Hikes: Join hiking clubs or go with friends. It's a great way to bond and share experiences. + - Solitude: Solo hikes provide introspection and solitude, allowing you to recharge. +5. Adventure and Exploration: + - Discover Hidden Gems: Hiking takes you off the beaten path. Discover hidden waterfalls, caves, and scenic trails. + - Sense of Accomplishment: Reaching a summit or completing a challenging trail gives a sense of achievement. +Remember, hiking can be tailored to your fitness level—start with shorter, easier trails and gradually progress. Lace up those hiking boots and embark on an adventure! 🌲🥾 diff --git a/samples/Console.HikeChatter/Console.HikeChatter.csproj b/samples/Console.HikeChatter/Console.HikeChatter.csproj new file mode 100644 index 0000000..ef4b7d7 --- /dev/null +++ b/samples/Console.HikeChatter/Console.HikeChatter.csproj @@ -0,0 +1,16 @@ + + + + Exe + net8.0 + enable + bd5c311f-6c35-4d21-badd-1b9d9b76b66b + + + + + + + + + diff --git a/samples/Console.HikeChatter/Program.cs b/samples/Console.HikeChatter/Program.cs new file mode 100644 index 0000000..35eca7b --- /dev/null +++ b/samples/Console.HikeChatter/Program.cs @@ -0,0 +1,39 @@ +using Microsoft.Extensions.Configuration; +using Mscc.GenerativeAI; + +// Read the API key from the user secrets file. +var config = new ConfigurationBuilder().AddUserSecrets().Build(); +string apiKey = config["GOOGLE_API_KEY"]; + +// == Providing context for the AI model ========== +var markdown = System.IO.File.ReadAllText("hikes.md"); +var systemPrompt = new Content { Parts = new() { new TextData() { Text = + """ + You are upbeat and friendly. You introduce yourself when first saying hello. + Provide a short answer only based on the user hiking records below: + + """ + markdown +}}}; +Console.WriteLine($"\n\t-=-=- Hiking History -=-=--\n{markdown}"); + +// Create a new Google AI model client. +var genai = new GoogleAI(apiKey); +var generationConfig = new GenerationConfig { Temperature = 1f, TopP = 0.95f, MaxOutputTokens = 1000 }; +var model = genai.GenerativeModel(model: Model.Gemini15Pro, generationConfig: generationConfig, systemInstruction: systemPrompt); + +// == Starting the conversation ========== +string userGreeting = "Hi!"; +Console.WriteLine($"\nUser >>> {userGreeting}"); + +var response = await model.GenerateContent(userGreeting); +Console.WriteLine($"\nGemini >>> {response.Text}"); + +// == Providing the user's request ========== +var hikeRequest = """ +I would like to know the ration of hike I did in Canada compare to hikes done in other countries. +"""; +Console.WriteLine($"\nUser >>> {hikeRequest}"); + +// == Getting the response from the AI model ========== +response = await model.GenerateContent(hikeRequest); +Console.WriteLine($"\nGemini >>> {response.Text}"); diff --git a/samples/Console.HikeChatter/README.md b/samples/Console.HikeChatter/README.md new file mode 100644 index 0000000..504ea39 --- /dev/null +++ b/samples/Console.HikeChatter/README.md @@ -0,0 +1,3 @@ +# Chatting About My Previous Hikes + +This sample demonstrates how to use Gemini AI with a `gemini-1.5-pro` model, from a .NET 8.0 console application. Use the AI model to get analytics and information about your previous hikes. It consists of a console application, running locally, that will read the file `hikes.md` and send request to the Gemini API and provide the result in the console. \ No newline at end of file diff --git a/samples/Console.HikeChatter/hikes.md b/samples/Console.HikeChatter/hikes.md new file mode 100644 index 0000000..91e2394 --- /dev/null +++ b/samples/Console.HikeChatter/hikes.md @@ -0,0 +1,10 @@ +| Trail Name | Hike Date | Country | Weather +| --------------- | ---------- | -------- | -------- +| Cascade Falls | 2021-07-15 | Canada | Sunny +| Johnston Canyon | 2022-05-10 | Canada | Cloudy +| Lake Louise | 2020-09-05 | Canada | Rainy +| Angel's Landing | 2023-06-20 | USA | Sunny +| Gros Morne | 2021-08-25 | Canada | Foggy +| Hocking Hills | 2022-04-01 | USA | Sunny +| The Chief | 2020-07-05 | Canada | Sunny +| Skaftafell | 2022-09-10 | Iceland | Cloudy \ No newline at end of file diff --git a/samples/Console.HikerAI/Console.HikerAI.csproj b/samples/Console.HikerAI/Console.HikerAI.csproj new file mode 100644 index 0000000..ef4b7d7 --- /dev/null +++ b/samples/Console.HikerAI/Console.HikerAI.csproj @@ -0,0 +1,16 @@ + + + + Exe + net8.0 + enable + bd5c311f-6c35-4d21-badd-1b9d9b76b66b + + + + + + + + + diff --git a/samples/Console.HikerAI/Program.cs b/samples/Console.HikerAI/Program.cs new file mode 100644 index 0000000..5a074d9 --- /dev/null +++ b/samples/Console.HikerAI/Program.cs @@ -0,0 +1,48 @@ +using Microsoft.Extensions.Configuration; +using Mscc.GenerativeAI; + +// Read the API key from the user secrets file. +var config = new ConfigurationBuilder().AddUserSecrets().Build(); +string apiKey = config["GOOGLE_API_KEY"]; + +// == Providing context for the AI model ========== +var systemPrompt = new Content { Parts = new() { new TextData() { Text = +""" +You are a hiking enthusiast who helps people discover fun hikes in their area. You are upbeat and friendly. +You introduce yourself when first saying hello. When helping people out, you always ask them +for this information to inform the hiking recommendation you provide: + +1. Where they are located +2. What hiking intensity they are looking for + +You will then provide three suggestions for nearby hikes that vary in length after you get that information. +You will also share an interesting fact about the local nature on the hikes when making a recommendation. +"""}}}; + +// Create a new Google AI model client. +var genai = new GoogleAI(apiKey); +var model = genai.GenerativeModel(model: Model.Gemini15Pro, systemInstruction: systemPrompt); + +// == Starting the conversation ========== +string userGreeting = """ +Hi! +Apparently you can help me find a hike that I will like? +"""; +Console.WriteLine($"\nUser >>> {userGreeting}"); + +var response = await model.GenerateContent(userGreeting); +Console.WriteLine($"\nGemini >>> {response.Text}"); + +// == Providing the user's request ========== +var hikeRequest = +""" +I live in Mauritius area and would like an easy hike. I don't mind driving a bit to get there. +I don't want the hike to be over 15 kilometers round trip. I'd consider a point-to-point hike. +I want the hike to be as isolated as possible. I don't want to see many people. +I would like it to be as bug free as possible. +"""; +Console.WriteLine($"\nUser >>> {hikeRequest}"); + +// == Getting the response from the AI model ========== +response = await model.GenerateContent(hikeRequest); +Console.WriteLine($"\nGemini >>> {response.Text}"); diff --git a/samples/Console.HikerAI/README.md b/samples/Console.HikerAI/README.md new file mode 100644 index 0000000..fcd8371 --- /dev/null +++ b/samples/Console.HikerAI/README.md @@ -0,0 +1,3 @@ +# HikerAI + +This sample demonstrates how to use Gemini AI with a `gemini-1.5-pro` model, from a .NET 8.0 console application. Get a hiking recommendation from the AI model. It consists of a console application, running locally, that will send request to the Gemini API deployed in your Azure subscription. \ No newline at end of file