package com.iwe3.langchain4j.controller;

import dev.langchain4j.model.chat.ChatModel;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class LangChain4JController
{
    // http://localhost:9001/langchain4j/hello?question=如何学习LangChain4J

    @Resource
    private ChatModel chatModel;

    @GetMapping(value = "/langchain4j/hello")
    public String hello(@RequestParam(value = "question",defaultValue = "你是谁") String question)
    {
        var result = chatModel.chat(question);
        System.out.println("通过langchain4j调用模型返回结果：\n"+result);
        return result;
    }
}