tjake / Jlama

Jlama is a modern LLM inference engine for Java
Apache License 2.0
665 stars 62 forks source link

Empty return on clean install with only one warning Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' is not supported] #66

Closed urbandroid closed 1 month ago

urbandroid commented 1 month ago

I have tried to test jlama and when short questions asked it returns answer but when i ask specific question it returns empty result in chat facility.

here are the the steps i took:

  1. jbang app install --force jlama@tjake
  2. jlama restapi tjake/Llama-3.2-1B-Instruct-Jlama-Q4 --auto-download
  3. open chat
  4. say hello it returns answer
  5. post question below empty answer is returned.

" something wrong with the supertrend of rsi calculation can you guess what?

package com.example;

import java.util.ArrayList; import java.util.List;

public class SupertrendRSI {

private final int rsiLength;
private final int atrLength;
private final double factor;
private final int smaLength;

// Constructor with default values
public SupertrendRSI() {
    this(14, 10, 3.0, 50);
}

// Constructor with custom values
public SupertrendRSI(int rsiLength, int atrLength, double factor, int smaLength) {
    this.rsiLength = rsiLength;
    this.atrLength = atrLength;
    this.factor = factor;
    this.smaLength = smaLength;
}

// Method to calculate Supertrend of RSI
public List<SupertrendResult> calculateSupertrendOfRSI(List<Price> priceList) {
    RSICalculator rsiCalculator = new RSICalculator();
    List<Double> rsiValues = rsiCalculator.calculateRSI(priceList.stream().map(Price::getClose).toList(), rsiLength);
    List<Double> atrValues = calculateATR(priceList, atrLength);

    // Debugging output
    System.out.println("RSI Values Size: " + rsiValues.size());
    System.out.println("ATR Values Size: " + atrValues.size());

    // Ensure both rsiValues and atrValues have the same size
    int minSize = Math.min(rsiValues.size(), atrValues.size());
    if (minSize < atrLength) { // Ensure we have enough data for ATR
        throw new IllegalStateException("Not enough data for ATR calculation.");
    }

    List<SupertrendResult> supertrendResults = new ArrayList<>();
    Double previousSupertrend = null;
    boolean isUptrend = true;

    for (int i = 0; i < minSize; i++) {
        if (rsiValues.get(i) == null || atrValues.get(i) == null) {
            supertrendResults.add(new SupertrendResult(null, null, null));
            continue;
        }

        double upperBand = rsiValues.get(i) + (factor * atrValues.get(i));
        double lowerBand = rsiValues.get(i) - (factor * atrValues.get(i));
        double supertrend;

        if (previousSupertrend == null) {
            supertrend = rsiValues.get(i);
            previousSupertrend = supertrend;
        } else {
            // Update Supertrend logic
            if (isUptrend) {
                previousSupertrend = Math.max(previousSupertrend, lowerBand);
                if (rsiValues.get(i) < previousSupertrend) {
                    isUptrend = false;
                    supertrend = upperBand; // Reverse trend
                } else {
                    supertrend = previousSupertrend;
                }
            } else {
                previousSupertrend = Math.min(previousSupertrend, upperBand);
                if (rsiValues.get(i) > previousSupertrend) {
                    isUptrend = true;
                    supertrend = lowerBand; // Reverse trend
                } else {
                    supertrend = previousSupertrend;
                }
            }
        }

        supertrendResults.add(new SupertrendResult(supertrend, upperBand, lowerBand));
    }

    return supertrendResults;
}

// Method to calculate ATR
private List<Double> calculateATR(List<Price> priceList, int period) {
    List<Double> atrValues = new ArrayList<>();
    List<Double> trValues = new ArrayList<>();

    // Calculate True Range (TR)
    for (int i = 1; i < priceList.size(); i++) {
        Price current = priceList.get(i);
        Price previous = priceList.get(i - 1);

        double high = current.getHigh();
        double low = current.getLow();
        double previousClose = previous.getClose();

        // Calculate True Range
        double tr = Math.max(high - low, Math.max(Math.abs(high - previousClose), Math.abs(low - previousClose)));
        trValues.add(tr);
    }

    // Calculate ATR based on the true range values
    for (int i = 0; i < trValues.size(); i++) {
        if (i < period - 1) {
            atrValues.add(null); // Insufficient data for ATR calculation
        } else {
            double sum = 0;
            for (int j = i - period + 1; j <= i; j++) {
                sum += trValues.get(j);
            }
            atrValues.add(sum / period); // Calculate average
        }
    }

    // Add nulls for remaining entries to match original priceList size
    while (atrValues.size() < priceList.size()) {
        atrValues.add(null);
    }

    return atrValues;
}

} "

tjake commented 1 month ago

Huh super interesting, thanks for the report. I'll take a look

tjake commented 1 month ago

The issue was I had the max tokens fixed to 1024, Ive changed it to be the model max. Fix will be in next release