| | |
| | | package com.yb.util; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.google.gson.Gson; |
| | | import com.yb.entity.ResponseEntity; |
| | | import okhttp3.*; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | |
| | | return null ; |
| | | } |
| | | |
| | | @Async |
| | | public String requesFast(String message){ |
| | | OkHttpClient client = new OkHttpClient(); |
| | | System.out.println("fastgpt:"+message) ; |
| | | OkHttpClient client = new OkHttpClient(); |
| | | Response response = null ; |
| | | // 创建请求头(Headers) |
| | | okhttp3.Headers headers = new okhttp3.Headers.Builder() |
| | | .add("Authorization", "Bearer fastgpt-rML09d7nyx8Bn2Al3UipZia3Q8FNuXdekU1nyMlgCfHNwS8NN1giSPNZ1y6Wmt") |
| | | .add("Authorization", "Bearer "+apikey) |
| | | .build(); |
| | | |
| | | /* |
| | |
| | | // 构建请求体(RequestBody),这里使用的是字符串类型的请求数据 |
| | | |
| | | HashMap<String,Object> hashMap = new HashMap<>() ; |
| | | hashMap.put("chatId",""+Math.random()*100000); |
| | | hashMap.put("chatId","1111"); |
| | | hashMap.put("stream","false"); |
| | | hashMap.put("detail","false"); |
| | | List<HashMap<String,String>> list = new ArrayList<>(); |
| | |
| | | if (response.isSuccessful()) { |
| | | //System.out.println("Success: " + response.body().string()); |
| | | String rep = response.body().string(); |
| | | return rep ; |
| | | if( rep.indexOf("flowResponses") > 0) { |
| | | int index = rep.indexOf("flowResponses"); |
| | | int index_s = rep.indexOf("data", index); |
| | | String data = rep.substring(index_s + 5); |
| | | System.out.println("data is ok...."); |
| | | return data; |
| | | }else{ |
| | | return rep ; |
| | | } |
| | | } else { |
| | | System.out.println("Error: " + response.code() + " " + response.message()); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | return response != null?response.body().toString():"null" ; |
| | | return null ; |
| | | } |
| | | |
| | | public String requesFast_kl(String parentId){ |
| | | public String requesFast_kl(){ |
| | | OkHttpClient client = new OkHttpClient(); |
| | | Response response = null ; |
| | | // 创建请求头(Headers) |
| | | okhttp3.Headers headers = new okhttp3.Headers.Builder() |
| | | .add("Authorization", "Bearer fastgpt-rML09d7nyx8Bn2Al3UipZia3Q8FNuXdekU1nyMlgCfHNwS8NN1giSPNZ1y6Wmt") |
| | | .add("Authorization", "Bearer "+apikey) |
| | | .build(); |
| | | |
| | | /* |
| | |
| | | |
| | | |
| | | // 创建请求(Request) |
| | | if( parentId != null ) fastgpt_kl = fastgpt_kl+"?parentId="+parentId; |
| | | |
| | | okhttp3.Request.Builder builder = new okhttp3.Request.Builder() |
| | | .url(fastgpt_kl) |
| | | .headers(headers) ; |
| | |
| | | response = client.newCall(request).execute(); |
| | | if (response.isSuccessful()) { |
| | | //System.out.println("Success: " + response.body().string()); |
| | | String rep = response.body().string(); |
| | | String rep = response.body().toString(); |
| | | |
| | | return rep ; |
| | | } else { |
| | | System.out.println("Error: " + response.code() + " " + response.message()); |