feat: ollama流式应答接口实现
This commit is contained in:
@@ -23,18 +23,18 @@
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-tika-document-reader</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-pgvector-store</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.ai</groupId>-->
|
||||
<!-- <artifactId>spring-ai-openai-spring-boot-starter</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.ai</groupId>-->
|
||||
<!-- <artifactId>spring-ai-tika-document-reader</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.ai</groupId>-->
|
||||
<!-- <artifactId>spring-ai-pgvector-store</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-ollama</artifactId>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.storm.dev.trigger.http;
|
||||
|
||||
import com.storm.dev.api.IAiService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.ai.chat.ChatResponse;
|
||||
import org.springframework.ai.chat.prompt.Prompt;
|
||||
import org.springframework.ai.ollama.OllamaChatClient;
|
||||
import org.springframework.ai.ollama.api.OllamaOptions;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author: lyd
|
||||
* @date: 2025/6/7 22:18
|
||||
*/
|
||||
@RestController()
|
||||
@CrossOrigin("*")
|
||||
@RequestMapping("/api/v1/ollama/")
|
||||
public class OllamaController implements IAiService {
|
||||
|
||||
@Resource
|
||||
private OllamaChatClient chatClient;
|
||||
|
||||
/**
|
||||
* http://localhost:8090/api/v1/ollama/generate?model=deepseek-r1:1.5b&message=1+1
|
||||
*/
|
||||
@GetMapping("generate")
|
||||
@Override
|
||||
public ChatResponse generate(@RequestParam String model, @RequestParam String message) {
|
||||
return chatClient.call(new Prompt(message, OllamaOptions.create().withModel(model)));
|
||||
}
|
||||
|
||||
/**
|
||||
* http://localhost:8090/api/v1/ollama/generate_stream?model=deepseek-r1:1.5b&message=hi
|
||||
*/
|
||||
@GetMapping("generate_stream")
|
||||
@Override
|
||||
public Flux<ChatResponse> generateStream(@RequestParam String model, @RequestParam String message) {
|
||||
return chatClient.stream(new Prompt(message, OllamaOptions.create().withModel(model)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 触发器
|
||||
* @author: lyd
|
||||
* @date: 2025/6/7 22:17
|
||||
*/
|
||||
package com.storm.dev.trigger;
|
||||
Reference in New Issue
Block a user