| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- mac
- defaultconfig
- AOS
- Andorid
- buildconfigfield
- Android
- Kotlin
- gradle
- boot
- xcframework
- DispatchQueue
- Java
- Swift
- arm-linux-androideabi
- ndkVersion
- data binding
- Jetpack
- 3rd framework
- VM arguments
- 3rd part
- NDK
- Registering an InstanceCreator with Gson for this type may fix this problem
- BindingAdapter
- EditText
- Compose
- Chat GPT
- IOS
- retrofit
- Framework
- Eclipse
Archives
- Today
- Total
grape
[android] simple GPT retrofit 3 - call 본문
void requestGPT(final String requestText){
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
String domain ="https://api.openai.com/v1/chat/";
GPTRetrofitInterface mRetrofitInterface = RetrofitGPT
.getClient(domain).create(GPTRetrofitInterface.class);
try {
gptBody body = new gptBody();
body.model = "gpt-3.5-turbo";
body.messages[0].role = "user";
body.messages[0].content = requestText;
Gson gson = new Gson();
String json = gson.toJson(body);
JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject();
Call<gptResponse> call = mRetrofitInterface.completions(jsonObject);
Response<gptResponse> response = call.execute();
if (response.code() == 200) {
System.out.println(response);
final gptResponse res = response.body();
runOnUiThread(new Runnable() {
public void run() {
myTextView.append(String.format("GPT(%d)\n", gptTime));
myTextView.append(res.choices[0].message.content);
}
});
}
else {
//[Todo] onError
Throwable e = new Throwable("send_response_code_"+response.code());
System.out.println(e);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println(e);
}
}
}).start();
}
'dev > aos' 카테고리의 다른 글
| [android]ViualStudio Xamarin 환경 설정. (2) | 2023.11.21 |
|---|---|
| [android] android studio build setting issue - Unsupported Java. Your build is currently configured to use Java 17.0.6 and Gradle (0) | 2023.10.14 |
| [android] simple GPT retrofit 2 - data (0) | 2023.10.13 |
| [android] simple GPT retrofit 1 - setting (0) | 2023.10.13 |
| [android]data binding 5 - mistake error (0) | 2023.10.12 |