Skip to content

Commit

Permalink
Add gpt-4o and gpt-4-turbo models (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldmannak committed May 15, 2024
1 parent 09c1477 commit fae63f5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The `complete(using:)` method also includes various optional parameters:
```swift
let completion = chatThread.complete(
using: openAIAPIConnection,
model: .gpt4,
model: .gpt4o,
temperature: 0.7,
maxTokens: 500
)
Expand Down
10 changes: 10 additions & 0 deletions Sources/CleverBird/chat/ChatModel.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
public enum ChatModel: Codable {
case gpt35Turbo
case gpt4
case gpt4Turbo
case gpt4o
case specific(String)

public init(from decoder: Decoder) throws {
Expand All @@ -10,6 +12,10 @@ public enum ChatModel: Codable {
switch modelString {
case _ where modelString.starts(with: "gpt-3.5"):
self = .gpt35Turbo
case _ where modelString.starts(with: "gpt-4o"):
self = .gpt4o
case _ where modelString.starts(with: "gpt-4-turbo"):
self = .gpt4Turbo
case _ where modelString.starts(with: "gpt-4"):
self = .gpt4
default:
Expand All @@ -30,6 +36,10 @@ extension ChatModel: CustomStringConvertible {
switch self {
case .gpt35Turbo:
return "gpt-3.5-turbo"
case .gpt4o:
return "gpt-4o"
case .gpt4Turbo:
return "gpt-4-turbo"
case .gpt4:
return "gpt-4"
case .specific(let string):
Expand Down
4 changes: 2 additions & 2 deletions Sources/CleverBird/chat/ChatThread+complete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

extension ChatThread {
public func complete(using connection: OpenAIAPIConnection,
model: ChatModel = .gpt4,
model: ChatModel = .gpt4o,
temperature: Percentage = 0.7,
topP: Percentage? = nil,
stop: [String]? = nil,
Expand All @@ -24,7 +24,7 @@ extension ChatThread {
}

public func completeIncludeUsage(using connection: OpenAIAPIConnection,
model: ChatModel = .gpt4,
model: ChatModel = .gpt4o,
temperature: Percentage = 0.7,
topP: Percentage? = nil,
stop: [String]? = nil,
Expand Down
4 changes: 3 additions & 1 deletion Sources/CleverBird/chat/ChatThread+tokenCount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ extension ChatThread {
switch model {
case .gpt35Turbo:
tokensPerMessage = 4
case .gpt4:
case .gpt4, .gpt4Turbo:
tokensPerMessage = 3
case .gpt4o:
tokensPerMessage = 3
case .specific(_):
tokensPerMessage = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Foundation
extension StreamableChatThread {

public func complete(using connection: OpenAIAPIConnection,
model: ChatModel = .gpt4,
model: ChatModel = .gpt4o,
temperature: Percentage = 0.7,
topP: Percentage? = nil,
stop: [String]? = nil,
Expand Down

0 comments on commit fae63f5

Please sign in to comment.