|
""" |
|
constants.py ── central config shared by every module |
|
""" |
|
|
|
import os |
|
from typing import Dict, List, 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") |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
SEARCH_START = "<<<<<<< SEARCH" |
|
DIVIDER = "=======" |
|
REPLACE_END = ">>>>>>> REPLACE" |
|
|
|
|
|
|
|
|
|
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, |
|
} |
|
|
|
|
|
|
|
|
|
AVAILABLE_MODELS: List[Dict[str, str]] = [ |
|
|
|
{"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"}, |
|
|
|
{"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"}, |
|
] |
|
|
|
|
|
|
|
|
|
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."}, |
|
] |
|
|