52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from typing import Any, Dict, Optional
|
|
|
|
|
|
def pp(obj: Any, max_len: int = 800) -> str:
|
|
"""
|
|
Pretty-print JSON-like objects in tests with length guard.
|
|
"""
|
|
try:
|
|
s = json.dumps(obj, ensure_ascii=False, indent=2)
|
|
except Exception:
|
|
s = str(obj)
|
|
if len(s) > max_len:
|
|
return s[:max_len] + "...<truncated>"
|
|
return s
|
|
|
|
|
|
def base_ctx(vendor: str = "openai") -> Dict[str, Any]:
|
|
"""
|
|
Base context used by edge-case tests (mirrors previous _base_ctx).
|
|
"""
|
|
return {
|
|
"model": "gpt-x",
|
|
"vendor_format": vendor,
|
|
"params": {"temperature": 0.1},
|
|
"chat": {"last_user": "hi"},
|
|
"OUT": {},
|
|
}
|
|
|
|
|
|
def ctx(vendor: str = "openai", incoming: Optional[Dict[str, Any]] = None, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
"""
|
|
General context used by macros/vars tests (mirrors previous _ctx).
|
|
"""
|
|
return {
|
|
"model": "gpt-x",
|
|
"vendor_format": vendor,
|
|
"params": params or {"temperature": 0.25},
|
|
"chat": {"last_user": "Привет"},
|
|
"OUT": {},
|
|
"incoming": incoming
|
|
or {
|
|
"method": "POST",
|
|
"url": "http://localhost/test",
|
|
"path": "/test",
|
|
"query": "",
|
|
"headers": {"x": "X-HEADER"},
|
|
"json": {},
|
|
},
|
|
} |