Click on Add Package. Xcode will now add the GoogleGenerativeAI to your project.
Initializing the API client
Before you can make any API calls, you need to import and initialize the API
client.
Import the GoogleGenerativeAI module:
import GoogleGenerativeAI
Initialize the API client:
let palmClient = GenerativeLanguage(apiKey: "YOUR API KEY")
Calling the API
Now you’re ready to call the PaLM API’s methods.
Note: All API methods are asynchronous, so you need to call them using Swift’s
async/await.
For example, here is how you can call the generateText method to summarize a Wikipedia article:
let prompt = "Summarise the following text: https://wikipedia.org/..."
let response = try await palmClient.generateText(with: prompt)
if let candidate = response?.candidates?.first, let text = candidate.output {
print(text)
}
Google Generative AI SDK for Swift
The Google Generative AI SDK for Swift allows developers to use state-of-the-art Large Language Models (LLMs) to build language applications.
Once you’ve added the Swift package to your Swift application, you can call the API as follows:
Getting Started
This repository contains a few sample apps. To try them out, follow these steps:
Examples
folder.API_KEY
property in thePaLM-Info.plist
file.Using the PaLM SDK in your own app
To use the Swift SDK for the PaLM API in your own apps, follow these steps:
Initializing the API client
Before you can make any API calls, you need to import and initialize the API client.
GoogleGenerativeAI
module:Calling the API
Now you’re ready to call the PaLM API’s methods.
For example, here is how you can call the
generateText
method to summarize a Wikipedia article:Documentation
You can find the documentation for the PaLM API at https://developers.generativeai.google.com/guide
Contributing
See Contributing for more information on contributing to the Generative AI SDK for Swift.
License
The contents of this repository are licensed under the Apache License, version 2.0.