-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
56 lines (39 loc) · 1.54 KB
/
example.py
File metadata and controls
56 lines (39 loc) · 1.54 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
56
import asyncio
import time
import apple_fm_sdk as fm
from fmtools import local_extract
@fm.generable()
class ContextSummary:
key_theme: str
word_count_estimate: int
@local_extract(schema=ContextSummary, debug_timing=False)
async def summarize_context(huge_text: str) -> ContextSummary:
"""Summarize the massive input text and estimate its word count."""
pass
async def main():
print("🧠 Testing Apple Foundation Model Context Window Limits...\n")
base_paragraph = (
"Apple Silicon Neural Engines provide an incredible leap in local machine learning performance. "
* 50
)
# base_paragraph is ~5000 characters.
multipliers = [1, 5, 10, 20, 50] # Testing 5k, 25k, 50k, 100k, 250k characters
for mult in multipliers:
test_text = base_paragraph * mult
char_count = len(test_text)
print(
f"Testing Context Size: {char_count:,} characters (approx {char_count // 4:,} tokens)..."
)
try:
start_time = time.perf_counter()
result = await summarize_context(test_text)
elapsed = time.perf_counter() - start_time
print(f"✅ Success! Processed {char_count:,} chars in {elapsed:.2f} seconds.")
print(f" -> Theme: {result.key_theme[:50]}...")
except Exception as e:
print(f"❌ Failed at {char_count:,} characters.")
print(f" Error: {e}")
break # Stop testing if we hit the limit
print("-" * 50)
if __name__ == "__main__":
asyncio.run(main())