I want to kno how can i use the theokanning java library to develop system using open ai for android studio to develop android app. Is this correct as it kept crashing when i run it?

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.robotemi.sdk.Robot;
import com.robotemi.sdk.listeners.OnRobotReadyListener;
import com.theokanning.openai.completion.chat.ChatCompletionRequest;
import com.theokanning.openai.completion.chat.ChatMessage;
import com.theokanning.openai.completion.chat.ChatMessageRole;
import com.theokanning.openai.service.OpenAiService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class GPTActivity extends AppCompatActivity {
private TextView textView;
private List messages = new ArrayList<>();
private static final String TAG = GPTActivity.class.getSimpleName();
private static Robot sRobot;

protected void onCreate(@Nullable Bundle savedInstanceState) {

    sRobot = Robot.getInstance();

    ChatMessage userMessage = new ChatMessage(ChatMessageRole.USER.value(), "Hello, do you think you are smart?");

public void getApiResponse(){

    Robot sRobot = Robot.getInstance();

    String token = System.getenv("Bearer ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■TFILgDBN");
    OpenAiService service = new OpenAiService(token);

        ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest
                .logitBias(new HashMap<>())
        ChatMessage responseMessage = service.createChatCompletion(chatCompletionRequest).getChoices().get(0).getMessage();
        messages.add(responseMessage); // don't forget to update the conversation with the latest response

        String response = responseMessage.getContent();

        // Find the TextView by its ID
        textView = findViewById(R.id.textView);
        // Set or update the text dynamically
        String newText = response;



Hi and welcome to the Developer Forum!

This seems to be using libraries that are not created or maintained by OpenAI, have you reached out to the heoKanning repo maintainers?

1 Like

how can one apply the theokanning in android studio rather to understand?

You might try the heoKJanning community, I personally do not know it.