File tree Expand file tree Collapse file tree
java/com/example/spring/app/llm Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ dependencies {
1717 implementation ' org.springframework.boot:spring-boot-starter-data-jpa'
1818 implementation ' org.springframework.boot:spring-boot-starter-oauth2-resource-server'
1919 implementation ' org.springframework.boot:spring-boot-starter-web'
20+ implementation platform(" org.springframework.ai:spring-ai-bom:1.0.0" )
21+ implementation ' org.springframework.ai:spring-ai-starter-model-openai'
2022 implementation ' org.springframework.boot:spring-boot-starter-security'
2123 implementation ' org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'
2224 implementation ' org.springframework.boot:spring-boot-starter-validation'
Original file line number Diff line number Diff line change 1+ package com .example .spring .app .llm ;
2+
3+ import org .springframework .ai .chat .client .ChatClient ;
4+ import org .springframework .web .bind .annotation .*;
5+
6+ @ CrossOrigin
7+ @ RestController
8+ @ RequestMapping ("/v1" )
9+ public class LLMController {
10+
11+ private final ChatClient chatClient ;
12+
13+ public LLMController (ChatClient .Builder chatClientBuilder ) {
14+ this .chatClient = chatClientBuilder .build ();
15+ }
16+
17+ @ GetMapping ("/ai" )
18+ String generation (String userInput ) {
19+ return this .chatClient .prompt ()
20+ .user (userInput )
21+ .call ()
22+ .content ();
23+ }
24+ }
Original file line number Diff line number Diff line change @@ -34,3 +34,8 @@ resilience4j.ratelimiter.instances.scrapService.timeout-duration=30s
3434
3535# Spring
3636spring.profiles.active =${SPRING_PROFILES_ACTIVE}
37+
38+ # Spring AI
39+ spring.ai.openai.api-key =ollama
40+ spring.ai.openai.base-url =http://localhost:11434/
41+ spring.ai.openai.chat.options.model =mistral:7b
You can’t perform that action at this time.
0 commit comments