Path
Google Gemini
Build with the Gemini API in Python: prompts, system instructions, chat, streaming, structured output, function calling, embeddings, token limits and errors.
By Deboistech 10 labs 2 h 24 minBeginner to intermediate
Showing 1 of 10 labs.
- Subscription Your first Gemini request Send a prompt, read the answer and token usage, and keep the API key out of your code.
- Subscription Prompts and system instructions Shape answers with a system instruction, few-shot examples and context you paste into the prompt.
- Subscription Generation settings and finish reasons Control length, randomness and stopping with the generation config, and read why an answer ended.
- Subscription Multi-turn chat Hold a conversation with chats.create, read and restore its history, and see why context grows.
- Subscription Streaming responses Print an answer as it is produced with generate_content_stream and read usage from the last chunk.
- Subscription Structured output and JSON Get JSON that fits a schema instead of free text, parse it safely and validate what comes back.
- Subscription Function calling Let the model ask your code to run a function, in automatic mode and in a manual loop.
- Subscription Embeddings and semantic search Turn text into vectors, compare them with cosine similarity, and search and answer by meaning.
- Subscription Tokens, limits and cost Count tokens before you send, read model limits, trim chat history and estimate what a call costs.
- Subscription Errors, retries and safety Handle API errors by class, retry with backoff, react to safety blocks, set timeouts and log calls.
