From 841299d64eae5fd6a5a83cde8e8cfa2ba76bc011 Mon Sep 17 00:00:00 2001 From: SwiftBeta <74316958+SwiftBeta@users.noreply.github.com> Date: Mon, 13 May 2024 22:19:51 +0200 Subject: [PATCH] Add new GPT4o model (#43) --- Demo/Demo/ChatCompletions/ChatCompletionsViewModel.swift | 2 +- README.md | 2 +- .../SwiftOpenAI/OpenAI/DataModels/OpenAIModelType.swift | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Demo/Demo/ChatCompletions/ChatCompletionsViewModel.swift b/Demo/Demo/ChatCompletions/ChatCompletionsViewModel.swift index 853636f..d14f900 100644 --- a/Demo/Demo/ChatCompletions/ChatCompletionsViewModel.swift +++ b/Demo/Demo/ChatCompletions/ChatCompletionsViewModel.swift @@ -23,7 +23,7 @@ final class ChatCompletionsViewModel { maxTokens: 2000) if isStream { do { - for try await newMessage in try await openAI.createChatCompletionsStream(model: .gpt4(.base), + for try await newMessage in try await openAI.createChatCompletionsStream(model: .gpt4o(.base), messages: messages, optionalParameters: optionalParameters) { onReceiveStream(newMessage: newMessage) diff --git a/README.md b/README.md index 7be6e2b..0db8c4e 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,7 @@ let optionalParameters = ChatCompletionsOptionalParameters( do { // Create a chat completion stream using the OpenAI API. let stream = try await openAI.createChatCompletionsStream( - model: .gpt4(.base), // Specify the model, here GPT-4 base model. + model: .gpt4o(.base), // Specify the model, here GPT-4 base model. messages: messages, // Provide the conversation messages. optionalParameters: optionalParameters // Include the optional parameters. ) diff --git a/Sources/SwiftOpenAI/OpenAI/DataModels/OpenAIModelType.swift b/Sources/SwiftOpenAI/OpenAI/DataModels/OpenAIModelType.swift index f3c0514..201c97e 100644 --- a/Sources/SwiftOpenAI/OpenAI/DataModels/OpenAIModelType.swift +++ b/Sources/SwiftOpenAI/OpenAI/DataModels/OpenAIModelType.swift @@ -1,12 +1,15 @@ import Foundation public enum OpenAIModelType { + case gpt4o(GPT4o) case gpt4(GPT4) case gpt3_5(GPT3_5) case embedding(EmbeddingModel) var name: String { switch self { + case .gpt4o(let gpt4oModel): + return gpt4oModel.rawValue case .gpt4(let gpt4Model): return gpt4Model.rawValue case .gpt3_5(let gpt3_5Model): @@ -28,6 +31,11 @@ public enum OpenAIImageModelType { } } +public enum GPT4o: String { + case base = "gpt-4o" + case gpt_4o_2024_05_13 = "gpt-4o-2024-05-13" +} + public enum GPT4: String { case base = "gpt-4-turbo" case gpt_4_turbo_2024_04_09 = "gpt-4-turbo-2024-04-09"