Skip to content

Commit b38b0a3

Browse files
committed
Formatting
1 parent 37492aa commit b38b0a3

File tree

1 file changed

+68
-50
lines changed

1 file changed

+68
-50
lines changed

README.md

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,55 @@
33
[![](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)
44
[![](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)
55

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.
7-
8-
> [!CAUTION]
9-
> **The Google AI SDK for Swift is recommended for prototyping only.** If you plan to enable
10-
> billing, we strongly recommend that you use a backend SDK to access the Google AI Gemini API. You
11-
> risk potentially exposing your API key to malicious actors if you embed your API key directly in
12-
> 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.
1318
1419
## Get started with the Gemini API
1520

16-
1. Go to [Google AI Studio](https://aistudio.google.com/).
17-
2. Login with your Google account.
18-
3. [Create](https://aistudio.google.com/app/apikey) an API key. Note that in Europe the free tier is not available.
19-
4. Check out this repository.\
20-
`git clone https://github.com/google/generative-ai-swift`
21-
5. Open and build the sample app in the `Examples` folder of this repo.
22-
6. Run the app once to ensure the build script generates an empty `GenerativeAI-Info.plist` file
23-
7. Paste your API key into the `API_KEY` property in the `GenerativeAI-Info.plist` file.
24-
8. Run the app
25-
9. For detailed instructions, try the [Swift SDK tutorial](https://ai.google.dev/tutorials/swift_quickstart) on [ai.google.dev](https://ai.google.dev).
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).
2636

2737
## Usage example
2838

29-
1. Add [`generative-ai-swift`](https://github.com/google/generative-ai-swift) to your Xcode project
30-
using Swift Package Manager.
39+
1. Add [`generative-ai-swift`](https://github.com/google/generative-ai-swift)
40+
to your Xcode project using Swift Package Manager.
3141

32-
2. Import the `GoogleGenerativeAI` module
42+
2. Import the `GoogleGenerativeAI` module
3343

3444
```swift
3545
import GoogleGenerativeAI
3646
```
3747

38-
3. Initialize the model
48+
1. Initialize the model
3949

4050
```swift
4151
let model = GenerativeModel(name: "gemini-1.5-flash-latest", apiKey: "YOUR_API_KEY")
4252
```
4353

44-
4. Run a prompt
54+
1. Run a prompt
4555

4656
```swift
4757
let cookieImage = UIImage(...)
@@ -51,59 +61,67 @@ let response = try await model.generateContent(prompt, cookieImage)
5161
```
5262

5363
For detailed instructions, you can find a
54-
[quickstart](https://ai.google.dev/tutorials/swift_quickstart) for the Google AI SDK for Swift in the
55-
Google documentation.
64+
[quickstart](https://ai.google.dev/tutorials/swift_quickstart) for the Google AI
65+
SDK for Swift in the Google documentation.
5666

57-
This quickstart describes how to add your API key and the Swift package to your app, initialize the
58-
model, and then call the API to access the model. It also describes some additional use cases and
59-
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.
6071

6172
## Logging
6273

63-
To enable additional logging in the Xcode console, including a cURL command and raw stream
64-
response for each model request, add `-GoogleGenerativeAIDebugLogEnabled` as
65-
`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.
6678

6779
## Command Line Tool
6880

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

72-
1. `open Examples/GenerativeAICLI/Package.swift`
73-
1. Run in Xcode and examine the console to see the options.
74-
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.
7587

7688
## Documentation
7789

78-
See the [Gemini API Cookbook](https://github.com/google-gemini/gemini-api-cookbook/) or [ai.google.dev](https://ai.google.dev) for complete documentation.
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.
7993

8094
## Contributing
8195

82-
See [Contributing](https://github.com/google/generative-ai-swift/blob/main/docs/CONTRIBUTING.md)
96+
See
97+
[Contributing](https://github.com/google/generative-ai-swift/blob/main/docs/CONTRIBUTING.md)
8398
for more information on contributing to the Google AI SDK for Swift.
8499

85100
## Developers who use the PaLM SDK for Swift (Deprecated)
86101

87-
> [!IMPORTANT]
88-
> The PaLM API is deprecated for use with Google AI services and tools (but _not_ for Vertex AI).
89-
> 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
90105
> [PaLM API deprecation guide](http://ai.google.dev/palm_docs/deprecation).
91106
92-
​​If you're using the PaLM SDK for Swift, review the information below to continue using the
93-
**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.
94110

95-
- To continue using PaLM models, make sure your app depends on version
96-
[`0.3.0`](https://github.com/google/generative-ai-swift/releases/tag/0.3.0)
97-
_up to_ the next minor version
98-
([`0.4.0`](https://github.com/google/generative-ai-swift/releases/tag/0.4.0))
99-
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`.
100116

101-
- When you're ready to use Gemini models, migrate your code to the Gemini API and update your app's
102-
`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.
103120

104121
To see the PaLM documentation and code, go to the
105122
[`palm` branch](https://github.com/google/generative-ai-swift/tree/palm).
106123

107124
## License
108125

109-
The contents of this repository are licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
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)