Created
February 5, 2025 15:09
-
-
Save rakia/3d0184a3547adf6fb5c396c43e141711 to your computer and use it in GitHub Desktop.
A spring boot REST controller to connect to Gemini API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.ai.chat.prompt.Prompt; | |
import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatModel; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.web.bind.annotation.*; | |
@RestController | |
@RequestMapping("/api/gemini") | |
public class GeminiController { | |
@Autowired | |
private VertexAiGeminiChatModel chatModel; | |
public GeminiController(VertexAiGeminiChatModel chatModel) { | |
this.chatModel = chatModel; | |
} | |
@GetMapping("/chat") | |
public String chat(@RequestParam String message) { | |
Prompt prompt = new Prompt(message); | |
return chatModel.call(prompt).getResult().getOutput().getContent(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment