# Task 56 - AI Question Intent Classifier

## 1. Overview

Task 56 is a VB.NET Windows Forms application that uses local AI to identify the intent of a user's question.

The application provides three options:

- How Many
- List Items
- Print Items

The user enters a question in the Question textbox and selects the appropriate button. The application sends the question to a locally running Ollama AI model and determines whether the question is related to the selected intent.

The result is displayed in the Answer textbox.

## 2. Technology Used

- VB.NET
- Windows Forms
- .NET Framework / .NET version configured in the project
- Ollama
- phi3:mini AI model
- Ollama local REST API
- System.Net.Http
- System.Text.Json

## 3. How the Application Works

The basic flow is:

User enters a question
        |
        v
Selects How Many / List Items / Print Items
        |
        v
VB.NET application sends the question to Ollama
        |
        v
Ollama uses the phi3:mini model
        |
        v
AI classifies the question
        |
        +--> HOW_MANY
        +--> LIST_ITEMS
        +--> PRINT_ITEMS
        +--> UNKNOWN
        |
        v
Result is displayed in the Answer textbox

## 4. AI Categories

### HOW_MANY

Used when the question asks for:

- A number
- A quantity
- A count
- A total
- How many

Example:

    How many students are there?

Expected result:

    The question is about how many is requested

### LIST_ITEMS

Used when the question asks to:

- List items
- Show items
- Display items
- Give names of multiple items

Example:

    What are the names of the students?

Expected result:

    The question is about List items is requested

### PRINT_ITEMS

Used when the question asks to:

- Print an item
- Print multiple items
- Produce a printed copy

Example:

    Please print the student list.

Expected result:

    The question is about Print items is requested

### UNKNOWN

Questions that do not match any of the above categories are classified as UNKNOWN.

Example:

    Explain photosynthesis.

## 5. Ollama Requirement

This application uses Ollama as a local AI service.

Ollama must be installed and running on the computer where the application is used.

The application connects to:

    http://localhost:11434/api/generate

The configured model is:

    phi3:mini

No paid API key is required.

The AI processing is performed locally through Ollama.

## 6. Installing Ollama

Install Ollama on the target computer using the official Ollama installer.

After installation, verify that Ollama is available from Command Prompt:

    ollama --version

If the command displays an Ollama version, the installation is successful.

## 7. Installing the AI Model

After Ollama is installed, open Command Prompt and run:

    ollama pull phi3:mini

Wait until the model download is completed.

Verify the installed model:

    ollama list

The output should contain:

    phi3:mini

## 8. Starting Ollama

Ollama normally runs in the background after it is started.

If Ollama is not running, it can be started from the Windows Start menu by opening Ollama.

It can also be started from Command Prompt with:

    ollama serve

When using `ollama serve`, keep the Command Prompt window open while using the application.

## 9. Verifying the Ollama API

To verify that Ollama is running, open Command Prompt and run:

    curl http://localhost:11434/api/tags

The response should contain information about the installed models, including:

    phi3:mini

If the API cannot be reached, start Ollama and try again.

## 10. Running the Application

1. Make sure Ollama is installed.
2. Make sure the `phi3:mini` model is installed.
3. Start Ollama.
4. Open the Task 56 project in Visual Studio.
5. Build the solution.
6. Run the application.
7. Enter a question in the Question textbox.
8. Click the required button.
9. Check the result in the Answer textbox.

## 11. Example Tests

### Test 1 - How Many

Question:

    How many students are there?

Click:

    How Many

Expected Answer:

    The question is about how many is requested

### Test 2 - List Items

Question:

    What are the names of the students?

Click:

    List Items

Expected Answer:

    The question is about List items is requested

### Test 3 - Print Items

Question:

    Please print the student list.

Click:

    Print Items

Expected Answer:

    The question is about Print items is requested

### Test 4 - Empty Question

Leave the Question textbox empty and click any button.

Expected Answer:

    Please enter a question.

### Test 5 - Ollama Offline

Stop Ollama and click one of the buttons.

Expected Answer:

    Unable to connect to Ollama. Please make sure Ollama is running.

## 12. Error Handling

The application handles the following situations:

- Empty question
- Ollama is not running
- AI request takes too long
- Invalid AI response
- Unexpected classification result

When Ollama is unavailable, the application displays:

    Unable to connect to Ollama. Please make sure Ollama is running.

The application does not require a paid online AI service.

## 13. Project Files

### Frm_QuestionIntent.vb

Contains the Windows Forms user interface and button actions.

### AIQuestionClassifier.vb

Contains the AI classification logic, Ollama API communication, prompt, response processing, and error handling.

## 14. Important Configuration

The following values are configured in `AIQuestionClassifier.vb`:

    OllamaUrl = http://localhost:11434/api/generate
    ModelName = phi3:mini

If a different Ollama model is used in the future, the `ModelName` value must be updated and the corresponding model must be installed.

## 15. Offline / Local AI

The application communicates with Ollama through `localhost`.

This means the AI model runs on the local computer instead of requiring a cloud AI service or paid API subscription.

Internet access is normally required to download Ollama and the AI model initially. After installation and model download, the classification service itself runs locally.

## 16. Troubleshooting

### Ollama connection error

If the application displays:

    Unable to connect to Ollama. Please make sure Ollama is running.

Start Ollama and try again.

You can also check:

    ollama list

and:

    curl http://localhost:11434/api/tags

### Model not found

If `phi3:mini` is not shown by:

    ollama list

run:

    ollama pull phi3:mini

### Application does not classify a question correctly

Make sure:

- Ollama is running.
- `phi3:mini` is installed.
- The question is clearly written.
- The correct button is selected.

## 17. Notes for Deployment

The target computer must have:

- Windows
- The required .NET runtime/framework for the project
- Ollama
- `phi3:mini`

The application source code alone does not include the AI model. The model must be installed through Ollama on the target computer.

## 18. Summary

Task 56 provides a simple local AI-based question intent classification system.

It supports:

- How Many questions
- List Items questions
- Print Items questions
- Unknown questions
- Empty question validation
- Ollama connection error handling

The application uses the open-source/local Ollama approach with the `phi3:mini` model, avoiding the need for a paid AI API.
