Skip to content

Commit ab0db98

Browse files
authored
Re-scope image validation method for Core ML adapter (#42)
1 parent 929712b commit ab0db98

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

Sources/AnyLanguageModel/Models/CoreMLLanguageModel.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,31 @@
210210

211211
return LanguageModelSession.ResponseStream(stream: stream)
212212
}
213+
214+
// MARK: - Image Validation
215+
216+
private func validateNoImageSegments(in session: LanguageModelSession) throws {
217+
// Check for image segments in instructions
218+
if let instructions = session.instructions {
219+
for segment in instructions.segments {
220+
if case .image = segment {
221+
throw CoreMLLanguageModelError.unsupportedFeature
222+
}
223+
}
224+
}
225+
226+
// Check for image segments in the most recent prompt
227+
for entry in session.transcript.reversed() {
228+
if case .prompt(let p) = entry {
229+
for segment in p.segments {
230+
if case .image = segment {
231+
throw CoreMLLanguageModelError.unsupportedFeature
232+
}
233+
}
234+
break
235+
}
236+
}
237+
}
213238
}
214239

215240
/// Errors that can occur when working with Core ML language models.
@@ -242,31 +267,6 @@
242267
}
243268
}
244269

245-
// MARK: - Image Validation
246-
247-
private func validateNoImageSegments(in session: LanguageModelSession) throws {
248-
// Check for image segments in instructions
249-
if let instructions = session.instructions {
250-
for segment in instructions.segments {
251-
if case .image = segment {
252-
throw CoreMLLanguageModelError.unsupportedFeature
253-
}
254-
}
255-
}
256-
257-
// Check for image segments in the most recent prompt
258-
for entry in session.transcript.reversed() {
259-
if case .prompt(let p) = entry {
260-
for segment in p.segments {
261-
if case .image = segment {
262-
throw CoreMLLanguageModelError.unsupportedFeature
263-
}
264-
}
265-
break
266-
}
267-
}
268-
}
269-
270270
// MARK: -
271271

272272
private func toGenerationConfig(_ options: GenerationOptions) -> GenerationConfig {

0 commit comments

Comments
 (0)