|
1 |
| -# Google AI SDK for Swift |
| 1 | +# [Deprecated] Google AI Swift SDK for the Gemini API |
2 | 2 |
|
3 |
| -[](https://swiftpackageindex.com/google-gemini/generative-ai-swift) |
4 |
| -[](https://swiftpackageindex.com/google-gemini/generative-ai-swift) |
| 3 | +With Gemini 2.0, we took the chance to create a unified SDK for mobile developers who want to use Google's GenAI models (Gemini, Veo, Imagen, etc). As part of that process, we took all of the feedback from this SDK and what developers like about other SDKs in the ecosystem to direclty work with the [Firebase SDK](https://firebase.google.com/docs/vertex-ai). We don't plan to add anything to this SDK or making any further changes. We know how disruptive an SDK change can be and don't take this change lightly, but our goal is to create an extremely simple and clear path for developers to build with our models so it felt necessary to make this change. |
5 | 4 |
|
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] |
14 |
| -> **The Google AI SDK for Swift is recommended for prototyping only.** If you |
15 |
| -> plan to enable billing, we strongly recommend that you use a backend SDK to |
16 |
| -> access the Google AI Gemini API. You risk potentially exposing your API key to |
17 |
| -> malicious actors if you embed your API key directly in your Swift app or fetch |
18 |
| -> it remotely at runtime. |
19 |
| -
|
20 |
| -## Get started with the Gemini API |
21 |
| - |
22 |
| -1. Go to [Google AI Studio](https://aistudio.google.com/). |
23 |
| -2. Login with your Google account. |
24 |
| -3. [Create an API key](https://aistudio.google.com/app/apikey). Note that in |
25 |
| - Europe the free tier is not available. |
26 |
| -4. Check out this repository. \ |
27 |
| - `git clone https://github.com/google/generative-ai-swift` |
28 |
| -5. Open and build the sample app in the `Examples` folder of this repo. |
29 |
| -6. Run the app once to ensure the build script generates an empty |
30 |
| - `GenerativeAI-Info.plist` file |
31 |
| -7. Paste your API key into the `API_KEY` property in the |
32 |
| - `GenerativeAI-Info.plist` file. |
33 |
| -8. Run the app |
34 |
| -9. For detailed instructions, try the |
35 |
| - [Swift SDK tutorial](https://ai.google.dev/tutorials/swift_quickstart) on |
36 |
| - [ai.google.dev](https://ai.google.dev). |
37 |
| - |
38 |
| -## Usage example |
39 |
| - |
40 |
| -1. Add [`generative-ai-swift`](https://github.com/google/generative-ai-swift) |
41 |
| - to your Xcode project using Swift Package Manager. |
42 |
| - |
43 |
| -2. Import the `GoogleGenerativeAI` module |
44 |
| - |
45 |
| -```swift |
46 |
| -import GoogleGenerativeAI |
47 |
| -``` |
48 |
| - |
49 |
| -1. Initialize the model |
50 |
| - |
51 |
| -```swift |
52 |
| -let model = GenerativeModel(name: "gemini-1.5-flash-latest", apiKey: "YOUR_API_KEY") |
53 |
| -``` |
54 |
| - |
55 |
| -1. Run a prompt |
56 |
| - |
57 |
| -```swift |
58 |
| -let cookieImage = UIImage(...) |
59 |
| -let prompt = "Do these look store-bought or homemade?" |
60 |
| - |
61 |
| -let response = try await model.generateContent(prompt, cookieImage) |
62 |
| -``` |
63 |
| - |
64 |
| -For detailed instructions, you can find a |
65 |
| -[quickstart](https://ai.google.dev/tutorials/swift_quickstart) for the Google AI |
66 |
| -SDK for Swift in the Google documentation. |
67 |
| - |
68 |
| -This quickstart describes how to add your API key and the Swift package to your |
69 |
| -app, initialize the model, and then call the API to access the model. It also |
70 |
| -describes some additional use cases and features, like streaming, counting |
71 |
| -tokens, and controlling responses. |
72 |
| - |
73 |
| -## Logging |
74 |
| - |
75 |
| -To enable additional logging in the Xcode console, including a cURL command and |
76 |
| -raw stream response for each model request, add |
77 |
| -`-GoogleGenerativeAIDebugLogEnabled` as `Arguments Passed On Launch` in the |
78 |
| -Xcode scheme. |
79 |
| - |
80 |
| -## Command Line Tool |
81 |
| - |
82 |
| -A command line tool is available to experiment with Gemini model requests via |
83 |
| -Xcode or the command line: |
84 |
| - |
85 |
| -1. `open Examples/GenerativeAICLI/Package.swift` |
86 |
| -1. Run in Xcode and examine the console to see the options. |
87 |
| -1. Edit the scheme's `Arguments Passed On Launch` with the desired options. |
88 |
| - |
89 |
| -## Documentation |
90 |
| - |
91 |
| -See the |
92 |
| -[Gemini API Cookbook](https://github.com/google-gemini/gemini-api-cookbook/) or |
93 |
| -[ai.google.dev](https://ai.google.dev) for complete documentation. |
94 |
| - |
95 |
| -## Contributing |
96 |
| - |
97 |
| -See |
98 |
| -[Contributing](https://github.com/google/generative-ai-swift/blob/main/docs/CONTRIBUTING.md) |
99 |
| -for more information on contributing to the Google AI SDK for Swift. |
100 |
| - |
101 |
| -## Developers who use the PaLM SDK for Swift (Decommissioned) |
102 |
| - |
103 |
| -> [!IMPORTANT] |
104 |
| -> The PaLM API is now |
105 |
| -> [decommissioned](https://ai.google.dev/palm_docs/deprecation). This means that |
106 |
| -> users cannot use a PaLM model in a prompt, tune a new PaLM model, or run |
107 |
| -> inference on PaLM-tuned models. |
108 |
| -> |
109 |
| -> Note: This is different from the |
110 |
| -> [Vertex AI PaLM API](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/text), |
111 |
| -> which is scheduled to be decommissioned in October 2024. |
112 |
| -
|
113 |
| -If you're using the PaLM SDK for Swift, migrate your code to the Gemini API |
114 |
| -and update your app's `generative-ai-swift` dependency to version `0.4.0` or |
115 |
| -higher. For more information on migrating from PaLM to Gemini, see the |
116 |
| -[migration guide](https://ai.google.dev/docs/migration_guide). |
117 |
| - |
118 |
| -## License |
119 |
| - |
120 |
| -The contents of this repository are licensed under the |
121 |
| -[Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). |
| 5 | +Thank you for building with Gemini and [let us know](https://discuss.ai.google.dev/c/gemini-api/4) if you need any help! |
0 commit comments