|
6 | 6 | > [!IMPORTANT] |
7 | 7 | > If you are using the PaLM SDK for Swift, please see [Developers who use the PaLM SDK for Swift](#developers-who-use-the-palm-sdk-for-swift) for instructions. |
8 | 8 |
|
| 9 | +The Google AI Swift SDK enables developers to use Google's state-of-the-art generative AI models |
| 10 | +(like Gemini) to build AI-powered features and applications. This SDK supports use cases like: |
| 11 | +- Generate text from text-only input |
| 12 | +- Generate text from text-and-images input (multimodal) |
| 13 | +- Build multi-turn conversations (chat) |
| 14 | + |
| 15 | +For example, with just a few lines of code, you can access Gemini's multimodal capabilities to |
| 16 | +generate text from text-and-image input: |
| 17 | + |
| 18 | +```swift |
| 19 | +let model = GenerativeModel(name: "gemini-pro-vision", apiKey: "YOUR_API_KEY") |
| 20 | +let cookieImage = UIImage(...) |
| 21 | +let prompt = "Do these look store-bought or homemade?" |
| 22 | + |
| 23 | +let response = try await model.generateContent(prompt, cookieImage) |
| 24 | +``` |
| 25 | + |
| 26 | +## Try out the sample Swift app |
| 27 | + |
| 28 | +This repository contains a sample app demonstrating how the SDK can access and utilize the Gemini |
| 29 | +model for various use cases. |
| 30 | + |
| 31 | +To try out the sample app, follow these steps: |
| 32 | + |
| 33 | +1. Check out this repository.\ |
| 34 | +`git clone https://github.com/google/generative-ai-swift` |
| 35 | + |
| 36 | +1. [Obtain an API key](https://makersuite.google.com/app/apikey) to use with the Google AI SDKs. |
| 37 | + |
| 38 | +1. Open and build the sample app in the `Examples` folder of this repo. |
| 39 | + |
| 40 | +1. Run the app once to ensure the build script generates an empty `GenerativeAI-Info.plist` file |
| 41 | + |
| 42 | +1. Paste your API key into the `API_KEY` property in the `GenerativeAI-Info.plist` file. |
| 43 | + |
| 44 | +1. Run the app. |
| 45 | + |
| 46 | +## Logging |
| 47 | + |
| 48 | +To enable additional logging in the Xcode console, including a cURL command and raw stream |
| 49 | +response for each model request, add `-GoogleGenerativeAIDebugLogEnabled` as |
| 50 | +`Arguments Passed On Launch` in the Xcode scheme. |
| 51 | + |
| 52 | +## Command Line Tool |
| 53 | + |
| 54 | +A command line tool is available to experiment with Gemini model requests via Xcode or the command |
| 55 | +line: |
| 56 | + |
| 57 | +1. `open Examples/GenerativeAICLI/Package.swift` |
| 58 | +1. Run in Xcode and examine the console to see the options. |
| 59 | +1. Edit the scheme's `Arguments Passed On Launch` with the desired options. |
| 60 | + |
| 61 | +## Contributing |
| 62 | + |
| 63 | +See [Contributing](https://github.com/google/generative-ai-swift/blob/main/docs/CONTRIBUTING.md) |
| 64 | +for more information on |
| 65 | +contributing to the Google AI Swift SDK. |
| 66 | + |
| 67 | + |
9 | 68 | ## Developers who use the PaLM SDK for Swift |
10 | 69 |
|
11 | | -If you're using the PaLM SDK for Swift, review the information below to continue using the PaLM SDK until you've migrated to the new version that allows you to use Gemini. |
| 70 | +If you're using the PaLM SDK for Swift, review the information below to continue |
| 71 | +using the PaLM SDK until you've migrated to the new version that allows you to use Gemini. |
12 | 72 |
|
13 | | -- To continue using PaLM models, make sure your app depends on version [`0.3.0`](https://github.com/google/generative-ai-swift/releases/tag/0.3.0) _up to_ the next minor version ([`0.4.0`](https://github.com/google/generative-ai-swift/releases/tag/0.4.0)) of `generative-ai-swift`. |
| 73 | +- To continue using PaLM models, make sure your app depends on version |
| 74 | +[`0.3.0`](https://github.com/google/generative-ai-swift/releases/tag/0.3.0) |
| 75 | +_up to_ the next minor version |
| 76 | +([`0.4.0`](https://github.com/google/generative-ai-swift/releases/tag/0.4.0)) |
| 77 | +of `generative-ai-swift`. |
14 | 78 |
|
15 | | -- When you're ready to use Gemini models, migrate your code to the Gemini API and update your app's `generative-ai-swift` dependency to version `0.4.0` or higher. |
| 79 | +- When you're ready to use Gemini models, migrate your code to the Gemini API and update your app's |
| 80 | +`generative-ai-swift` dependency to version `0.4.0` or higher. |
16 | 81 |
|
17 | | -To see the PaLM documentation and code, go to the [`palm` branch](https://github.com/google/generative-ai-swift/tree/palm). |
| 82 | +To see the PaLM documentation and code, go to the |
| 83 | +[`palm` branch](https://github.com/google/generative-ai-swift/tree/palm). |
0 commit comments