|
210 | 210 |
|
211 | 211 | return LanguageModelSession.ResponseStream(stream: stream) |
212 | 212 | } |
| 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 | + } |
213 | 238 | } |
214 | 239 |
|
215 | 240 | /// Errors that can occur when working with Core ML language models. |
|
242 | 267 | } |
243 | 268 | } |
244 | 269 |
|
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 | | - |
270 | 270 | // MARK: - |
271 | 271 |
|
272 | 272 | private func toGenerationConfig(_ options: GenerationOptions) -> GenerationConfig { |
|
0 commit comments