package org.studiorailgun.conversation.llm;

import java.util.Scanner;

import org.studiorailgun.conversation.command.CommandParser;
import org.studiorailgun.kobold.KoboldPrinter;
import org.studiorailgun.kobold.KoboldRequest;

public class LLMLoop {
    
    /**
     * The size of the context available
     */
    static final int CONTEXT_SIZE = 32 * 1024;

    /**
     * Controls whether the main parser loop is running
     */
    public static boolean running = true;

    /**
     * The main method
     */
    public static void main(){

        //setup actual input
        Scanner scan = new Scanner(System.in);
        String prompt = "";

        //setup conversation tracking
        LLMConversation convo = new LLMConversation();
        Actor player = new Actor("John");
        Actor ai = new Actor("Dave");
        convo.addParticipant(player);
        convo.addParticipant(ai);

        //actual main loop
        while(running){

            //handle player statement
            prompt = scan.nextLine();
            if(CommandParser.parseCommands(prompt)){
                continue;
            }
            convo.addStatement(new Statement(player, prompt));

            //handle ai statement
            KoboldRequest request = convo.generateStatementRequest(ai);
            request.fire();
            KoboldPrinter printer = new KoboldPrinter(request);
            printer.print();
            System.out.println("[System] Created prompt of size: " + request.getPrompt().length() + " (" + (request.getPrompt().length() / (float)CONTEXT_SIZE) + ")");
            convo.pushbackRequest(ai, request);
        }

        scan.close();
    }

}
