Table of Contents

Introduction
Tutorial
Version History
Download and Installation
Support
Integration Services
Code Gallery
Licensing

Git Hub
Source Code
Issue Tracking

Community
Classes & Schedule

Code Gallery

Table of Contents

Incorporating CASE AI in VB Scripting for HMI Environments

' VBScript to open CASE.exe, activate -talk, and handle the interaction
Option Explicit

' Define variables
Dim objShell, objExec, strInput, strOutput, startTime, endTime, responseTime

' Create a shell object
Set objShell = CreateObject("WScript.Shell")

' Start CASE.exe with -talk command
Set objExec = objShell.Exec("CASE.exe -talk")

' Wait for the model to load
Do While Not objExec.StdOut.AtEndOfStream
    strOutput = objExec.StdOut.ReadLine
    If InStr(strOutput, "UserPrompt>") > 0 Then Exit Do
Loop

' Input data from user
strInput = InputBox("Enter your prompt for the AI:", "Conversational Agent")

' Record the start time
startTime = Timer

' Send the user prompt to CASE
objExec.StdIn.WriteLine strInput

' Capture the output response
Do While Not objExec.StdOut.AtEndOfStream
    strOutput = objExec.StdOut.ReadLine
    If InStr(strOutput, "UserPrompt>") > 0 Then
        endTime = Timer
        Exit Do
    End If
    If Len(strOutput) > 0 Then
        WScript.Echo strOutput
    End If
Loop

' Calculate the response time
responseTime = endTime - startTime

' Display the response time
WScript.Echo "Response Time: " & responseTime & " seconds"

' Clean up
Set objExec = Nothing
Set objShell = Nothing

Incorporating CASE AI in Python for HMI Environments

import subprocess
import time

# Start CASE.exe with -talk command
process = subprocess.Popen(
    ["CASE.exe", "-talk"],
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    text=True
)

# Wait for the model to load and reach the UserPrompt
while True:
    output = process.stdout.readline().strip()
    print(output)  # Print the initial output (optional)
    if "UserPrompt>" in output:
        break

# Input data from user
user_input = input("Enter your prompt for the AI: ")

# Record the start time
start_time = time.time()

# Send the user prompt to CASE
process.stdin.write(user_input + "\n")
process.stdin.flush()

# Capture the output response
response = []
while True:
    output = process.stdout.readline().strip()
    if "UserPrompt>" in output:
        end_time = time.time()
        break
    if output:
        response.append(output)

# Calculate the response time
response_time = end_time - start_time

# Display the response and response time
print("Response from AI:\n" + "\n".join(response))
print(f"Response Time: {response_time:.2f} seconds")

# Terminate the process (optional)
process.terminate()

Incorporating CASE AI for Batch Script (Windows Command Prompt) Environments

 @echo off
setlocal

rem Start CASE.exe with -talk
start /B "" CASE.exe -talk > output.txt

rem Wait for the model to load (basic loop checking for UserPrompt>)
:waitForPrompt
findstr /C:"UserPrompt>" output.txt >nul
if errorlevel 1 (
    timeout /t 1 /nobreak >nul
    goto waitForPrompt
)

rem Prompt user for input
set /p userInput="Enter your prompt for the AI: "

rem Get start time
for /F "tokens=2 delims==" %%i in ('wmic OS get LocalDateTime /value') do set startTime=%%i

rem Send user input to CASE.exe
echo %userInput%>> output.txt

rem Wait for the response (basic loop checking for UserPrompt>)
:waitForResponse
findstr /C:"UserPrompt>" output.txt >nul
if errorlevel 1 (
    timeout /t 1 /nobreak >nul
    goto waitForResponse
)

rem Get end time
for /F "tokens=2 delims==" %%i in ('wmic OS get LocalDateTime /value') do set endTime=%%i

rem Calculate response time
set /A responseTime=endTime-startTime

rem Display the response time
echo Response Time: %responseTime% seconds

endlocal

Incorporating CASE AI for PowerShell Environments

 # Start CASE.exe with -talk
$process = Start-Process "CASE.exe" -ArgumentList "-talk" -PassThru -RedirectStandardOutput "output.txt" -NoNewWindow

# Wait for the model to load
while (-not (Get-Content output.txt | Select-String -Pattern "UserPrompt>")) {
    Start-Sleep -Milliseconds 500
}

# Prompt user for input
$userInput = Read-Host "Enter your prompt for the AI"

# Record the start time
$startTime = Get-Date

# Send the user input to CASE.exe
Add-Content "output.txt" $userInput

# Wait for the response
while (-not (Get-Content output.txt | Select-String -Pattern "UserPrompt>")) {
    Start-Sleep -Milliseconds 500
}

# Record the end time
$endTime = Get-Date

# Calculate the response time
$responseTime = $endTime - $startTime

# Display the response time
Write-Output "Response Time: $($responseTime.TotalSeconds) seconds"

Incorporating CASE AI for C# (Console Application) Environments

 using System;
using System.Diagnostics;
using System.IO;

class Program
{
    static void Main()
    {
        Process process = new Process();
        process.StartInfo.FileName = "CASE.exe";
        process.StartInfo.Arguments = "-talk";
        process.StartInfo.RedirectStandardInput = true;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.CreateNoWindow = true;
        process.Start();

        StreamReader outputReader = process.StandardOutput;
        StreamWriter inputWriter = process.StandardInput;

        // Wait for UserPrompt>
        while (!outputReader.ReadLine().Contains("UserPrompt>")) {}

        Console.Write("Enter your prompt for the AI: ");
        string userInput = Console.ReadLine();

        // Start timing
        Stopwatch stopwatch = Stopwatch.StartNew();

        // Send input
        inputWriter.WriteLine(userInput);

        // Read output and look for UserPrompt>
        string response;
        do
        {
            response = outputReader.ReadLine();
            Console.WriteLine(response);
        } while (!response.Contains("UserPrompt>"));

        // Stop timing
        stopwatch.Stop();

        Console.WriteLine($"Response Time: {stopwatch.Elapsed.TotalSeconds} seconds");
    }
}

Incorporating CASE AI for Java Environments

 import java.io.*;
import java.util.Scanner;

public class CASEChat {
    public static void main(String[] args) throws IOException {
        ProcessBuilder builder = new ProcessBuilder("CASE.exe", "-talk");
        builder.redirectErrorStream(true);
        Process process = builder.start();

        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));

        // Wait for UserPrompt>
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
            if (line.contains("UserPrompt>")) break;
        }

        // Get user input
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter your prompt for the AI: ");
        String userInput = scanner.nextLine();

        // Start timing
        long startTime = System.nanoTime();

        // Send user input
        writer.write(userInput + "\n");
        writer.flush();

        // Read response and wait for UserPrompt>
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
            if (line.contains("UserPrompt>")) {
                long endTime = System.nanoTime();
                double responseTime = (endTime - startTime) / 1_000_000_000.0;
                System.out.printf("Response Time: %.2f seconds%n", responseTime);
                break;
            }
        }

        process.destroy();
    }
}

Incorporating CASE AI for Node.js Environments

 const { spawn } = require('child_process');
const readline = require('readline');

const process = spawn('CASE.exe', ['-talk']);

const rl = readline.createInterface({
    input: process.stdout,
    output: process.stdin,
    terminal: false
});

// Wait for UserPrompt>
process.stdout.on('data', (data) => {
    const output = data.toString();
    console.log(output);

    if (output.includes('UserPrompt>')) {
        rl.question('Enter your prompt for the AI: ', (userInput) => {
            const startTime = process.hrtime();

            process.stdin.write(userInput + '\n');

            process.stdout.on('data', (responseData) => {
                const response = responseData.toString();
                console.log(response);

                if (response.includes('UserPrompt>')) {
                    const endTime = process.hrtime(startTime);
                    const responseTime = endTime[0] + endTime[1] / 1e9;
                    console.log(`Response Time: ${responseTime.toFixed(2)} seconds`);
                    rl.close();
                }
            });
        });
    }
});

Incorporating CASE AI for Ruby Environments

 require 'open3'
require 'time'

# Start CASE.exe with -talk
stdin, stdout, stderr, wait_thr = Open3.popen3("CASE.exe -talk")

# Wait for UserPrompt>
until stdout.gets.chomp.include?("UserPrompt>")
  # Optionally print initialization output
end

# Prompt user for input
print "Enter your prompt for the AI: "
user_input = gets.chomp

# Record start time
start_time = Time.now

# Send input
stdin.puts user_input

# Capture response
response = ""
until (line = stdout.gets.chomp).include?("UserPrompt>")
  response += line + "\n"
end

# Record end time
end_time = Time.now

# Calculate response time
response_time = end_time - start_time

# Display the response and time
puts "Response:\n#{response}"
puts "Response Time: #{response_time.round(2)} seconds"

Incorporating CASE AI for Go Environments

 package main

import (
	"bufio"
	"fmt"
	"os"
	"os/exec"
	"strings"
	"time"
)

func main() {
	// Start CASE.exe with -talk
	cmd := exec.Command("CASE.exe", "-talk")
	stdin, _ := cmd.StdinPipe()
	stdout, _ := cmd.StdoutPipe()
	cmd.Start()

	// Wait for UserPrompt>
	scanner := bufio.NewScanner(stdout)
	for scanner.Scan() {
		output := scanner.Text()
		fmt.Println(output)
		if strings.Contains(output, "UserPrompt>") {
			break
		}
	}

	// Prompt user for input
	fmt.Print("Enter your prompt for the AI: ")
	var userInput string
	fmt.Scanln(&userInput)

	// Record start time
	startTime := time.Now()

	// Send user input
	fmt.Fprintln(stdin, userInput)

	// Capture response
	for scanner.Scan() {
		output := scanner.Text()
		fmt.Println(output)
		if strings.Contains(output, "UserPrompt>") {
			endTime := time.Now()
			responseTime := endTime.Sub(startTime)
			fmt.Printf("Response Time: %.2f seconds\n", responseTime.Seconds())
			break
		}
	}
	cmd.Wait()
}

Incorporating CASE AI for Perl Environments

 use strict;
use warnings;
use Time::HiRes qw(time);
use IPC::Open3;
use Symbol 'gensym';

# Start CASE.exe with -talk
my $stderr = gensym;
my $pid = open3(my $stdin, my $stdout, $stderr, 'CASE.exe -talk');

# Wait for UserPrompt>
while (<$stdout>) {
    print $_;
    last if /UserPrompt>/;
}

# Prompt user for input
print "Enter your prompt for the AI: ";
chomp(my $user_input = );

# Record start time
my $start_time = time();

# Send user input
print $stdin "$user_input\n";

# Capture response
while (<$stdout>) {
    print $_;
    if (/UserPrompt/>) {
        my $end_time = time();
        my $response_time = $end_time - $start_time;
        printf "Response Time: %.2f seconds\n", $response_time;
        last;
    }
}

Incorporating CASE AI for PHP Environments

  array("pipe", "r"),  // stdin
    1 => array("pipe", "w"),  // stdout
    2 => array("pipe", "w")   // stderr
);

$process = proc_open('CASE.exe -talk', $descriptorspec, $pipes);

if (is_resource($process)) {
    // Wait for UserPrompt>
    while ($line = fgets($pipes[1])) {
        echo $line;
        if (strpos($line, "UserPrompt>") !== false) {
            break;
        }
    }

    // Prompt user for input
    $user_input = readline("Enter your prompt for the AI: ");

    // Record start time
    $start_time = microtime(true);

    // Send user input to CASE.exe
    fwrite($pipes[0], $user_input . PHP_EOL);

    // Capture response
    while ($line = fgets($pipes[1])) {
        echo $line;
        if (strpos($line, "UserPrompt>") !== false) {
            break;
        }
    }

    // Calculate response time
    $end_time = microtime(true);
    $response_time = $end_time - $start_time;

    // Display response time
    echo "Response Time: " . round($response_time, 2) . " seconds" . PHP_EOL;

    // Close the pipes
    fclose($pipes[0]);
    fclose($pipes[1]);
    fclose($pipes[2]);

    // Close the process
    proc_close($process);
}
?>

Incorporating CASE AI for ASP.NET Environments

 using System;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Web.UI;

public partial class Chat : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected async void BtnChat_Click(object sender, EventArgs e)
    {
        string userInput = txtUserInput.Text;
        string response = await RunCaseAiChat(userInput);
        lblResponse.Text = response;
    }

    private async Task RunCaseAiChat(string userInput)
    {
        Process process = new Process();
        process.StartInfo.FileName = "CASE.exe";
        process.StartInfo.Arguments = "-talk";
        process.StartInfo.RedirectStandardInput = true;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.CreateNoWindow = true;

        process.Start();

        // Wait for UserPrompt>
        while (!process.StandardOutput.ReadLine().Contains("UserPrompt>")) { }

        // Start timing
        Stopwatch stopwatch = Stopwatch.StartNew();

        // Send user input
        process.StandardInput.WriteLine(userInput);

        // Capture response
        string response = string.Empty;
        string line;
        while ((line = process.StandardOutput.ReadLine()) != null)
        {
            response += line + "
"; if (line.Contains("UserPrompt>")) { stopwatch.Stop(); response += $"Response Time: {stopwatch.Elapsed.TotalSeconds} seconds
"; break; } } process.WaitForExit(); process.Close(); return response; } }