Load Jev API key from api_key.txt beside the node
This commit is contained in:
@@ -32,6 +32,9 @@ env/
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# API Keys
|
||||
api_key.txt
|
||||
|
||||
# Model files (too large for git)
|
||||
*.gguf
|
||||
*.safetensors
|
||||
|
||||
@@ -80,10 +80,15 @@ ov1, ov2 = (512, 384) if w >= h else (384, 512)
|
||||
Same inputs, outputs, and script rules as `MultiOutputScript`, plus a `jev` namespace that asks [Jev](https://typesafe.ai) (TypeSafe AI's decision model) typed questions about text.
|
||||
|
||||
Setup:
|
||||
```bash
|
||||
pip install typesafe-sdk
|
||||
export TYPESAFE_API_KEY="your-api-key"
|
||||
```
|
||||
1. Install the SDK in the Python environment that runs ComfyUI:
|
||||
```bash
|
||||
pip install typesafe-sdk
|
||||
```
|
||||
2. Create `api_key.txt` in the actual installation directory of this custom node and add your TypeSafe API key (single line, no quotes):
|
||||
```
|
||||
ComfyUI/custom_nodes/<your-installation-folder>/api_key.txt
|
||||
```
|
||||
The key is read from this file on every run; the `TYPESAFE_API_KEY` environment variable is not used. `api_key.txt` is listed in `.gitignore`; never commit it.
|
||||
|
||||
Extra input:
|
||||
- `max_jev_calls` (INT, default 8): maximum Jev API requests per run. Identical questions within a run are asked only once.
|
||||
|
||||
+12
-1
@@ -14,6 +14,7 @@ import ast
|
||||
import datetime
|
||||
import math
|
||||
import random
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
from .jev_backend import JevBackend, TypeSafeClient
|
||||
@@ -22,6 +23,7 @@ from .jev_backend import JevBackend, TypeSafeClient
|
||||
_DEFAULT_MAX_STEPS = 10000
|
||||
_DEFAULT_MAX_CALL_DEPTH = 32
|
||||
_MAX_RANGE_SIZE = 10000
|
||||
_API_KEY_PATH = Path(__file__).resolve().parent / "api_key.txt"
|
||||
|
||||
_BLOCKED_AST_NODES = (
|
||||
ast.Import,
|
||||
@@ -889,7 +891,16 @@ class MultiOutputScriptJev(MultiOutputScript):
|
||||
):
|
||||
if TypeSafeClient is None:
|
||||
raise RuntimeError("typesafe-sdk is not installed. Run: pip install typesafe-sdk")
|
||||
with TypeSafeClient() as client:
|
||||
if not _API_KEY_PATH.exists():
|
||||
raise EnvironmentError(
|
||||
f"API key file not found: {_API_KEY_PATH}\nPlease create this file with your TypeSafe API key."
|
||||
)
|
||||
api_key = _API_KEY_PATH.read_text(encoding="utf-8").strip()
|
||||
if not api_key:
|
||||
raise EnvironmentError(
|
||||
f'API key is not set in "{_API_KEY_PATH}"\nPlease add your TypeSafe API key to this file.'
|
||||
)
|
||||
with TypeSafeClient(api_key=api_key) as client:
|
||||
return _run_script(
|
||||
code,
|
||||
JevBackend(client, max_jev_calls),
|
||||
|
||||
Reference in New Issue
Block a user