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:
import GoogleGenerativeAI
let palmClient = GenerativeLanguage(apiKey: "YOUR API KEY")
response = try await palmClient.chat(message: "Hello")
This repository contains a few sample apps. To try them out, follow these steps:
git clone https://github.com/google/generative-ai-swift
Examples
folder.API_KEY
property in the PaLM-Info.plist
file.To use the Swift SDK for the PaLM API in your own apps, follow these steps:
Before you can make any API calls, you need to import and initialize the API client.
GoogleGenerativeAI
module:
import GoogleGenerativeAI
let palmClient = GenerativeLanguage(apiKey: "YOUR API KEY")
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)
}
You can find the documentation for the PaLM API at https://developers.generativeai.google.com/guide
See Contributing for more information on contributing to the Generative AI SDK for Swift.
The contents of this repository are licensed under the Apache License, version 2.0.