Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copy to .env and fill in your values — never commit .env
HF_TOKEN=your_huggingface_write_token_here
HF_DEFAULT_MODEL=Qwen/Qwen2.5-72B-Instruct
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ tools/test_batch*.json
# Secrets / credentials
.env
.env.*
!.env.example
*.key
*.pem
credentials*
Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: python prompt_expert_enhance.py web --port $PORT --no-browser
30 changes: 28 additions & 2 deletions prompt_expert_enhance.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
OLLAMA_URL = "http://localhost:11434/api/generate"
BASE_DIR = Path(__file__).resolve().parent

# Cloud deploy: set HF_TOKEN env var to switch to HF Inference API backend.
# All Ollama checks are skipped automatically when this is set.
_HF_TOKEN: str = os.environ.get("HF_TOKEN", "")
_CLOUD_MODE: bool = bool(_HF_TOKEN)
_HF_INFERENCE_URL = "https://api-inference.huggingface.co/v1/chat/completions"
_HF_DEFAULT_MODEL = os.environ.get("HF_DEFAULT_MODEL", "Qwen/Qwen2.5-72B-Instruct")


def _is_frozen() -> bool:
"""True when running inside a PyInstaller-compiled app, not from source."""
Expand Down Expand Up @@ -324,6 +331,8 @@ def is_ollama_installed() -> bool:


def is_ollama_running() -> bool:
if _CLOUD_MODE:
return True
try:
requests.get(f"{OLLAMA_API_BASE}/api/tags", timeout=3)
return True
Expand Down Expand Up @@ -439,7 +448,20 @@ def start_ollama_serve():
print(f" [!] Could not start Ollama: {e}")


_HF_AVAILABLE_MODELS = [
"Qwen/Qwen2.5-72B-Instruct",
"Qwen/Qwen2.5-Coder-32B-Instruct",
"meta-llama/Llama-3.3-70B-Instruct",
"mistralai/Mistral-7B-Instruct-v0.3",
"mistralai/Mixtral-8x7B-Instruct-v0.1",
"google/gemma-3-27b-it",
"microsoft/Phi-4-reasoning",
]


def list_local_models() -> List[Dict[str, str]]:
if _CLOUD_MODE:
return [{"name": m, "size": "cloud", "modified": ""} for m in _HF_AVAILABLE_MODELS]
base = _BACKEND_API_BASE or OLLAMA_API_BASE
if _BACKEND_TYPE == "openai_compatible":
try:
Expand Down Expand Up @@ -554,6 +576,8 @@ def pick_model_interactive(label: str, current: str) -> str:


def ensure_ollama_ready():
if _CLOUD_MODE:
return
if not is_ollama_installed():
if not install_ollama_interactive():
print("\n [!] Ollama is not available. Generation will fail.")
Expand Down Expand Up @@ -1283,8 +1307,9 @@ def query_ollama(
if _BACKEND_TYPE == "openai_compatible":
is_chat = _is_chat_endpoint(ollama_url)
payload = _openai_compatible_payload(model, prompt, temperature, num_predict, ollama_url, stream=False)
headers = {"Authorization": f"Bearer {_HF_TOKEN}"} if _HF_TOKEN else {}
try:
resp = requests.post(ollama_url, json=payload, timeout=timeout)
resp = requests.post(ollama_url, json=payload, headers=headers, timeout=timeout)
resp.raise_for_status()
data = resp.json()
result = _openai_compatible_extract_text(data["choices"][0], is_chat) or "[Empty response]"
Expand Down Expand Up @@ -1353,9 +1378,10 @@ def query_ollama_stream(
if _BACKEND_TYPE == "openai_compatible":
is_chat = _is_chat_endpoint(ollama_url)
payload = _openai_compatible_payload(model, prompt, temperature, num_predict, ollama_url, stream=True)
headers = {"Authorization": f"Bearer {_HF_TOKEN}"} if _HF_TOKEN else {}
full_text = []
try:
with requests.post(ollama_url, json=payload, timeout=timeout, stream=True) as resp:
with requests.post(ollama_url, json=payload, headers=headers, timeout=timeout, stream=True) as resp:
resp.raise_for_status()
for raw_line in resp.iter_lines():
if not raw_line:
Expand Down
12 changes: 12 additions & 0 deletions render.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
- type: web
name: wild-root-prompt
runtime: python
buildCommand: pip install -r requirements.txt
startCommand: python prompt_expert_enhance.py web --port $PORT --no-browser
envVars:
- key: HF_TOKEN
sync: false # set this in Render dashboard — never commit the value
- key: HF_DEFAULT_MODEL
value: Qwen/Qwen2.5-72B-Instruct
healthCheckPath: /api/status
15 changes: 11 additions & 4 deletions web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
load_settings, save_settings, PRE_PROCESSOR_TIMEOUT,
is_ollama_running, ensure_ollama_ready,
set_backend_type, set_backend_api_base,
_CLOUD_MODE, _HF_INFERENCE_URL,
PROMPT_TEMPLATES,
)

Expand Down Expand Up @@ -458,7 +459,9 @@
const r = await fetch('/api/status')
const d = await r.json()
$('ollama-dot').className = 'dot ' + (d.ollama ? 'green' : 'red')
$('ollama-status').textContent = d.ollama ? 'Ollama running — ready' : 'Ollama not running — start it first'
$('ollama-status').textContent = d.ollama
? (d.cloud ? 'HF Inference API — ready' : 'Ollama running — ready')
: 'Ollama not running — start it first'
} catch { $('ollama-dot').className = 'dot red'; $('ollama-status').textContent = 'Server error' }
}

Expand Down Expand Up @@ -918,7 +921,7 @@ def index():

@app.route("/api/status")
def api_status():
return jsonify({"ollama": is_ollama_running()})
return jsonify({"ollama": is_ollama_running(), "cloud": _CLOUD_MODE})


@app.route("/api/models")
Expand Down Expand Up @@ -1096,8 +1099,12 @@ def generate_sse():

def run_web_server(port: int = 7860, open_browser: bool = True):
startup_settings = load_settings()
set_backend_type(startup_settings.get("backend_type", "ollama"))
set_backend_api_base(startup_settings.get("ollama_url", OLLAMA_URL))
if _CLOUD_MODE:
set_backend_type("openai_compatible")
set_backend_api_base(_HF_INFERENCE_URL)
else:
set_backend_type(startup_settings.get("backend_type", "ollama"))
set_backend_api_base(startup_settings.get("ollama_url", OLLAMA_URL))

print(f"\n Wild_Root_Prompt Web UI")
print(f" ─────────────────────────────────────")
Expand Down
Loading