dependencies: [
.package(url: "https://github.com/exyte/OpenAI")
]
To install OpenAI
, simply add the following line to your Podfile:
pod 'ExyteOpenAI'
To integrate OpenAI
into your Xcode project using Carthage, specify it in your Cartfile
github "exyte/OpenAI"
⚠️ OpenAI strongly recommends developers of client-side applications proxy requests through a separate backend service to keep their API key safe. API keys can access and manipulate customer billing, usage, and organizational data, so it's a significant risk to expose them.
let client = OpenAI(apiKey: "YOUR_API_KEY_HERE")
let assistantPayload = CreateAssistantPayload(model: .gpt_4o, name: "My Assistant", instructions: "Be funny")
client.createAssistant(from: assistantPayload) <...>
let threadPayload = CreateThreadPayload(messages: [...], metadata: [...])
client.createThread(from: threadPayload) <...>
let messagePayload = CreateMessagePayload(role: .user, content: "Hello!")
client.createMessage(in: threadId, payload: messagePayload) <...>
client.createRun(in: threadId, payload: CreateRunPayload(assistantId: assistantId)) <...>
client.retrieveRun(id: runId, from: threadId)
let listPayload = ListPayload(after: lastMessageId)
client.listMessages(from: threadId, payload: listPayload) <...>
For more detailed information about OpenAI Assistants API usage, please refer to platform.openai.com and our Examples section.
Creates a model response for the given chat conversation.
createChatCompletion(
from: CreateChatCompletionPayload(
model: model,
messages: [ChatCompletionMessage(role: .user, content: "Hello")]
)
)
ChatCompletion
List and describe the various models available in the API. A list of models and their differences can be found on platform.openai.com.
listModels()
ObjectList<Model>
retrieveModel(with: modelId)
Model
deleteModel(with: modelId)
DeletionStatus
Files are used to upload documents that can be used with features like Assistants.
uploadFile(payload: FilePayload(purpose: filePurpose, fileURL: fileURL))
File
listFiles()
ObjectList<File>
retrieveFile(id: fileId)
File
deleteFile(id: fileId)
DeletionStatus
retrieveFileContent(id: fileId, destinationURL: destinationURL)
URL
Build assistants that can call models and use tools to perform tasks.
createAssistant(from: CreateAssistantPayload(model: model, name: name, ...))
Assistant
listAssistants(payload: ListPayload(limit: limit, ...))
ObjectList<Assistant>
retrieveAssistant(id: assistantId)
Assistant
modifyAssistant(id: assistandId, payload: CreateAssistantPayload(model: updatedModel, name: updatedName, ...))
Assistant
deleteAssistant(id: assistantId)
DeletionStatus
createThread(
from: CreateThreadPayload(
messages: [CreateMessagePayload(role: .user, content: "Hello"), ...],
metadata: ["key1": "value1", ...]
)
)
Thread
retrieveThread(id: threadId)
Thread
modifyThread(id: threadId, payload: ModifyPayload(metadata: ["key1": "value1", ...]))
Thread
deleteThread(id: threadId)
DeletionStatus
createMessage(in: threadId, payload: CreateMessagePayload(role: .user, content: "Hello"))
Message
listMessages(from: threadId, payload: ListPayload(limit: limit))
ObjectList<Message>
retrieveMessage(id: messageId, from: threadId)
Message
modifyMessage(id: messageId, from: threadId, payload: ModifyPayload(metadata: ["key1": "value1", ...]))
Message
createRun(in: threadId, payload: CreateRunPayload(assistantId: assistantId, ...))
Run
createStreamRun(in: threadId, payload: CreateStreamRunPayload(assistantId: assistantId))
StreamEvent
sequencecreateThreadAndRun(
from: CreateThreadAndRunPayload(
assistantId: assistantId,
thread: CreateThreadPayload(
messages: [CreateMessagePayload(role: .user, content: "Hello"), ...],
metadata: ["key1": "value1", ...]
)
)
)
Run
listRuns(from: threadId, payload: ListPayload(limit: limit, ...))
ObjectList<Run>
retrieveRun(id: runId, from: threadId)
Run
modifyRun(id: runId, from: threadId, payload: ModifyPayload(metadata: ["key1": "value1", ...]))
Run
cancelRun(id: runId, from: threadId)
Run
listRunSteps(from: runId, in: threadId, payload: ListPayload(limit: limit, ...))
ObjectList<RunStep>
retrieveRunStep(id: runStepId, from: runId, in: threadId)
RunStep
To try the OpenAIAssistants examples:
https://github.com/exyte/OpenAI
PopupView - Toasts and popups library
Grid - The most powerful Grid container
ScalingHeaderScrollView - A scroll view with a sticky header which shrinks as you scroll
AnimatedTabBar - A tabbar with a number of preset animations
MediaPicker - Customizable media picker
Chat - Chat UI framework with fully customizable message cells, input view, and a built-in media picker
AnimatedGradient - Animated linear gradient
ConcentricOnboarding - Animated onboarding flow
FloatingButton - Floating button menu
ActivityIndicatorView - A number of animated loading indicators
ProgressIndicatorView - A number of animated progress indicators
FlagAndCountryCode - Phone codes and flags for every country
SVGView - SVG parser
LiquidSwipe - Liquid navigation animation