mukel / llama3.java

Practical Llama 3 inference in Java
MIT License
514 stars 61 forks source link

runInteractive() Scanner not being closed (small tweak) #10

Closed SkyAphid closed 2 months ago

SkyAphid commented 2 months ago

As requested, I'm opening this small issue just to show you a simple trick to prevent any IDE warnings from appearing in runInteractive():

    static void runInteractive(Llama model, Sampler sampler, Options options) {
        ...
        Scanner in = new Scanner(System.in);
        while (true) {
            ...
            }
        }
    }

The Scanner in isn't being closed- which isn't necessarily a big deal since it'll be closed when the program ends. But for the sake of clean code, you can tweak it to this:

    static void runInteractive(Llama model, Sampler sampler, Options options) {
        ...
        try (Scanner in = new Scanner(System.in)) {
            while (true) {
                ...
            }
        }
    }
SkyAphid commented 2 months ago

I misunderstood your comment- I'm going to open a PR.