| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- Registering an InstanceCreator with Gson for this type may fix this problem
- 3rd framework
- xcframework
- mac
- retrofit
- DispatchQueue
- Kotlin
- arm-linux-androideabi
- Jetpack
- Java
- BindingAdapter
- Compose
- IOS
- Android
- ndkVersion
- buildconfigfield
- 3rd part
- EditText
- Andorid
- AOS
- gradle
- Chat GPT
- Framework
- boot
- Swift
- Eclipse
- data binding
- defaultconfig
- VM arguments
- NDK
Archives
- Today
- Total
grape
[android] simple GPT retrofit 1 - setting 본문
OKHttpclient
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;
public class RetrofitGPT {
static Retrofit retrofit = null;
public static OkHttpClient client = null;
static String MYCODE = "";
public static Retrofit getClient(String aServer) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
try {
client = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.addInterceptor(interceptor)
.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
// TODO Auto-generated method stub
String token = "Bearer " + MYCODE;
Request request = chain.request().newBuilder()
.addHeader("Authorization", token)
.build();
return chain.proceed(request);
}
}).build();
retrofit = new Retrofit.Builder().baseUrl(aServer)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.client(client).build();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return retrofit;
}
}
Rest API Interface
import com.google.gson.JsonObject;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Headers;
import retrofit2.http.POST;
public interface GPTRetrofitInterface {
@Headers("Content-Type: application/json")
@POST("completions ")
Call<gptResponse> completions(@Body JsonObject sendJSONObject);
}'dev > aos' 카테고리의 다른 글
| [android] simple GPT retrofit 3 - call (2) | 2023.10.14 |
|---|---|
| [android] simple GPT retrofit 2 - data (0) | 2023.10.13 |
| [android]data binding 5 - mistake error (0) | 2023.10.12 |
| [android]data binding 4 - app custom attribute (0) | 2023.10.12 |
| [android]data binding 3 - Two-way data binding & BindingAdapter example EditText (0) | 2023.10.12 |