Skip to content

Commit 9bb7ae3

Browse files
committed
Aligning the README with the Python's one
1 parent 5478400 commit 9bb7ae3

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

README.md

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,57 @@
1+
# Google AI SDK for Swift
2+
13
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fgoogle-gemini%2Fgenerative-ai-swift%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/google-gemini/generative-ai-swift)
24
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fgoogle-gemini%2Fgenerative-ai-swift%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/google-gemini/generative-ai-swift)
35

4-
# Google AI SDK for Swift
6+
The Google AI Swift SDK is the easiest way for Swift developers to build with the Gemini API. The Gemini API gives you access to Gemini [models](https://ai.google.dev/models/gemini) created by [Google DeepMind](https://deepmind.google/technologies/gemini/#introduction). Gemini models are built from the ground up to be multimodal, so you can reason seamlessly across text, images, and code.
57

68
> [!CAUTION]
79
> **The Google AI SDK for Swift is recommended for prototyping only.** If you plan to enable
810
> billing, we strongly recommend that you use a backend SDK to access the Google AI Gemini API. You
911
> risk potentially exposing your API key to malicious actors if you embed your API key directly in
1012
> your Swift app or fetch it remotely at runtime.
1113
12-
The Google AI SDK for Swift enables developers to use Google's state-of-the-art generative AI models
13-
(like Gemini) to build AI-powered features and applications. This SDK supports use cases like:
14-
- Generate text from text-only input
15-
- Generate text from text-and-images input (multimodal)
16-
- Build multi-turn conversations (chat)
17-
1814
For example, with just a few lines of code, you can access Gemini's multimodal capabilities to
1915
generate text from text-and-image input:
2016

21-
```swift
22-
let model = GenerativeModel(name: "gemini-1.5-flash-latest", apiKey: "YOUR_API_KEY")
23-
let cookieImage = UIImage(...)
24-
let prompt = "Do these look store-bought or homemade?"
2517

26-
let response = try await model.generateContent(prompt, cookieImage)
27-
```
28-
29-
## Try out the sample Swift app
30-
31-
This repository contains a sample app demonstrating how the SDK can access and utilize the Gemini
32-
model for various use cases.
18+
## Get started with the Gemini API
19+
1. Go to [Google AI Studio](https://aistudio.google.com/).
20+
2. Login with your Google account.
21+
3. [Create](https://aistudio.google.com/app/apikey) an API key. Note that in Europe the free tier is not available.
22+
4. Check out this repository.\
23+
`git clone https://github.com/google/generative-ai-swift`
24+
5. Open and build the sample app in the `Examples` folder of this repo.
25+
6. Run the app once to ensure the build script generates an empty `GenerativeAI-Info.plist` file
26+
7. Paste your API key into the `API_KEY` property in the `GenerativeAI-Info.plist` file.
27+
8. Run the app
28+
9. For detailed instructions, try the [Swift SDK tutorial](https://ai.google.dev/tutorials/swift_quickstart) on [ai.google.dev](https://ai.google.dev).
3329

34-
To try out the sample app, follow these steps:
30+
## Usage example
3531

36-
1. Check out this repository.\
37-
`git clone https://github.com/google/generative-ai-swift`
32+
Add [`generative-ai-swift`](https://github.com/google/generative-ai-swift) to your Xcode project
33+
using Swift Package Manager.
3834

39-
1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs.
35+
Import the `GoogleGenerativeAI` module
4036

41-
1. Open and build the sample app in the `Examples` folder of this repo.
37+
```swift
38+
import GoogleGenerativeAI
39+
```
4240

43-
1. Run the app once to ensure the build script generates an empty `GenerativeAI-Info.plist` file
41+
Initialize the model
4442

45-
1. Paste your API key into the `API_KEY` property in the `GenerativeAI-Info.plist` file.
43+
```swift
44+
let model = GenerativeModel(name: "gemini-1.5-flash-latest", apiKey: "YOUR_API_KEY")
45+
```
4646

47-
1. Run the app.
47+
Run a prompt
4848

49-
## Use the SDK in your app
49+
```swift
50+
let cookieImage = UIImage(...)
51+
let prompt = "Do these look store-bought or homemade?"
5052

51-
Add [`generative-ai-swift`](https://github.com/google/generative-ai-swift) to your Xcode project
52-
using Swift Package Manager.
53+
let response = try await model.generateContent(prompt, cookieImage)
54+
```
5355

5456
For detailed instructions, you can find a
5557
[quickstart](https://ai.google.dev/tutorials/swift_quickstart) for the Google AI SDK for Swift in the
@@ -76,14 +78,12 @@ line:
7678

7779
## Documentation
7880

79-
Find complete documentation for the Google AI SDKs and the Gemini model in the Google
80-
documentation: https://ai.google.dev/docs
81+
See the [Gemini API Cookbook](https://github.com/google-gemini/gemini-api-cookbook/) or [ai.google.dev](https://ai.google.dev) for complete documentation.
8182

8283
## Contributing
8384

8485
See [Contributing](https://github.com/google/generative-ai-swift/blob/main/docs/CONTRIBUTING.md)
85-
for more information on
86-
contributing to the Google AI SDK for Swift.
86+
for more information on contributing to the Google AI SDK for Swift.
8787

8888

8989
## Developers who use the PaLM SDK for Swift (Deprecated)
@@ -107,3 +107,7 @@ of `generative-ai-swift`.
107107

108108
To see the PaLM documentation and code, go to the
109109
[`palm` branch](https://github.com/google/generative-ai-swift/tree/palm).
110+
111+
## License
112+
113+
The contents of this repository are licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0).

0 commit comments

Comments
 (0)