Introduction
This blog is to provide the practical knowledge about how you can create your own customized CLI based AI customer support model according to your requirement using .NET programming language. Basically there are few easy steps by using these steps you will be able to create your own Customized AI model.
STEP 1: Download the AI Model
Pull the AI model which you want to use for customization and model creation. here we will use “Mistral”. Run this command in your terminal:
ollama run mistral
this command will find is this already present in your system or not, if it is not found then it will download the model and then execute.
STEP 2: Create a .NET console application
Open the terminal on desktop or any folder suppose we are creating the folder of desktop use the command:
cd ..
cd desktop\Project
Now use the command to create the templet of console app, use comand:
dotnet new console -n CliBot
As output in the project folder on desktop Clibot named file will be created:
CliBot
│
├── Program.cs
├── CliBot.csproj
STEP 3:
Now enter in the project folder using command:
cd CliBot
And open VS code to edit the program.cs file and replace the code of Program.cs files:
using System.Text;
using System.Text.Json;
var httpClient = new HttpClient();
string ollamaUrl = "http://localhost:11434/api/chat";
string systemPrompt = """
You are a professional customer support assistant for a tech company.
Rules:
- Be polite and helpful
- Give short and clear answers
- Help users solve technical issues
""";
var messages = new List<object>
{
new
{
role = "system",
content = systemPrompt
}
};
Console.WriteLine("Bot Started (type 'exit' to stop)\n");
while (true)
{
Console.Write("You: ");
string? userInput = Console.ReadLine();
if (string.IsNullOrWhiteSpace(userInput))
continue;
if (userInput.ToLower() == "exit")
{
Console.WriteLine("Bot: Goodbye!");
break;
}
messages.Add(new
{
role = "user",
content = userInput
});
var requestBody = new
{
model = "mistral",
messages = messages,
stream = false
};
string jsonData = JsonSerializer.Serialize(requestBody);
var response = await httpClient.PostAsync(
ollamaUrl,
new StringContent(jsonData, Encoding.UTF8, "application/json")
);
if (!response.IsSuccessStatusCode)
{
Console.WriteLine("Bot: Unable to connect to Ollama.");
continue;
}
string responseJson = await response.Content.ReadAsStringAsync();
using JsonDocument doc = JsonDocument.Parse(responseJson);
string reply =
doc.RootElement
.GetProperty("message")
.GetProperty("content")
.GetString() ?? "";
Console.WriteLine($"\nBot: {reply}\n");
messages.Add(new
{
role = "assistant",
content = reply
});
}
STEP 4:
Now again open the terminal and use the command to run the model in terminal:
cd ..
cd desktop\project\Clibot
dotnet run
Test the model:
You: hey, Do you know my internet is important to access browser
Bot: Hello! Yes, I understand that your internet connection is essential to browse the web. If you're experiencing issues with your internet, here are a few steps you can take to troubleshoot:
1. Check your router and modem: Ensure both devices are powered on and connected properly. If possible, try restarting them by unplugging the power cord, waiting for about 30 seconds, then plugging it back in.
2. Verify your internet connection: Check if other devices on your network can connect to the internet. If not, there might be an issue with your internet service provider (ISP).
3. Test your speed: Use a speed test tool like fast.com or speedtest.net to measure your internet speed and see if it's within the range you should be getting according to your subscription plan.
4. Check your browser: Try using a different browser to see if the issue persists. If it does, the problem might be related to your network rather than your browser.
5. Antivirus software or firewall: Ensure that your antivirus software is not blocking your internet access and check if any firewall settings are interfering with your connection.
If none of these steps help resolve your issue, I recommend reaching out to your ISP for further assistance as they can provide more targeted solutions based on your specific service plan and location.
note:-the response of this model is according to the prompt I used in my system.
read more about ollama:
previous topic:
Building Technical Customer support model using ollama
next topic:
Understanding Embeddings in Ollama