Skip to content

Commit

Permalink
Merge pull request #16 from ronaldmannak/main
Browse files Browse the repository at this point in the history
Add support for new text-embedding-3-small and text-embedding-3-large embedding models
  • Loading branch information
btfranklin authored Mar 8, 2024
2 parents f0ebfa1 + edcefce commit 61812ff
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
19 changes: 12 additions & 7 deletions Sources/CleverBird/chat/ChatModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@ public enum ChatModel: Codable {

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

try container.encode(modelString)
}
}

extension ChatModel: CustomStringConvertible {
public var description: String {
switch self {
case .gpt35Turbo:
modelString = "gpt-3.5-turbo"
return "gpt-3.5-turbo"
case .gpt4:
modelString = "gpt-4"
case .specific(let specificString):
modelString = specificString
return "gpt-4"
case .specific(let string):
return string
}

try container.encode(modelString)

}
}
2 changes: 1 addition & 1 deletion Sources/CleverBird/embeddings/EmbeddedDocumentStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class EmbeddedDocumentStore {
private var similarityMetric: SimilarityMetric

public init(connection: OpenAIAPIConnection,
model: EmbeddingModel = .textEmbeddingAda002,
model: EmbeddingModel = .textEmbedding3Small,
user: String? = nil,
similarityMetric: SimilarityMetric = .cosine) {
self.connection = connection
Expand Down
26 changes: 20 additions & 6 deletions Sources/CleverBird/embeddings/EmbeddingModel.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Created by B.T. Franklin on 7/25/23

public enum EmbeddingModel: Codable {
case textEmbedding3Small
case textEmbedding3Large
case textEmbeddingAda002
case specific(String)

Expand All @@ -9,6 +11,10 @@ public enum EmbeddingModel: Codable {
let modelString = try container.decode(String.self)

switch modelString {
case "text-embedding-3-small":
self = .textEmbedding3Small
case "text-embedding-3-large":
self = .textEmbedding3Large
case "text-embedding-ada-002":
self = .textEmbeddingAda002
default:
Expand All @@ -18,15 +24,23 @@ public enum EmbeddingModel: Codable {

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

try container.encode(modelString)
}
}

extension EmbeddingModel: CustomStringConvertible {
public var description: String {
switch self {
case .textEmbedding3Small:
return "text-embedding-3-small"
case .textEmbedding3Large:
return "text-embedding-3-large"
case .textEmbeddingAda002:
modelString = "text-embedding-ada-002"
case .specific(let specificString):
modelString = specificString
return "text-embedding-ada-002"
case .specific(let string):
return string
}

try container.encode(modelString)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
public struct EmbeddingRequestParameters: Encodable {
public let model: EmbeddingModel
public let input: [String]
public let dimensions: Int?
public let user: String?

public init(model: EmbeddingModel,
input: [String],
dimensions: Int? = nil,
user: String? = nil) {
self.model = model
self.input = input
self.dimensions = dimensions
self.user = user
}
}

0 comments on commit 61812ff

Please sign in to comment.