AI Agent commited on
Commit Β·
1cda057
1
Parent(s): 91dae80
Update expert mode to use diffusiongemma model and include read_b64 helper
Browse files- agents/nvidia_llm.py +11 -6
agents/nvidia_llm.py
CHANGED
|
@@ -5,6 +5,7 @@ import queue as _queue_module
|
|
| 5 |
import time
|
| 6 |
import requests
|
| 7 |
import keyring
|
|
|
|
| 8 |
from flask import Flask, request, jsonify
|
| 9 |
|
| 10 |
# ββ Logging βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -29,7 +30,7 @@ _QUEUE_MAX_SIZE = int(os.getenv("NVIDIA_QUEUE_MAX", "8"))
|
|
| 29 |
_REQUEST_TIMEOUT_S = int(os.getenv("NVIDIA_LLM_TIMEOUT", "600"))
|
| 30 |
|
| 31 |
# DEFAULT_MODEL = "google/diffusiongemma-26b-a4b-it"
|
| 32 |
-
DEFAULT_MODEL = "
|
| 33 |
|
| 34 |
# ββ Flask app βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 35 |
app = Flask(__name__)
|
|
@@ -47,6 +48,10 @@ _inference_queue: _queue_module.Queue = _queue_module.Queue(maxsize=_QUEUE_MAX_S
|
|
| 47 |
if not NVIDIA_API_KEY:
|
| 48 |
log.warning("NVIDIA_API_KEY is not set. API calls might fail if the token is required.")
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
def _run_inference(data: dict) -> dict:
|
| 51 |
raw_prompt = data.get("prompt", "")
|
| 52 |
if not raw_prompt:
|
|
@@ -64,11 +69,11 @@ def _run_inference(data: dict) -> dict:
|
|
| 64 |
reasoning_effort = None
|
| 65 |
else:
|
| 66 |
model_name = data.get("model", DEFAULT_MODEL)
|
| 67 |
-
max_tokens = int(data.get("max_tokens",
|
| 68 |
-
chat_template_kwargs =
|
| 69 |
-
temperature = float(data.get("temperature",
|
| 70 |
-
top_p = float(data.get("top_p",
|
| 71 |
-
reasoning_effort =
|
| 72 |
|
| 73 |
invoke_url = "https://integrate.api.nvidia.com/v1/chat/completions"
|
| 74 |
headers = {
|
|
|
|
| 5 |
import time
|
| 6 |
import requests
|
| 7 |
import keyring
|
| 8 |
+
import base64
|
| 9 |
from flask import Flask, request, jsonify
|
| 10 |
|
| 11 |
# ββ Logging βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 30 |
_REQUEST_TIMEOUT_S = int(os.getenv("NVIDIA_LLM_TIMEOUT", "600"))
|
| 31 |
|
| 32 |
# DEFAULT_MODEL = "google/diffusiongemma-26b-a4b-it"
|
| 33 |
+
DEFAULT_MODEL = "google/diffusiongemma-26b-a4b-it"
|
| 34 |
|
| 35 |
# ββ Flask app βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 36 |
app = Flask(__name__)
|
|
|
|
| 48 |
if not NVIDIA_API_KEY:
|
| 49 |
log.warning("NVIDIA_API_KEY is not set. API calls might fail if the token is required.")
|
| 50 |
|
| 51 |
+
def read_b64(path):
|
| 52 |
+
with open(path, "rb") as f:
|
| 53 |
+
return base64.b64encode(f.read()).decode()
|
| 54 |
+
|
| 55 |
def _run_inference(data: dict) -> dict:
|
| 56 |
raw_prompt = data.get("prompt", "")
|
| 57 |
if not raw_prompt:
|
|
|
|
| 69 |
reasoning_effort = None
|
| 70 |
else:
|
| 71 |
model_name = data.get("model", DEFAULT_MODEL)
|
| 72 |
+
max_tokens = int(data.get("max_tokens", 4096))
|
| 73 |
+
chat_template_kwargs = {"enable_thinking": True}
|
| 74 |
+
temperature = float(data.get("temperature", 1.00))
|
| 75 |
+
top_p = float(data.get("top_p", 0.95))
|
| 76 |
+
reasoning_effort = None
|
| 77 |
|
| 78 |
invoke_url = "https://integrate.api.nvidia.com/v1/chat/completions"
|
| 79 |
headers = {
|