File size: 7,597 Bytes
517f963 af61d39 517f963 5040499 517f963 5040499 517f963 f60a70a af61d39 517f963 84fe941 517f963 5040499 517f963 |
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
"""
constants.py ── central config shared by every module
"""
import os
from typing import Dict, List, Optional
# --------------------------------------------------------------------------- #
# 0 · Minimal env‑checks (HF token is required; others optional) #
# --------------------------------------------------------------------------- #
HF_TOKEN: str | None = os.getenv("HF_TOKEN")
if not HF_TOKEN:
raise RuntimeError("HF_TOKEN env‑var missing – please export it!")
OPENAI_API_KEY: str | None = os.getenv("OPENAI_API_KEY")
GEMINI_API_KEY: str | None = os.getenv("GEMINI_API_KEY")
# --------------------------------------------------------------------------- #
# 1 · Gradio syntax‑highlight whitelist #
# --------------------------------------------------------------------------- #
GRADIO_SUPPORTED_LANGUAGES: List[Optional[str]] = [
"python", "c", "cpp", "markdown", "latex", "json", "html", "css",
"javascript", "jinja2", "typescript", "yaml", "dockerfile", "shell", "r",
"sql", "sql-msSQL", "sql-mySQL", "sql-mariaDB", "sql-sqlite",
"sql-cassandra", "sql-plSQL", "sql-hive", "sql-pgSQL", "sql-gql",
"sql-gpSQL", "sql-sparkSQL", "sql-esper", None,
]
def get_gradio_language(lang: str) -> Optional[str]:
return lang if lang in GRADIO_SUPPORTED_LANGUAGES else None
# --------------------------------------------------------------------------- #
# 2 · Search/replace markers #
# --------------------------------------------------------------------------- #
SEARCH_START = "<<<<<<< SEARCH"
DIVIDER = "======="
REPLACE_END = ">>>>>>> REPLACE"
# --------------------------------------------------------------------------- #
# 3 · System prompts (regular + “with search”) #
# --------------------------------------------------------------------------- #
HTML_SYSTEM_PROMPT = (
"ONLY USE HTML, CSS, JS. Produce **one** fully‑responsive `<html>` file; "
"put all CSS inside a `<style>` tag in `<head>`, all JS inside one "
"`<script>` before `</body>`. No inline styles. Respond solely with a "
"```html``` fenced block – no extra commentary."
)
HTML_SYSTEM_PROMPT_WITH_SEARCH = (
HTML_SYSTEM_PROMPT
+ "\n\nFeel free to integrate insights gleaned from live web‑search."
)
TRANSFORMERS_JS_SYSTEM_PROMPT = (
"Create a browser‑only demo using `@xenova/transformers`. Output **exactly "
"three** fenced blocks, in order: `index.html`, `index.js`, `style.css`. "
"No prose."
)
TRANSFORMERS_JS_SYSTEM_PROMPT_WITH_SEARCH = (
TRANSFORMERS_JS_SYSTEM_PROMPT
+ "\n\nLeverage real‑time search to adopt the latest transformers.js tricks."
)
SVELTE_SYSTEM_PROMPT = (
"Generate the minimum custom files for a SvelteKit (TS) app. Always emit "
"`src/App.svelte` and `src/app.css` blocks – extra components only if needed."
)
SVELTE_SYSTEM_PROMPT_WITH_SEARCH = (
SVELTE_SYSTEM_PROMPT
+ "\n\nUse live search results to stay current with Svelte best‑practices."
)
GENERIC_SYSTEM_PROMPT = (
"You are an expert {language} developer. Deliver clean, runnable "
"{language} code inside one fenced block and nothing else."
)
GENERIC_SYSTEM_PROMPT_WITH_SEARCH = (
GENERIC_SYSTEM_PROMPT
+ "\n\nIncorporate any pertinent findings from web‑search."
)
FollowUpSystemPrompt = f"""
Modify existing code using SEARCH / REPLACE blocks only:
{SEARCH_START}
old lines
{DIVIDER}
new lines
{REPLACE_END}
""".strip()
TransformersJSFollowUpSystemPrompt = (
"You are editing an existing **transformers.js** project (index.html / "
"index.js / style.css). Use the same SEARCH / REPLACE format.\n"
+ FollowUpSystemPrompt
)
SYSTEM_PROMPTS: Dict[str, str] = {
"html": HTML_SYSTEM_PROMPT,
"html_search": HTML_SYSTEM_PROMPT_WITH_SEARCH,
"transformers.js": TRANSFORMERS_JS_SYSTEM_PROMPT,
"transformers.js_search": TRANSFORMERS_JS_SYSTEM_PROMPT_WITH_SEARCH,
"svelte": SVELTE_SYSTEM_PROMPT,
"svelte_search": SVELTE_SYSTEM_PROMPT_WITH_SEARCH,
}
# --------------------------------------------------------------------------- #
# 4 · Model catalogue #
# --------------------------------------------------------------------------- #
AVAILABLE_MODELS: List[Dict[str, str]] = [
# ── the 12 models from the user’s screenshot ───────────────────────────
{"name": "Moonshot Kimi‑K2", "id": "moonshotai/Kimi-K2-Instruct"},
{"name": "DeepSeek V3", "id": "deepseek-ai/DeepSeek-V3-0324"},
{"name": "DeepSeek R1", "id": "deepseek-ai/DeepSeek-R1-0528"},
{"name": "ERNIE‑4.5‑VL", "id": "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT"},
{"name": "MiniMax M1", "id": "MiniMaxAI/MiniMax-M1-80k"},
{"name": "Qwen3‑235B‑A22B", "id": "Qwen/Qwen3-235B-A22B"},
{"name": "SmolLM3‑3B", "id": "HuggingFaceTB/SmolLM3-3B"},
{"name": "GLM‑4.1V‑9B‑Thinking", "id": "THUDM/GLM-4.1V-9B-Thinking"},
{"name": "Qwen3‑235B‑A22B‑Instruct‑2507", "id": "Qwen/Qwen3-235B-A22B-Instruct-2507"},
{"name": "Qwen3‑Coder‑480B‑A35B", "id": "Qwen/Qwen3-Coder-480B-A35B-Instruct"},
{"name": "Qwen3‑32B", "id": "Qwen/Qwen3-32B"},
{"name": "Qwen3‑235B‑A22B‑Thinking", "id": "Qwen/Qwen3-235B-A22B-Thinking-2507"},
# ── optional extra providers (comment‑out if unneeded) ─────────────────
{"name": "OpenAI GPT‑4", "id": "openai/gpt-4", "provider": "openai"},
{"name": "Gemini Pro", "id": "gemini/pro", "provider": "gemini"},
{"name": "Fireworks V1", "id": "fireworks-ai/fireworks-v1", "provider": "fireworks"},
]
# --------------------------------------------------------------------------- #
# 5 · Sidebar quick‑start demos #
# --------------------------------------------------------------------------- #
DEMO_LIST: List[Dict[str, str]] = [
{"title": "Todo App", "description": "Add / delete / complete todo list."},
{"title": "Calculator", "description": "Four‑function calculator."},
{"title": "Chat Interface", "description": "Two‑pane chat layout."},
{"title": "E‑commerce Product", "description": "Responsive product card."},
{"title": "Login Form", "description": "Email + password form."},
{"title": "Dashboard Layout", "description": "Sidebar nav + content grid."},
{"title": "Data Table", "description": "Sortable, filterable table."},
{"title": "Image Gallery", "description": "CSS‑grid lightbox gallery."},
{"title": "UI from Image", "description": "Screenshot → HTML/CSS."},
{"title": "Extract Text from Img", "description": "OCR image for text."},
{"title": "Website Redesign", "description": "Modern redesign of a URL."},
{"title": "Modify HTML", "description": "Apply SEARCH / REPLACE edits."},
{"title": "Transformers.js Demo", "description": "Pure browser AI demo."},
]
|