Skip to content

Commit 2c09198

Browse files
authored
Aligning the README with the Python's one (#180)
1 parent 5478400 commit 2c09198

File tree

1 file changed

+88
-70
lines changed

1 file changed

+88
-70
lines changed

README.md

Lines changed: 88 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,127 @@
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
5-
6-
> [!CAUTION]
7-
> **The Google AI SDK for Swift is recommended for prototyping only.** If you plan to enable
8-
> billing, we strongly recommend that you use a backend SDK to access the Google AI Gemini API. You
9-
> risk potentially exposing your API key to malicious actors if you embed your API key directly in
10-
> your Swift app or fetch it remotely at runtime.
6+
The Google AI Swift SDK is the easiest way for Swift developers to build with
7+
the Gemini API. The Gemini API gives you access to Gemini
8+
[models](https://ai.google.dev/models/gemini) created by
9+
[Google DeepMind](https://deepmind.google/technologies/gemini/#introduction).
10+
Gemini models are built from the ground up to be multimodal, so you can reason
11+
seamlessly across text, images, and code.
12+
13+
> [!CAUTION] **The Google AI SDK for Swift is recommended for prototyping
14+
> only.** If you plan to enable billing, we strongly recommend that you use a
15+
> backend SDK to access the Google AI Gemini API. You risk potentially exposing
16+
> your API key to malicious actors if you embed your API key directly in your
17+
> Swift app or fetch it remotely at runtime.
18+
19+
## Get started with the Gemini API
20+
21+
1. Go to [Google AI Studio](https://aistudio.google.com/).
22+
2. Login with your Google account.
23+
3. [Create an API key](https://aistudio.google.com/app/apikey). Note that in
24+
Europe the free tier is not available.
25+
4. Check out this repository. \
26+
`git clone https://github.com/google/generative-ai-swift`
27+
5. Open and build the sample app in the `Examples` folder of this repo.
28+
6. Run the app once to ensure the build script generates an empty
29+
`GenerativeAI-Info.plist` file
30+
7. Paste your API key into the `API_KEY` property in the
31+
`GenerativeAI-Info.plist` file.
32+
8. Run the app
33+
9. For detailed instructions, try the
34+
[Swift SDK tutorial](https://ai.google.dev/tutorials/swift_quickstart) on
35+
[ai.google.dev](https://ai.google.dev).
36+
37+
## Usage example
38+
39+
1. Add [`generative-ai-swift`](https://github.com/google/generative-ai-swift)
40+
to your Xcode project using Swift Package Manager.
41+
42+
2. Import the `GoogleGenerativeAI` module
1143

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)
44+
```swift
45+
import GoogleGenerativeAI
46+
```
1747

18-
For example, with just a few lines of code, you can access Gemini's multimodal capabilities to
19-
generate text from text-and-image input:
48+
1. Initialize the model
2049

2150
```swift
2251
let model = GenerativeModel(name: "gemini-1.5-flash-latest", apiKey: "YOUR_API_KEY")
52+
```
53+
54+
1. Run a prompt
55+
56+
```swift
2357
let cookieImage = UIImage(...)
2458
let prompt = "Do these look store-bought or homemade?"
2559

2660
let response = try await model.generateContent(prompt, cookieImage)
2761
```
2862

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.
33-
34-
To try out the sample app, follow these steps:
35-
36-
1. Check out this repository.\
37-
`git clone https://github.com/google/generative-ai-swift`
38-
39-
1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs.
40-
41-
1. Open and build the sample app in the `Examples` folder of this repo.
42-
43-
1. Run the app once to ensure the build script generates an empty `GenerativeAI-Info.plist` file
44-
45-
1. Paste your API key into the `API_KEY` property in the `GenerativeAI-Info.plist` file.
46-
47-
1. Run the app.
48-
49-
## Use the SDK in your app
50-
51-
Add [`generative-ai-swift`](https://github.com/google/generative-ai-swift) to your Xcode project
52-
using Swift Package Manager.
53-
5463
For detailed instructions, you can find a
55-
[quickstart](https://ai.google.dev/tutorials/swift_quickstart) for the Google AI SDK for Swift in the
56-
Google documentation.
64+
[quickstart](https://ai.google.dev/tutorials/swift_quickstart) for the Google AI
65+
SDK for Swift in the Google documentation.
5766

58-
This quickstart describes how to add your API key and the Swift package to your app, initialize the
59-
model, and then call the API to access the model. It also describes some additional use cases and
60-
features, like streaming, counting tokens, and controlling responses.
67+
This quickstart describes how to add your API key and the Swift package to your
68+
app, initialize the model, and then call the API to access the model. It also
69+
describes some additional use cases and features, like streaming, counting
70+
tokens, and controlling responses.
6171

6272
## Logging
6373

64-
To enable additional logging in the Xcode console, including a cURL command and raw stream
65-
response for each model request, add `-GoogleGenerativeAIDebugLogEnabled` as
66-
`Arguments Passed On Launch` in the Xcode scheme.
74+
To enable additional logging in the Xcode console, including a cURL command and
75+
raw stream response for each model request, add
76+
`-GoogleGenerativeAIDebugLogEnabled` as `Arguments Passed On Launch` in the
77+
Xcode scheme.
6778

6879
## Command Line Tool
6980

70-
A command line tool is available to experiment with Gemini model requests via Xcode or the command
71-
line:
81+
A command line tool is available to experiment with Gemini model requests via
82+
Xcode or the command line:
7283

73-
1. `open Examples/GenerativeAICLI/Package.swift`
74-
1. Run in Xcode and examine the console to see the options.
75-
1. Edit the scheme's `Arguments Passed On Launch` with the desired options.
84+
1. `open Examples/GenerativeAICLI/Package.swift`
85+
1. Run in Xcode and examine the console to see the options.
86+
1. Edit the scheme's `Arguments Passed On Launch` with the desired options.
7687

7788
## Documentation
7889

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

8294
## Contributing
8395

84-
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.
87-
96+
See
97+
[Contributing](https://github.com/google/generative-ai-swift/blob/main/docs/CONTRIBUTING.md)
98+
for more information on contributing to the Google AI SDK for Swift.
8899

89100
## Developers who use the PaLM SDK for Swift (Deprecated)
90101

91-
> [!IMPORTANT]
92-
> The PaLM API is deprecated for use with Google AI services and tools (but _not_ for Vertex AI).
93-
> Learn more about this deprecation, its timeline, and how to migrate to use Gemini in the
102+
> [!IMPORTANT] The PaLM API is deprecated for use with Google AI services and
103+
> tools (but *not* for Vertex AI). Learn more about this deprecation, its
104+
> timeline, and how to migrate to use Gemini in the
94105
> [PaLM API deprecation guide](http://ai.google.dev/palm_docs/deprecation).
95106
96-
​​If you're using the PaLM SDK for Swift, review the information below to continue using the
97-
**deprecated** PaLM SDK until you've migrated to the new version that allows you to use Gemini.
107+
​​If you're using the PaLM SDK for Swift, review the information below to
108+
continue using the **deprecated** PaLM SDK until you've migrated to the new
109+
version that allows you to use Gemini.
98110

99-
- To continue using PaLM models, make sure your app depends on version
100-
[`0.3.0`](https://github.com/google/generative-ai-swift/releases/tag/0.3.0)
101-
_up to_ the next minor version
102-
([`0.4.0`](https://github.com/google/generative-ai-swift/releases/tag/0.4.0))
103-
of `generative-ai-swift`.
111+
- To continue using PaLM models, make sure your app depends on version
112+
[`0.3.0`](https://github.com/google/generative-ai-swift/releases/tag/0.3.0)
113+
*up to* the next minor version
114+
([`0.4.0`](https://github.com/google/generative-ai-swift/releases/tag/0.4.0))
115+
of `generative-ai-swift`.
104116

105-
- When you're ready to use Gemini models, migrate your code to the Gemini API and update your app's
106-
`generative-ai-swift` dependency to version `0.4.0` or higher.
117+
- When you're ready to use Gemini models, migrate your code to the Gemini API
118+
and update your app's `generative-ai-swift` dependency to version `0.4.0` or
119+
higher.
107120

108121
To see the PaLM documentation and code, go to the
109122
[`palm` branch](https://github.com/google/generative-ai-swift/tree/palm).
123+
124+
## License
125+
126+
The contents of this repository are licensed under the
127+
[Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0).

0 commit comments

Comments
 (0)