leutu
2024-06-24 3f1ea1e3240f045412189619d7e4021d5f26a4f2
src/main/java/com/yb/controller/AiController.java
@@ -3,9 +3,12 @@
import com.alibaba.fastjson.JSON;
import com.yb.util.OkHttpUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import net.sf.json.JSONObject;
import okhttp3.Response;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -20,6 +23,7 @@
import java.util.Set;
@Tag(name="terra openai")
@RestController
@RequestMapping("/api/v1")
public class AiController {
@@ -32,12 +36,16 @@
    @Value("${spring.intent}")
    String intent ;
    @GetMapping("/chat")
    @Operation(summary = "大模型对话")
    public String chat(@RequestParam(value = "message",defaultValue = "Hi") String message){
        return chatModel.call("请用中文回答如下问题,如果有地名出现,回到内容包括经纬度并使用json返回,"+message);
    }
    @GetMapping("/intent")
    @Operation(summary = "意图请求")
    public String intent(@RequestParam(value = "message",defaultValue = "Hi") String message){
        String json = okHttpUtil.getMessage(intent+"="+message);
        Map<String,String> hashMap = new HashMap<>() ;
@@ -62,8 +70,10 @@
    }
    @GetMapping("/mix")
    @Operation(summary = "意图与大模型请求")
    public String mix(@RequestParam(value = "message",defaultValue = "Hi") String message){
        String json = okHttpUtil.getMessage(intent+"="+message);
        String json = okHttpUtil.postFastgpt(message);
        System.out.println(message);
//        JSONObject jsonObject = JSONObject.parseObject(json);
        Map<String,String> hashMap = new HashMap<>() ;
        iteraJson(json,hashMap);
@@ -77,8 +87,30 @@
        }else{
            json = hashMap.put("content", chatModel.call("请用中文回答如下问题,如果有地名出现,回到内容包括经纬度并使用json返回,"+message));
        }
        System.out.println(JSON.toJSON(hashMap).toString());
        System.out.println("====================================");
        return JSON.toJSON(hashMap).toString() ;
    }
    @GetMapping("/fastgpt")
    @Operation(summary = "知识库查询")
    public String fastgpt(@RequestParam(value = "message",defaultValue = "三维实景") String message){
        okHttpUtil.requesFast(message);
        String json = okHttpUtil.requesFast(message);
        return  json ;
    }
    @GetMapping("/fastgpt_list")
    @Operation(summary = "知识库列表")
    public String fastgpt_list(){
        String json = okHttpUtil.requesFast_kl();
        return  json ;
    }
}