Skip to content

Latest commit

 

History

History

samples

Gemini API Swift SDK sample code

This directory contains sample code for key features of the SDK, organised by high level feature.

These samples are embedded in parts of the documentation, most notably in the API reference.

Each file is structured as a runnable test case, ensuring that samples are executable and functional. Each test demonstrates a single concept, and contains region tags that are used to demarcate the test scaffolding from the spotlight code. If you are contributing, code within region tags should follow sample code best practices - being clear, complete and concise.

Contents

File Description
APIKey.swift Setting up your API key
ChatSnippets.swift Multi-turn chat conversations
CodeExecution.swift Executing code
ControlledGeneration.swift Generating content with output constraints (e.g. JSON mode)
CountTokens.swift Counting input and output tokens
FunctionCalling.swift Using function calling
GenerationConfig.swift Setting model parameters
SafetySettings.swift Setting and using safety controls
SystemInstructions.swift Setting system instructions
TextGeneration.swift Generating text