Skip to content

Commit 85d10af

Browse files
author
Mickey Knox
committed
extend model feature flags
1 parent 7ddfef9 commit 85d10af

File tree

11 files changed

+212
-189
lines changed

11 files changed

+212
-189
lines changed

app/modules/foundations/LLMFoundation/Sources/AIModel.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import Foundation
55

66
// MARK: - LLMReasoning
77

8-
public struct LLMReasoning: Sendable, Hashable, Codable { }
8+
public struct LLMReasoning: Sendable, Hashable, Codable {
9+
public init() { }
10+
}
911

1012
// MARK: - AIProviderModel
1113

@@ -42,7 +44,10 @@ public struct AIModel: Hashable, Identifiable, Sendable, Codable {
4244
documentationURL: URL? = nil,
4345
reasoning: LLMReasoning? = nil,
4446
createdAt: TimeInterval,
45-
rankForProgramming: Int)
47+
rankForProgramming: Int,
48+
supportsChat: Bool = true,
49+
supportsTools: Bool = true,
50+
supportsCompletion: Bool = false)
4651
{
4752
self.slug = slug
4853
self.name = name
@@ -54,6 +59,13 @@ public struct AIModel: Hashable, Identifiable, Sendable, Codable {
5459
self.reasoning = reasoning
5560
self.createdAt = createdAt
5661
self.rankForProgramming = rankForProgramming
62+
self.supportsChat = supportsChat
63+
// TODO: move to appropriate place
64+
&& AIModel.modelSupportsChat(id: slug)
65+
self.supportsTools = supportsTools
66+
self.supportsCompletion = supportsCompletion
67+
// TODO: move to appropriate place
68+
|| AIModel.modelSupportsCompletion(id: slug)
5769
}
5870

5971
/// A few models for debugging and providing default values.
@@ -122,6 +134,9 @@ public struct AIModel: Hashable, Identifiable, Sendable, Codable {
122134
public let reasoning: LLMReasoning?
123135
public let createdAt: TimeInterval
124136
public let rankForProgramming: Int
137+
public let supportsChat: Bool
138+
public let supportsTools: Bool
139+
public let supportsCompletion: Bool
125140

126141
public var id: String {
127142
slug
@@ -147,11 +162,11 @@ public struct AIModel: Hashable, Identifiable, Sendable, Codable {
147162
}
148163

149164
extension AIModel {
150-
public var supportsCompletion: Bool {
165+
static func modelSupportsCompletion(id: String) -> Bool {
151166
["inception/mercury-coder-small", "mistralai/codestral-latest"].contains(id)
152167
}
153168

154-
public var supportsChat: Bool {
169+
static func modelSupportsChat(id: String) -> Bool {
155170
id != "inception/mercury-coder-small"
156171
}
157172
}

app/modules/serviceInterfaces/LocalServerServiceInterface/Sources/listModelsSchema.generated.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ extension Schema {
6464
public let pricing: ModelPricing?
6565
public let createdAt: Double
6666
public let rankForProgramming: Int
67+
public let supportsChat: Bool
68+
public let supportsTools: Bool
69+
public let supportsReasoning: Bool
70+
public let supportsCompletion: Bool
6771

6872
private enum CodingKeys: String, CodingKey {
6973
case providerId = "providerId"
@@ -77,6 +81,10 @@ extension Schema {
7781
case pricing = "pricing"
7882
case createdAt = "createdAt"
7983
case rankForProgramming = "rankForProgramming"
84+
case supportsChat = "supportsChat"
85+
case supportsTools = "supportsTools"
86+
case supportsReasoning = "supportsReasoning"
87+
case supportsCompletion = "supportsCompletion"
8088
}
8189

8290
public init(
@@ -90,7 +98,11 @@ extension Schema {
9098
outputModalities: [ModelModality],
9199
pricing: ModelPricing? = nil,
92100
createdAt: Double,
93-
rankForProgramming: Int
101+
rankForProgramming: Int,
102+
supportsChat: Bool,
103+
supportsTools: Bool,
104+
supportsReasoning: Bool,
105+
supportsCompletion: Bool
94106
) {
95107
self.providerId = providerId
96108
self.globalId = globalId
@@ -103,6 +115,10 @@ extension Schema {
103115
self.pricing = pricing
104116
self.createdAt = createdAt
105117
self.rankForProgramming = rankForProgramming
118+
self.supportsChat = supportsChat
119+
self.supportsTools = supportsTools
120+
self.supportsReasoning = supportsReasoning
121+
self.supportsCompletion = supportsCompletion
106122
}
107123

108124
public init(from decoder: Decoder) throws {
@@ -118,6 +134,10 @@ extension Schema {
118134
pricing = try container.decodeIfPresent(ModelPricing?.self, forKey: .pricing)
119135
createdAt = try container.decode(Double.self, forKey: .createdAt)
120136
rankForProgramming = try container.decode(Int.self, forKey: .rankForProgramming)
137+
supportsChat = try container.decode(Bool.self, forKey: .supportsChat)
138+
supportsTools = try container.decode(Bool.self, forKey: .supportsTools)
139+
supportsReasoning = try container.decode(Bool.self, forKey: .supportsReasoning)
140+
supportsCompletion = try container.decode(Bool.self, forKey: .supportsCompletion)
121141
}
122142

123143
public func encode(to encoder: Encoder) throws {
@@ -133,6 +153,10 @@ extension Schema {
133153
try container.encodeIfPresent(pricing, forKey: .pricing)
134154
try container.encode(createdAt, forKey: .createdAt)
135155
try container.encode(rankForProgramming, forKey: .rankForProgramming)
156+
try container.encode(supportsChat, forKey: .supportsChat)
157+
try container.encode(supportsTools, forKey: .supportsTools)
158+
try container.encode(supportsReasoning, forKey: .supportsReasoning)
159+
try container.encode(supportsCompletion, forKey: .supportsCompletion)
136160
}
137161
}
138162
public enum ModelModality: String, Codable, Sendable, CaseIterable {

app/modules/services/LLMService/Sources/LLMModelManager.swift

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -329,23 +329,31 @@ final class AIModelsManager: AIModelsManagerProtocol {
329329
name: apiProvider.name,
330330
settings: apiProvider.settings)))
331331
let response: Schema.ListModelsOutput = try await localServer.postRequest(path: "models", data: data)
332-
return response.models.map { AIProviderModel(
333-
providerId: $0.providerId,
334-
provider: provider,
335-
modelInfo: .init(
336-
name: $0.name,
337-
slug: $0.globalId,
338-
contextSize: $0.contextLength,
339-
maxOutputTokens: $0.maxCompletionTokens,
340-
defaultPricing: $0.pricing != nil
341-
? .init(
342-
input: $0.pricing?.prompt ?? 0,
343-
output: $0.pricing?.completion ?? 0,
344-
cacheWrite: $0.pricing?.inputCacheWrite ?? 0,
345-
cachedInput: $0.pricing?.inputCacheRead ?? 0)
346-
: nil,
347-
createdAt: $0.createdAt,
348-
rankForProgramming: $0.rankForProgramming)) }
332+
return response.models.map { model in
333+
let defaultPricing: ModelPricing? = {
334+
guard let pricing = model.pricing else { return nil }
335+
return .init(
336+
input: pricing.prompt,
337+
output: pricing.completion,
338+
cacheWrite: pricing.inputCacheWrite ?? 0,
339+
cachedInput: pricing.inputCacheRead ?? 0)
340+
}()
341+
return AIProviderModel(
342+
providerId: model.providerId,
343+
provider: provider,
344+
modelInfo: .init(
345+
name: model.name,
346+
slug: model.globalId,
347+
contextSize: model.contextLength,
348+
maxOutputTokens: model.maxCompletionTokens,
349+
defaultPricing: defaultPricing,
350+
reasoning: model.supportsReasoning ? LLMReasoning() : nil,
351+
createdAt: model.createdAt,
352+
rankForProgramming: model.rankForProgramming,
353+
supportsChat: model.supportsChat,
354+
supportsTools: model.supportsTools,
355+
supportsCompletion: model.supportsCompletion))
356+
}
349357
}
350358

351359
private func observerChangesToSettings() {

app/modules/services/LLMService/Tests/LLMModelManagerTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,10 @@ private func makeSchemaModel(
10941094
maxCompletionTokens: 8_192,
10951095
inputModalities: [.text],
10961096
outputModalities: [.text],
1097+
supportsChat: true,
1098+
supportsTools: true,
1099+
supportsReasoning: false,
1100+
supportsCompletion: true,
10971101
pricing: pricing ?? Schema.ModelPricing(
10981102
prompt: 1.0,
10991103
completion: 2.0),

local-server/build.sha256

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
48ce67299157389bcd10431b9b1905d0fc47731f189f5993d547ec4706682062
1+
e73e92e58623897e84bfc944cf385d6089ea727d20db1a5ad64c5af486c6653b

local-server/src/server/endpoints/listModels.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export const registerEndpoint = (router: Router, aiProviders: AIProvider[]) => {
7171
: undefined,
7272
createdAt: model.created,
7373
rankForProgramming: model.rankForProgramming,
74+
supportsChat: model.supportsChat,
75+
supportsTools: model.supportsTools,
76+
supportsReasoning: model.supportsReasoning,
77+
supportsCompletion: model.supportsCompletion,
7478
})),
7579
} satisfies ListModelsOutput)
7680
})

0 commit comments

Comments
 (0)