-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_raw_generate_timing.py
More file actions
61 lines (50 loc) · 1.99 KB
/
Copy pathtest_raw_generate_timing.py
File metadata and controls
61 lines (50 loc) · 1.99 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
57
58
59
60
61
"""
test_raw_generate_timing.py
─────────────────────────────
Isolated test: calls Ollama exactly the way _llm.py does (generate with
raw=True), completely outside FastAPI/Streamlit/LangGraph, and times it.
Run with:
python test_raw_generate_timing.py
Compare the printed time against your manual `ollama run granite3.3 "..."`
test (~60s). If this script takes roughly the same time, the problem is
elsewhere (timeout config, concurrent load, etc). If this takes much
longer, the raw=True Python path itself is the culprit.
"""
import time
import ollama
from backend.config import OLLAMA_MODEL, OLLAMA_BASE_URL
PROMPT = (
"Write a JSON object with fields title, genre, synopsis, theme, mood "
"for a movie idea about a young woman who inherits a detective agency. "
"Only output JSON, about 150 words total."
)
print(f"Connecting to Ollama at {OLLAMA_BASE_URL}...")
# NOTE: no client-level timeout set here on purpose, so we can see the TRUE
# time the call takes without being cut off early -- this isolates timing
# from timeout configuration entirely.
client = ollama.Client(host=OLLAMA_BASE_URL)
options = {
"temperature": 0.7,
"top_p": 0.9,
"num_predict": 600,
"num_ctx": 1200, # same value your idea_agent call used when it failed
}
print(f"Sending raw=True generate() call [num_predict={options['num_predict']}, num_ctx={options['num_ctx']}]...")
print("(No timeout set -- this will wait as long as it takes. Watch the clock.)")
t0 = time.time()
response = client.generate(
model=OLLAMA_MODEL,
prompt=PROMPT,
raw=True,
options=options,
keep_alive="10m",
)
elapsed = time.time() - t0
print(f"\n{'=' * 60}")
print(f"DONE in {elapsed:.1f} seconds")
print(f"{'=' * 60}")
print(f"\nResponse text ({len(response.response)} chars):")
print(response.response)
thinking = getattr(response, "thinking", None)
if thinking:
print(f"\n[WARNING] Thinking content present ({len(thinking)} chars) -- not suppressed!")