Skip to content

Sentiment analysis hanging 0.8.4 #162

@fancellu

Description

@fancellu

Hangs with Jlama (my 7950x is running at 65% cpu!!), emits POSITIVE false with Gemini

import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.googleai.GoogleAiGeminiChatModel;
import dev.langchain4j.model.jlama.JlamaChatModel;
import dev.langchain4j.service.AiServices;

import java.nio.file.Path;

public class JlamaSentimentBug {

    static enum Sentiment {
        POSITIVE, NEUTRAL, NEGATIVE
    }

    // Define the AI-powered Sentiment Analyzer interface
    interface SentimentAnalyzer {

        @dev.langchain4j.service.UserMessage("Analyze sentiment of {{it}}")
        Jlama.Sentiment analyzeSentimentOf(String text);

        @dev.langchain4j.service.UserMessage("Does {{it}} have a positive sentiment?")
        boolean isPositive(String text);
    }

    public static void sentiment(ChatLanguageModel model){
        Jlama.SentimentAnalyzer sentimentAnalyzer = AiServices.create(Jlama.SentimentAnalyzer.class, model);

        // Example Sentiment Analysis
        Jlama.Sentiment sentiment = sentimentAnalyzer.analyzeSentimentOf("I love this product!");
        System.out.println(sentiment); // Expected Output: POSITIVE

        boolean positive = sentimentAnalyzer.isPositive("This is a terrible experience.");
        System.out.println(positive); // Expected Output: false
    }

    public static void main(String[] args) {

        ChatLanguageModel model = JlamaChatModel.builder()
                .modelCachePath(Path.of("jlamaCache"))
                .modelName("tjake/Llama-3.2-1B-Instruct-JQ4")
                .build();

//        String apiKey = System.getenv("GEMINI_API_KEY");
//        if (apiKey == null) {
//            System.out.println("GEMINI_API_KEY is not set");
//        } else {
//            System.out.println("GEMINI_API_KEY is set");
//        }
//
//
//        ChatLanguageModel model = GoogleAiGeminiChatModel.builder()
//                .apiKey(apiKey)
//                .modelName("gemini-2.0-flash")
//                .build();


        sentiment(model);

    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions