Building Technical Customer support model using ollama


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.  Basically there are few easy steps by using these steps you will be able to create your own Customized AI model.

STEP 1:

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.

Check: check your server is working or not using command:-

ollama serve

if page gets open it means server is running. Exit the model 

ctrl + c or \bye

STEP 2:

create a new file of your model name in your system with .py extention. 

example:- 

I am creating this file on desktop.

cli_bot.py

now write the simple logic:

import requests
import json

OLLAMA_URL = "http://localhost:11434/api/chat"

SYSTEM_PROMPT = """
You are a professional customer support assistant for a tech company.
Rules:
- Be polite and helpful
- Give short, clear answers
"""

messages = [{"role": "system", "content": SYSTEM_PROMPT}]

print(" Bot Started (type 'exit' to stop)\n")

while True:
    user_input = input("You: ")

    if user_input.lower() == "exit":
        print("Bot: Goodbye!")
        break
    messages.append({"role": "user", "content": user_input})

    response = requests.post(
        OLLAMA_URL,
        json={
            "model": "mistral",
            "messages": messages,
            "stream": True
        },
        stream=True
    )
    print("Bot: ", end="", flush=True)

    full_reply = ""

    try:
        for line in response.iter_lines():
            if line:
                chunk = json.loads(line.decode("utf-8"))
                if "message" in chunk:
                    content = chunk["message"].get("content", "")
                    print(content, end="", flush=True)
                    full_reply += content
    except Exception as e:
        print("\nError:", e)
    print("\n")
    messages.append({"role": "assistant", "content": full_reply})

STEP 3: 

Now run the model:
open your system terminal and enter the command:

cd desktop   #to reach the folder where you created the model file
python cli_bot.py   # to execute the model

Now the CLI based model is executed now you can enter your prompt related to technical questions and can get your answer in stream form.

Test the model 

user: my data connection is not working

bot: I'm sorry to hear that you're having trouble with your data connection. Here are a few steps you can take to troubleshoot the issue:

1. Check if your device is connected to the internet by visiting a website or using an app that requires an internet connection.
2. Make sure that airplane mode is turned off on your device.
3. Restart your device and try connecting to the internet again.
4. If you're using Wi-Fi, try turning it off and then back on, or try switching to cellular data if available.
5. If you're still having trouble, try resetting your network settings by going to Settings > General > Reset > Reset Network Settings. Be aware that this will erase all saved networks and passwords, so you'll need to re-enter them afterwards.
6. If none of these steps work, please contact our technical support team for further assistance. We're here to help!

note:-the response of this model is according to the prompt I used in my system.

read more about ollama:

previous topic: Creating Custom AI Models with Modelfiles

0 Comments Report