if (FALSE) {
# Synchronous text generation with grounding:
result <- geminiGrounding4R(
mode = "text",
contents = "What is the current Google stock price?",
store_history = FALSE,
debug = TRUE, # Enable debug to see request details
api_key = Sys.getenv("GoogleGemini_API_KEY")
)
print(result)
# Basic text generation without grounding (for troubleshooting):
basic_result <- geminiGrounding4R(
mode = "text",
contents = "Hello, how are you?",
enable_grounding = FALSE,
debug = TRUE,
api_key = Sys.getenv("GoogleGemini_API_KEY")
)
print(basic_result)
# Chat mode with history storage:
chat_history <- list(
list(role = "user", text = "Hello"),
list(role = "model", text = "Hi there! How can I help you?")
)
chat_result <- geminiGrounding4R(
mode = "chat",
contents = chat_history,
store_history = TRUE,
dynamic_threshold = 0.7,
api_key = Sys.getenv("GoogleGemini_API_KEY")
)
print(chat_result)
# Streaming text generation:
stream_result <- geminiGrounding4R(
mode = "stream_text",
contents = "Tell me a story about a magic backpack.",
store_history = FALSE,
dynamic_threshold = 0.7,
api_key = Sys.getenv("GoogleGemini_API_KEY")
)
print(stream_result$full_text)
}
Run the code above in your browser using DataLab