I’m trying to build a simple chat app using the Gemini AI SDK and one step is to create a ChatManager as follows:
import com.google.ai.client.generativeai.GenerativeModel;
import com.google.ai.client.generativeai.models.Content;
import com.google.ai.client.generativeai.models.Text;
import java.util.ArrayList;
import java.util.List;
public class ChatManager {
private GenerativeModel model;
private List<Content> chatHistory = new ArrayList<>();
public ChatManager(String apiKey) {
this.model = GenerativeModel.fromApiKey(apiKey);
}
public String sendMessage(String message) {
chatHistory.add(Content.builder().parts(List.of(Text.builder().text(message).build())).build());
GenerativeModel.Response response = model.generateText(chatHistory);
String aiResponse = response.candidates().get(0).output();
chatHistory.add(Content.builder().parts(List.of(Text.builder().text(aiResponse).build())).build());
return aiResponse;
}
}
My app-level gradle file includes the following dependency:
implementation 'com.google.ai.client.generativeai:generativeai:0.7.0'
However, the app is unable to import the two com.google.ai.client.generativeai.models.* libraries. After digging around, I believe it’s because I’m in the EU region and in order to import the libraries, I needed to enable the paid tier in GCP. I did that and rebuilt the app, but I still can’t access the libraries.
Anyone here know what the problem is?