feat(dashscope): 支持跨域并修改聊天接口为POST请求
- 添加了@CrossOrigin注解以支持跨域访问 - 将/chat接口从GET请求改为POST请求- 修改请求参数接收方式为@RequestBody - 移除了不必要的导入语句
This commit is contained in:
@@ -3,21 +3,19 @@ package com.hanserwei.snailsai.controller;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.http.MediaType;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
@RequestMapping("/dashscope")
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class DashScopeController {
|
||||
|
||||
@Resource
|
||||
private ChatClient dashScopeChatClient;
|
||||
|
||||
@GetMapping(value = "/chat",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public Flux<String> chat(@RequestParam("userPrompt") String userPrompt) {
|
||||
@PostMapping(value = "/chat",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public Flux<String> chat(@RequestBody String userPrompt) {
|
||||
return dashScopeChatClient.prompt()
|
||||
.user(userPrompt)
|
||||
.stream()
|
||||
|
||||
Reference in New Issue
Block a user