Skip to content

Commit

Permalink
Added "specific" case to Model, allowing for the use of new features …
Browse files Browse the repository at this point in the history
…(such as function calling) that are not yet available on the mainline versions of the GPT models.
  • Loading branch information
btfranklin committed Jun 18, 2023
1 parent 18aef5c commit b7bcf3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Sources/CleverBird/chat/ChatThread+tokenCount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ extension ChatThread {
tokensPerMessage = 4
case .gpt4:
tokensPerMessage = 3
case .specific(_):
tokensPerMessage = 3
}

var numTokens = 0
Expand Down
26 changes: 22 additions & 4 deletions Sources/CleverBird/datatypes/Model.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
public enum Model: String, Codable {
case gpt35Turbo = "gpt-3.5-turbo"
case gpt4 = "gpt-4"
public enum Model: Codable {
case gpt35Turbo
case gpt4
case specific(String)

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
Expand All @@ -12,7 +13,24 @@ public enum Model: String, Codable {
case _ where modelString.starts(with: "gpt-4"):
self = .gpt4
default:
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Cannot initialize Model from invalid String value: \(modelString)")
self = .specific(modelString)
}
}

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
let modelString: String

switch self {
case .gpt35Turbo:
modelString = "gpt-3.5-turbo"
case .gpt4:
modelString = "gpt-4"
case .specific(let specificString):
modelString = specificString
}

try container.encode(modelString)
}

}

0 comments on commit b7bcf3b

Please sign in to comment.