Skip to main content

Swift quickstart

In this quickstart, you will learn how to search for and run a model and pipeline.

Create and export an API Key

Create an API key on the Integrations page on Studio. Once generated,

  1. Add your API key as an environment variable to your system or
  2. Set the API key as an environment variable in Xcode - this approach keeps your API key separate from your code, which can be beneficial for security and portability.
export TEAM_API_KEY="your_api_key_here"

Install the aiXplain SDK

The Swift Package Manager is a tool for managing the distribution of Swift code.

Adding aiXplainKit Package to Your Xcode Project

  1. Open your Xcode project: Open your existing Xcode project or create a new one.

  2. Navigate to the project settings: Click on your project in the Project Navigator to open the project settings.

  3. Add the package dependency:

    • Select the project in the Project Navigator.
    • Click on the Package Dependencies tab.
    • Click the + button to add a new package.
  4. Enter the package repository URL: In the dialog that appears, enter the URL of the aiXplainKit package: https://github.com/aixplain/aiXplainKit

  5. Choose the package options:

  • Select the version rule you want to use (e.g., Up to Next Major Version).
  • Click Next.
  1. Add the package to your target: Select the target you want to add the package to, and click Finish.

After completing these steps, Xcode will fetch the aiXplainKit package and add it to your project. You can now import and use the package in your Swift code.

Models

let provider = ModelProvider()
Task {
let query = ModelQuery(functions: ["text-generation"])
let result = try? await provider.list(query)

result?.forEach {
print($0.id, $0.name)
}
}
Show output

Let's select Groq Llama 3 70B, which has ID 6626a3a8c8f1d089790cf5a2.

let groqLlama3 = try? await ModelProvider().get("6626a3a8c8f1d089790cf5a2")

Run

let response = try await groqLlama3.run("What is the capital of France?")
print(response)
Show output
note

See our guides on How to search the marketplace and How to call an asset for more information.

Pipelines

info

To run a pipeline, you must first create one. (The pipeline below is Private.)
Watch our Design Overview video to learn how to use Design to build your first pipeline (Translation & Speech Synthesis).

Search

Suppose you created a pipeline called German Audio to English Text, and it has ID 6671d0c3d7b83256062929a3.

Let's select the pipeline.

let pipeline = try! await PipelineProvider().get("6671d0c3d7b83256062929a3")

Run

let response = try? await pipeline.run(URL("./audio.mp3"))
// print(response?.rawData)
info

We don't yet have a standard format for Swift pipeline outputs. For now, the best way to see a pipeline output is to run the pipeline and print the response.

note

See our guides on How to search the marketplace and How to call an asset for more information.