leutu
2024-06-19 28fc8b028099f0fd4719b0a35d4fb98a728d73cd
src/main/java/com/yb/controller/AiController.java
@@ -3,9 +3,11 @@
import com.alibaba.fastjson.JSON;
import com.yb.util.OkHttpUtil;
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 +22,7 @@
import java.util.Set;
@Tag(name="terra openai")
@RestController
@RequestMapping("/api/v1")
public class AiController {
@@ -32,6 +35,8 @@
    @Value("${spring.intent}")
    String intent ;
    @GetMapping("/chat")
    public String chat(@RequestParam(value = "message",defaultValue = "Hi") String message){
        return chatModel.call("请用中文回答如下问题,如果有地名出现,回到内容包括经纬度并使用json返回,"+message);
@@ -40,8 +45,9 @@
    @GetMapping("/intent")
    public String intent(@RequestParam(value = "message",defaultValue = "Hi") String message){
        String json = okHttpUtil.getMessage(intent+"="+message);
        return json ;
        Map<String,String> hashMap = new HashMap<>() ;
        iteraJson(json,hashMap);
        return  JSON.toJSON(hashMap).toString() ;
    }
    public  boolean iteraJson(String str, Map res){
        if(str.toString().indexOf(":") == -1){
@@ -62,7 +68,8 @@
    @GetMapping("/mix")
    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);
@@ -76,8 +83,28 @@
        }else{
            json = hashMap.put("content", chatModel.call("请用中文回答如下问题,如果有地名出现,回到内容包括经纬度并使用json返回,"+message));
        }
        return json ;
        System.out.println(JSON.toJSON(hashMap).toString());
        System.out.println("====================================");
        return JSON.toJSON(hashMap).toString() ;
    }
    @GetMapping("/fastgpt")
    public String fastgpt(@RequestParam(value = "message",defaultValue = "Hi") String message){
        okHttpUtil.requesFast(message);
        String json = okHttpUtil.requesFast(message);
        return  json ;
    }
    @GetMapping("/fastgpt_list")
    public String fastgpt_list(String parentId){
        String json = okHttpUtil.requesFast_kl(parentId);
        return  json ;
    }
}