Skip to content

Commit de4da8f

Browse files
committed
Add custom body info to chat model
1 parent 67bfe32 commit de4da8f

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

Tool/Sources/AIModel/ChatModel.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ public struct ChatModel: Codable, Equatable, Identifiable {
9494
self.headers = headers
9595
}
9696
}
97+
98+
public struct CustomBodyInfo: Codable, Equatable {
99+
public var jsonBody: String
100+
101+
public init(jsonBody: String = "") {
102+
self.jsonBody = jsonBody
103+
}
104+
}
97105

98106
@FallbackDecoding<EmptyString>
99107
public var apiKeyName: String
@@ -122,6 +130,8 @@ public struct ChatModel: Codable, Equatable, Identifiable {
122130
public var openAICompatibleInfo: OpenAICompatibleInfo
123131
@FallbackDecoding<EmptyChatModelCustomHeaderInfo>
124132
public var customHeaderInfo: CustomHeaderInfo
133+
@FallbackDecoding<EmptyChatModelCustomBodyInfo>
134+
public var customBodyInfo: CustomBodyInfo
125135

126136
public init(
127137
apiKeyName: String = "",
@@ -136,7 +146,8 @@ public struct ChatModel: Codable, Equatable, Identifiable {
136146
ollamaInfo: OllamaInfo = OllamaInfo(),
137147
googleGenerativeAIInfo: GoogleGenerativeAIInfo = GoogleGenerativeAIInfo(),
138148
openAICompatibleInfo: OpenAICompatibleInfo = OpenAICompatibleInfo(),
139-
customHeaderInfo: CustomHeaderInfo = CustomHeaderInfo()
149+
customHeaderInfo: CustomHeaderInfo = CustomHeaderInfo(),
150+
customBodyInfo: CustomBodyInfo = CustomBodyInfo()
140151
) {
141152
self.apiKeyName = apiKeyName
142153
self.baseURL = baseURL
@@ -151,6 +162,7 @@ public struct ChatModel: Codable, Equatable, Identifiable {
151162
self.googleGenerativeAIInfo = googleGenerativeAIInfo
152163
self.openAICompatibleInfo = openAICompatibleInfo
153164
self.customHeaderInfo = customHeaderInfo
165+
self.customBodyInfo = customBodyInfo
154166
}
155167
}
156168

@@ -217,6 +229,10 @@ public struct EmptyChatModelCustomHeaderInfo: FallbackValueProvider {
217229
public static var defaultValue: ChatModel.Info.CustomHeaderInfo { .init() }
218230
}
219231

232+
public struct EmptyChatModelCustomBodyInfo: FallbackValueProvider {
233+
public static var defaultValue: ChatModel.Info.CustomBodyInfo { .init() }
234+
}
235+
220236
public struct EmptyTrue: FallbackValueProvider {
221237
public static var defaultValue: Bool { true }
222238
}

0 commit comments

Comments
 (0)