🎨 代码调整
This commit is contained in:
parent
c06a157e66
commit
c493412066
@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||||
|
import com.rymcu.forest.util.Utils;
|
||||||
import com.theokanning.openai.DeleteResult;
|
import com.theokanning.openai.DeleteResult;
|
||||||
import com.theokanning.openai.OpenAiError;
|
import com.theokanning.openai.OpenAiError;
|
||||||
import com.theokanning.openai.OpenAiHttpException;
|
import com.theokanning.openai.OpenAiHttpException;
|
||||||
@ -38,6 +39,8 @@ import io.reactivex.BackpressureStrategy;
|
|||||||
import io.reactivex.Flowable;
|
import io.reactivex.Flowable;
|
||||||
import io.reactivex.Single;
|
import io.reactivex.Single;
|
||||||
import okhttp3.*;
|
import okhttp3.*;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
import retrofit2.HttpException;
|
import retrofit2.HttpException;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@ -53,6 +56,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import com.rymcu.forest.util.SpringContextHolder;
|
import com.rymcu.forest.util.SpringContextHolder;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
|
||||||
public class OpenAiService {
|
public class OpenAiService {
|
||||||
|
|
||||||
@ -395,10 +400,12 @@ public class OpenAiService {
|
|||||||
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
|
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
|
||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OkHttpClient defaultClient(String token, Duration timeout) {
|
public static OkHttpClient defaultClient(String token, Duration timeout) {
|
||||||
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||||
|
String ip = Utils.getIpAddress(request);
|
||||||
return new OkHttpClient.Builder()
|
return new OkHttpClient.Builder()
|
||||||
.addInterceptor(new AuthenticationInterceptor(token))
|
.addInterceptor(new AuthenticationInterceptor(token))
|
||||||
|
.addInterceptor(new IpAddressInterceptor(ip))
|
||||||
.connectionPool(new ConnectionPool(5, 1, TimeUnit.SECONDS))
|
.connectionPool(new ConnectionPool(5, 1, TimeUnit.SECONDS))
|
||||||
.readTimeout(timeout.toMillis(), TimeUnit.MILLISECONDS)
|
.readTimeout(timeout.toMillis(), TimeUnit.MILLISECONDS)
|
||||||
.build();
|
.build();
|
||||||
|
Loading…
Reference in New Issue
Block a user