Parcourir la source

Connect to local LLM

atsachlaris il y a 1 semaine
Parent
commit
9027d89756

+ 20 - 0
pom.xml

@@ -64,6 +64,13 @@
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>1.18.32</version>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 
     <build>
@@ -72,6 +79,19 @@
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <annotationProcessorPaths>
+                        <path>
+                            <groupId>org.projectlombok</groupId>
+                            <artifactId>lombok</artifactId>
+                            <version>1.18.32</version>
+                        </path>
+                    </annotationProcessorPaths>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 

+ 18 - 0
requests/llm.http

@@ -0,0 +1,18 @@
+### Chat completion test (vLLM local)
+# !! SSH access to tyrion.uv.es is needed !!
+POST http://127.0.0.1:8090/v1/chat/completions
+Authorization: Bearer hhOQ6QBqHKtOO9MKAUhIyU9auBkgIF40QJKa24jWJzdtxvdXMLi10xUAWMsdpFP0
+Content-Type: application/json
+
+{
+  "model": "/media/nas/peerobs_sync/shared/2025-ReviewSim/models/Qwen2.5-7B-Instruct-AWQ",
+  "messages": [
+    {
+      "role": "user",
+      "content": "What's 1+1"
+    }
+  ],
+  "max_tokens": 100,
+  "temperature": 0.7
+}
+

+ 21 - 0
src/main/java/es/uv/saic/service/EnhancementService.java

@@ -0,0 +1,21 @@
+package es.uv.saic.service;
+
+import org.springframework.ai.chat.client.ChatClient;
+import org.springframework.stereotype.Service;
+
+@Service
+public class EnhancementService {
+
+    private final ChatClient chatClient;
+
+    public EnhancementService(ChatClient.Builder chatClientBuilder) {
+        this.chatClient = chatClientBuilder.build();
+    }
+
+    public String ask(String message) {
+        return chatClient.prompt()
+                .user(message)
+                .call()
+                .content();
+    }
+}

+ 10 - 0
src/main/java/es/uv/saic/web/EnhancementController.java

@@ -1,16 +1,26 @@
 package es.uv.saic.web;
 
+import es.uv.saic.service.EnhancementService;
+import lombok.RequiredArgsConstructor;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 @RestController
 @RequestMapping("/enhancements")
+@RequiredArgsConstructor
 public class EnhancementController {
 
+    private final EnhancementService enhancementService;
+
     @GetMapping("hello")
     public String helloWord() {
         return "Hello World";
     }
 
+    @GetMapping("chat")
+    public String chat(@RequestParam String message) {
+        return enhancementService.ask(message);
+    }
 }

+ 3 - 3
src/main/resources/application-local.properties

@@ -3,6 +3,6 @@ spring.datasource.url=jdbc:postgresql://saicd.uv.es:5432/saic_v2
 spring.datasource.password=docent1ia2.l6
 
 # AI config
-spring.ai.openai.base-url=http://localhost:8000/v1
-spring.ai.openai.api-key=dummy-key
-spring.ai.openai.chat.options.model=dummy_model
+spring.ai.openai.base-url=http://127.0.0.1:8090
+spring.ai.openai.api-key=hhOQ6QBqHKtOO9MKAUhIyU9auBkgIF40QJKa24jWJzdtxvdXMLi10xUAWMsdpFP0
+spring.ai.openai.chat.options.model=/media/nas/peerobs_sync/shared/2025-ReviewSim/models/Qwen2.5-7B-Instruct-AWQ