filmov
tv
How to integrate Open AI Chat GPT model 'gpt-3.5-turbo' in your Android app?
Показать описание
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);
}
}
--
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);
}
}
--
Комментарии