-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathColorFix.swift
More file actions
55 lines (48 loc) · 1.72 KB
/
Copy pathColorFix.swift
File metadata and controls
55 lines (48 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// ColorFix.swift
// Foundation-Models-Playgrounds
//
// Created by IVAN CAMPOS on 6/14/25.
//
import FoundationModels
import Playgrounds
@Generable(description: "Original shade plus its CVD‑safe replacement.")
struct ColorFix {
@Guide(description: "e.g. \"#007AFF\"")
var originalHex: String
@Guide(description: "CVD‑adjusted value")
var fixedHex: String
@Guide(description: "Approximated delta‑E or qualitative similarity note.")
var similarityNote: String
}
/// Structured LLM output.
@Generable(description: "Revised palette that remains distinguishable for Protanopia, Deuteranopia, and Tritanopia.")
struct PaletteFixResult {
@Guide(description: "Semantic name → adjusted color info.")
var revisedPalette: [ColorFix]
@Guide(description: "Problems found with original colors (contrast issues, indistinguishable pairs, etc.).")
var detectedIssues: [String]
@Guide(description: "Tips for designers (≤ 3) on maintaining brand identity while inclusive.")
var guidance: [String]
}
#Playground {
let originalPalette = """
{
"Primary": "#007AFF",
"Secondary": "#34C759",
"Accent": "#FF375F",
"Background":"#F2F2F7",
"Text": "#1C1C1E"
}
"""
let instruction = """
You are a Color‑Blind Palette Fixer. Evaluate the JSON palette for Protanopia, Deuteranopia,
and Tritanopia via standard simulation matrices. Supply CVD‑safe replacements only when needed,
preserving perceptual similarity. Return a `PaletteFixResult`.
"""
let session = LanguageModelSession(instructions: instruction)
let fixed = try await session.respond(
to: Prompt(originalPalette),
generating: PaletteFixResult.self
)
}