public class GeminiClient extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static boolean |
debug |
static okhttp3.OkHttpClient |
httpClient |
| 构造器和说明 |
|---|
GeminiClient() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
chatWithModel(String model,
String role,
String prompt) |
static String |
chatWithModel(String apiKey,
String model,
String role,
String prompt) |
static GeminiChatResponseVo |
generate(String modelName,
GeminiChatRequestVo requestVo) |
static okhttp3.Response |
generate(String modelName,
String bodyString) |
static GeminiChatResponseVo |
generate(String googleApiKey,
String modelName,
GeminiChatRequestVo requestVo)
单次生成内容 (同步请求)
POST https://generativelanguage.googleapis.com/v1beta/models/{model_name}:generateContent?
|
static okhttp3.Response |
generate(String googleApiKey,
String modelName,
String bodyString) |
static GeminiChatResponseVo |
generate(String baseUrl,
String googleApiKey,
String modelName,
GeminiChatRequestVo requestVo) |
static okhttp3.Call |
stream(String modelName,
GeminiChatRequestVo requestVo,
okhttp3.Callback callback) |
static okhttp3.Call |
stream(String modelName,
String bodyString,
okhttp3.Callback callback) |
static okhttp3.Call |
stream(String googleApiKey,
String modelName,
GeminiChatRequestVo requestVo,
okhttp3.Callback callback)
流式生成内容 (SSE,异步请求)
POST https://generativelanguage.googleapis.com/v1beta/models/{model_name}:streamGenerateContent?
|
static okhttp3.Call |
stream(String googleApiKey,
String modelName,
String bodyString,
okhttp3.Callback callback) |
static FileUploadResponseVo |
uploadFile(byte[] bytes)
重载方法,从环境变量中获取 API Key
|
static String |
uploadFile(String googleApiKey,
byte[] bytes)
上传文件到 Google Gemini API
|
public static boolean debug
public static final okhttp3.OkHttpClient httpClient
public static GeminiChatResponseVo generate(String googleApiKey, String modelName, GeminiChatRequestVo requestVo)
googleApiKey - - 你的 Google API KeymodelName - - 要使用的模型名称,如 "gemini-1.5-flash"requestVo - - 请求体实体public static GeminiChatResponseVo generate(String baseUrl, String googleApiKey, String modelName, GeminiChatRequestVo requestVo)
public static GeminiChatResponseVo generate(String modelName, GeminiChatRequestVo requestVo)
public static okhttp3.Response generate(String googleApiKey, String modelName, String bodyString)
public static String chatWithModel(String model, String role, String prompt)
model - role - prompt - public static String chatWithModel(String apiKey, String model, String role, String prompt)
apiKey - model - role - prompt - public static okhttp3.Call stream(String googleApiKey, String modelName, GeminiChatRequestVo requestVo, okhttp3.Callback callback)
googleApiKey - - 你的 Google API KeymodelName - - 要使用的模型名称requestVo - - 请求体callback - - 用于处理 SSE 流式回调public static okhttp3.Call stream(String modelName, GeminiChatRequestVo requestVo, okhttp3.Callback callback)
public static okhttp3.Call stream(String modelName, String bodyString, okhttp3.Callback callback)
public static okhttp3.Call stream(String googleApiKey, String modelName, String bodyString, okhttp3.Callback callback)
public static String uploadFile(String googleApiKey, byte[] bytes)
googleApiKey - - 你的 Google API Keypublic static FileUploadResponseVo uploadFile(byte[] bytes)
displayName - - 文件的显示名称file - - 要上传的文件mimeType - - 文件的 MIME 类型Copyright © 2025. All rights reserved.