How to integrate Open AI Chat GPT model 'gpt-3.5-turbo' in your Android app?

preview_player
Показать описание
In this video it shows the steps to integrate the Chat GPT APIs of "gpt-3.5-turbo" model in your Android App. It uses Android's volley library to call the GPT APIs from the Json object.

Complete source code and other details/ steps of this video are posted in the below link:

However, the main Java code is copied below also for reference:

public class MainActivity extends AppCompatActivity {
private TextView textView;
private String stringAPIKey = "sk-8pKdd8YoyxxxxxxxxxxXXXXXbkFJX2tPPkoXzpegNelf8NS5";
private String stringOutput = "";

@Override
protected void onCreate(Bundle savedInstanceState) {

}

public void buttonChatGPT(View view){
JSONObject jsonObject = new JSONObject();

try {

JSONArray jsonArrayMessage = new JSONArray();
JSONObject jsonObjectMessage = new JSONObject();

} catch (JSONException e) {
throw new RuntimeException(e);
}

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
stringURLEndPoint, jsonObject, new Response.Listener ANGULAR_BRACKET JSONObject ANGULAR_BRACKET () {
@Override
public void onResponse(JSONObject response) {

String stringText = null;
try {
.getJSONObject(0)
.getJSONObject("message")
.getString("content");
} catch (JSONException e) {
throw new RuntimeException(e);
}

stringOutput = stringOutput + stringText;
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
}){
@Override
public MapANGULAR_BRACKETString, StringANGULAR_BRACKET getHeaders() throws AuthFailureError {
MapANGULAR_BRACKETString, StringANGULAR_BRACKET mapHeader = new HashMapANGULAR_BRACKET();

return mapHeader;
}

@Override
protected Response ANGULAR_BRACKET JSONObjectANGULAR_BRACKET parseNetworkResponse(NetworkResponse response) {
}
};

int intTimeoutPeriod = 60000; // 60 seconds timeout duration defined
RetryPolicy retryPolicy = new DefaultRetryPolicy(intTimeoutPeriod,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
}
}

--
Рекомендации по теме
Комментарии
Автор

Thanks my friend. gpt-3.5-turbo model worked for me, appreciate your efforts, great video.

prasoonpandey
Автор

SEND FOR ALL USER : model in this code was deleted, you can replace this by "gpt-3.5-turbo-instruct"

AKTHPTTANHLINH
Автор

how do you learn this, i also want to learn to figure out on my own how to write code by looking into gpt document??

paragbharadia
Автор

is this api with prices ? and how much bro ?

didiwaytrooo