Google's Gemini API offers advanced capabilities including real-time grounding with Google Search, server-side code execution, and efficient context caching. Mastering these features enables sophisticated AI applications with current knowledge and computational abilities.
0 / 5 completed
1 / 5
A developer uses Gemini with tools=[Tool(google_search_retrieval=GoogleSearchRetrieval())]. What does grounding with Google Search provide?
Grounding with Google Search allows Gemini to retrieve current information from the web during generation. When Gemini determines a query benefits from fresh data, it performs a search and uses the results as context, citing sources in its response. This reduces hallucinations on time-sensitive factual topics where training data may be outdated.
2 / 5
Gemini's code execution tool (Tool(code_execution=CodeExecution())) runs code in what environment?
Gemini's code execution tool runs Python in a Google-managed secure sandbox. Gemini writes Python code, executes it server-side, receives the output, and incorporates results into its response. This enables data analysis, math computation, and chart generation within a conversation without any client-side execution infrastructure.
3 / 5
What is context caching in the Gemini API and when is it cost-effective?
Gemini's context caching lets you upload a large stable context (e.g., a 100-page document, a long system prompt) to Google's servers. The cached content has a token cost to create but subsequent requests referencing the cache are charged at a lower cache read rate instead of full input token rate. It's cost-effective when the same large context is reused across many requests.
4 / 5
A developer defines a Gemini function with FunctionDeclaration(name='get_weather', parameters=...) and the model responds with a FunctionCall part. What must the developer do next?
Gemini function calling is a client-side execution loop: Gemini returns a FunctionCall part indicating which function to call and with what arguments. The developer executes the function, then sends a new message to the Gemini API with a FunctionResponse part containing the result. Gemini uses this result to generate the final natural language response.
5 / 5
When using Gemini's function calling, what does setting tool_config=ToolConfig(function_calling_config=FunctionCallingConfig(mode='ANY')) force?
Setting mode='ANY' in FunctionCallingConfig forces Gemini to always call a function (one of the declared tools) rather than returning a plain text response. The default AUTO mode lets Gemini decide whether to call a function or respond with text. NONE disables function calling entirely.