package com.example.block18springai.controller;

import com.example.block18springai.ai_config.ApiKeys;
import com.example.block18springai.ai_config.Assistant;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/ai")
@RestController
public class AIController_LangChain4j {
    ChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(10);

    Assistant assistant = AiServices.builder(Assistant.class)
            .chatLanguageModel(OpenAiChatModel.withApiKey(ApiKeys.OPENAI_API_KEY))
            .chatMemory(chatMemory)
            .build();

    @PostMapping("/message")
    public String chat(@RequestParam String message) {
        return  assistant.chat(message);
    }

}

dev.langchain4j.service.AiServices.builder
[((784, 959), 'dev.langchain4j.service.AiServices.builder'), ((784, 938), 'dev.langchain4j.service.AiServices.builder'), ((784, 902), 'dev.langchain4j.service.AiServices.builder')]