llama-stack-client-swift brings the inference and agents APIs of Llama Stack to iOS.
- Inference & Agents: Leverage remote Llama Stack distributions for inference, code execution, and safety.
- Custom Tool Calling: Provide Swift tools that Llama agents can understand and use.
-
Xcode > File > Add Package Dependencies...
-
Add this repo URL at the top right:
https://github.com/meta-llama/llama-stack-client-swift
-
Select and add
llama-stack-client-swift
to your app target -
On the first build: Enable & Trust the OpenAPIGenerator extension when prompted
-
import LlamaStackClient
and test out a call:
import LlamaStackClient
let inference = RemoteInference(url: URL(string: "http://127.0.0.1:5000")!)
for await chunk in try await inference.chatCompletion(
request:
Components.Schemas.ChatCompletionRequest(
messages: [
.UserMessage(Components.Schemas.UserMessage(
content: .case1("Hello Llama!"),
role: .user)
)
], model_id: "Meta-Llama3.1-8B-Instruct",
stream: true)
) {
switch (chunk.event.delta) {
case .case1(let s):
print(s)
case .ToolCallDelta(_):
break
}
}
Llama Stack types are generated from the OpenAPI spec in the main repo. That spec is synced to this repo via a git submodule and script. We'll typically take care of this and you shouldn't need to run this.
git submodule update --init --recursive
scripts/generate_swift_types.sh