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 jakarta.annotation.Resource;
|
||||||
import org.springframework.ai.chat.client.ChatClient;
|
import org.springframework.ai.chat.client.ChatClient;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
@RequestMapping("/dashscope")
|
@RequestMapping("/dashscope")
|
||||||
@RestController
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
public class DashScopeController {
|
public class DashScopeController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ChatClient dashScopeChatClient;
|
private ChatClient dashScopeChatClient;
|
||||||
|
|
||||||
@GetMapping(value = "/chat",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
@PostMapping(value = "/chat",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||||
public Flux<String> chat(@RequestParam("userPrompt") String userPrompt) {
|
public Flux<String> chat(@RequestBody String userPrompt) {
|
||||||
return dashScopeChatClient.prompt()
|
return dashScopeChatClient.prompt()
|
||||||
.user(userPrompt)
|
.user(userPrompt)
|
||||||
.stream()
|
.stream()
|
||||||
|
|||||||
Reference in New Issue
Block a user