Skip to content

Commit 8545399

Browse files
Adding read me for anthropic
1 parent 2fa2f34 commit 8545399

File tree

4 files changed

+73
-45
lines changed

4 files changed

+73
-45
lines changed

Examples/SwiftOpenAIExample/SwiftOpenAIExample/ApiKeyIntroView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,5 @@ struct ApiKeyIntroView: View {
5454
#Preview {
5555
ApiKeyIntroView()
5656
}
57+
58+

Examples/SwiftOpenAIExample/SwiftOpenAIExample/ChatDemo/ChatDemoView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct ChatDemoView: View {
7575
messages: [.init(
7676
role: .user,
7777
content: content)],
78-
model: .gpt4o)
78+
model: .custom("claude-3-7-sonnet-20250219"))
7979
switch selectedSegment {
8080
case .chatCompletion:
8181
try await chatProvider.startChat(parameters: parameters)

Examples/SwiftOpenAIExample/SwiftOpenAIExample/OptionsListView.swift

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -43,51 +43,51 @@ struct OptionsListView: View {
4343
var body: some View {
4444
List(options, id: \.self, selection: $selection) { option in
4545
Text(option.rawValue)
46-
.sheet(item: $selection) { selection in
47-
VStack {
48-
Text(selection.rawValue)
49-
.font(.largeTitle)
50-
.padding()
51-
switch selection {
52-
case .audio:
53-
AudioDemoView(service: openAIService)
54-
case .chat:
55-
ChatDemoView(service: openAIService)
56-
case .chatPredictedOutput:
57-
ChatPredictedOutputDemoView(service: openAIService)
58-
case .vision:
59-
ChatVisionDemoView(service: openAIService)
60-
case .embeddings:
61-
EmbeddingsDemoView(service: openAIService)
62-
case .fineTuning:
63-
FineTuningJobDemoView(service: openAIService)
64-
case .files:
65-
FilesDemoView(service: openAIService)
66-
case .images:
67-
ImagesDemoView(service: openAIService)
68-
case .localChat:
69-
LocalChatDemoView(service: openAIService)
70-
case .models:
71-
ModelsDemoView(service: openAIService)
72-
case .moderations:
73-
ModerationDemoView(service: openAIService)
74-
case .chatHistoryConversation:
75-
ChatStreamFluidConversationDemoView(service: openAIService)
76-
case .chatFunctionCall:
77-
ChatFunctionCallDemoView(service: openAIService)
78-
case .chatFunctionsCallStream:
79-
ChatFunctionsCalllStreamDemoView(service: openAIService)
80-
case .chatStructuredOutput:
81-
ChatStructuredOutputDemoView(service: openAIService)
82-
case .chatStructuredOutputTool:
83-
ChatStructureOutputToolDemoView(service: openAIService)
84-
case .configureAssistant:
85-
AssistantConfigurationDemoView(service: openAIService)
86-
case .realTimeAPI:
87-
Text("WIP")
88-
}
89-
}
46+
}
47+
.sheet(item: $selection) { selection in
48+
VStack {
49+
Text(selection.rawValue)
50+
.font(.largeTitle)
51+
.padding()
52+
switch selection {
53+
case .audio:
54+
AudioDemoView(service: openAIService)
55+
case .chat:
56+
ChatDemoView(service: openAIService)
57+
case .chatPredictedOutput:
58+
ChatPredictedOutputDemoView(service: openAIService)
59+
case .vision:
60+
ChatVisionDemoView(service: openAIService)
61+
case .embeddings:
62+
EmbeddingsDemoView(service: openAIService)
63+
case .fineTuning:
64+
FineTuningJobDemoView(service: openAIService)
65+
case .files:
66+
FilesDemoView(service: openAIService)
67+
case .images:
68+
ImagesDemoView(service: openAIService)
69+
case .localChat:
70+
LocalChatDemoView(service: openAIService)
71+
case .models:
72+
ModelsDemoView(service: openAIService)
73+
case .moderations:
74+
ModerationDemoView(service: openAIService)
75+
case .chatHistoryConversation:
76+
ChatStreamFluidConversationDemoView(service: openAIService)
77+
case .chatFunctionCall:
78+
ChatFunctionCallDemoView(service: openAIService)
79+
case .chatFunctionsCallStream:
80+
ChatFunctionsCalllStreamDemoView(service: openAIService)
81+
case .chatStructuredOutput:
82+
ChatStructuredOutputDemoView(service: openAIService)
83+
case .chatStructuredOutputTool:
84+
ChatStructureOutputToolDemoView(service: openAIService)
85+
case .configureAssistant:
86+
AssistantConfigurationDemoView(service: openAIService)
87+
case .realTimeAPI:
88+
Text("WIP")
9089
}
90+
}
9191
}
9292
}
9393
}

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ to stay on the bleeding edge.
102102
SwiftOpenAI supports various providers that are OpenAI-compatible, including but not limited to:
103103

104104
- [Azure OpenAI](#azure-openai)
105+
- [Anthropic](#anthropic)
105106
- [Gemini](#gemini)
106107
- [Ollama](#ollama)
107108
- [Groq](#groq)
@@ -3592,6 +3593,31 @@ let vectorStoreFiles = try await service.listVectorStoreFilesInABatch(vectorStor
35923593
35933594
⚠️ We currently support Only Assistants Beta 2. If you need support for Assistants V1, you can access it in the jroch-supported-branch-for-assistants-v1 branch or in the v2.3 release.. [Check OpenAI Documentation for details on migration.](https://platform.openai.com/docs/assistants/migration))
35943595
3596+
## Anthropic
3597+
3598+
Anthropic provides OpenAI compatibility, for more, visit the [documentation](https://docs.anthropic.com/en/api/openai-sdk#getting-started-with-the-openai-sdk)
3599+
3600+
To use Claude models with `SwiftOpenAI` you can.
3601+
3602+
```swift
3603+
let anthropicApiKey = ""
3604+
let openAIService = OpenAIServiceFactory.service(apiKey: anthropicApiKey,
3605+
overrideBaseURL: "https://api.anthropic.com",
3606+
overrideVersion: "v1")
3607+
```
3608+
3609+
Now you can create the completio parameters like this:
3610+
3611+
```swift
3612+
let parameters = ChatCompletionParameters(
3613+
messages: [.init(
3614+
role: .user,
3615+
content: "Are you Claude?")],
3616+
model: .custom("claude-3-7-sonnet-20250219"))
3617+
```
3618+
3619+
For a more complete Anthropic Swift Package, you can use [SwiftAnthropic](https://github.com/jamesrochabrun/SwiftAnthropic)
3620+
35953621
## Azure OpenAI
35963622

35973623
This library provides support for both chat completions and chat stream completions through Azure OpenAI. Currently, `DefaultOpenAIAzureService` supports chat completions, including both streamed and non-streamed options.

0 commit comments

Comments
 (0)