Spaces:
Running
Running
| """ | |
| Configuration file for the Ling Spaces application. | |
| This file centralizes all the configuration variables, such as API endpoints, | |
| API keys, and system prompts for different functionalities. | |
| """ | |
| import os | |
| from dotenv import load_dotenv | |
| from i18n.model_config import model_descriptions | |
| # Load environment variables from .secrets file | |
| load_dotenv(dotenv_path='.secrets') | |
| # --- API Configuration --- | |
| # API endpoint for OpenAI compatible services | |
| OPEN_AI_ENTRYPOINT = os.getenv("OPEN_AI_ENTRYPOINT") or "https://api.openai.com/v1" | |
| # API key for OpenAI compatible services | |
| OPEN_AI_KEY = os.getenv("OPEN_AI_KEY") | |
| # Brand name of the OpenAI compatible provider | |
| OPEN_AI_PROVIDER = os.getenv("OPEN_AI_PROVIDER") or "OpenAI Compatible API" | |
| # Fallback/warning for API keys | |
| if not OPEN_AI_KEY: | |
| print("⚠️ Warning: OPEN_AI_KEY is not set. Remote models may not function correctly.") | |
| if not OPEN_AI_ENTRYPOINT: | |
| print("⚠️ Warning: OPEN_AI_ENTRYPOINT is not set. Using default: https://api.openai.com/v1") | |
| # --- Model Specifications --- | |
| # Constants for easy referencing of models | |
| LING_MINI_2_0 = "ling-mini-2.0" | |
| LING_1T = "ling-1t" | |
| LING_FLASH_2_0 = "ling-flash-2.0" | |
| RING_1T = "ring-1t" | |
| RING_FLASH_2_0 = "ring-flash-2.0" | |
| RING_MINI_2_0 = "ring-mini-2.0" | |
| CHAT_MODEL_SPECS = { | |
| LING_1T: { | |
| "provider": "openai_compatible", | |
| "model_id": "inclusionai/ling-1t", | |
| "display_name": "🦉 Ling-1T", | |
| "description": model_descriptions["ling-1t-desc"], | |
| "url": "https://huggingface.co/inclusionAI/Ling-1T" | |
| }, | |
| RING_1T: { | |
| "provider": "openai_compatible", | |
| "model_id": "inclusionai/ring-1t", | |
| "display_name": "💍️ Ring-1T", | |
| "description": model_descriptions["ring-1t-desc"], | |
| "url": "https://huggingface.co/inclusionAI/Ring-1T" | |
| }, | |
| LING_FLASH_2_0: { | |
| "provider": "openai_compatible", | |
| "model_id": "inclusionai/ling-flash-2.0", | |
| "display_name": "🦉 Ling-flash-2.0", | |
| "description": model_descriptions["ling-flash-2.0-desc"], | |
| "url": "https://huggingface.co/inclusionAI/Ling-flash-2.0" | |
| }, | |
| RING_FLASH_2_0: { | |
| "provider": "openai_compatible", | |
| "model_id": "inclusionai/ring-flash-2.0", | |
| "display_name": "💍️ Ring-flash-2.0", | |
| "description": model_descriptions["ring-flash-2.0-desc"], | |
| "url": "https://huggingface.co/inclusionAI/Ring-flash-2.0" | |
| }, | |
| LING_MINI_2_0: { | |
| "provider": "openai_compatible", | |
| "model_id": "inclusionai/ling-mini-2.0", | |
| "display_name": "🦉 Ling-mini-2.0", | |
| "description": model_descriptions["ling-mini-2.0-desc"], | |
| "url": "https://huggingface.co/inclusionAI/Ling-mini-2.0" | |
| }, | |
| RING_MINI_2_0: { | |
| "provider": "openai_compatible", | |
| "model_id": "inclusionai/ring-mini-2.0", | |
| "display_name": "💍️ Ring-mini-2.0", | |
| "description": model_descriptions["ring-mini-2.0-desc"], | |
| "url": "https://huggingface.co/inclusionAI/Ring-mini-2.0" | |
| } | |
| } | |
| # --- Code Framework Specifications --- | |
| # Constants for easy referencing of code frameworks | |
| STATIC_PAGE = "static_page" | |
| REACT_TAILWIND = "react_tailwind" | |
| REACT_TAILWIND_CHARTJS = "react_tailwind_chartjs" # Added new constant | |
| REACT_THREE_FIBER = "react_three_fiber" | |
| OLD_SCHOOL_HTML = "old_school_html" | |
| CODE_FRAMEWORK_SPECS = { | |
| STATIC_PAGE: { | |
| "display_name": "静态页面", | |
| "description": "生成一个独立的、响应式的 HTML 文件,包含所有必要的 CSS 和 JavaScript。适合快速原型和简单的网页展示。" | |
| }, | |
| REACT_TAILWIND: { | |
| "display_name": "React + Tailwind", | |
| "description": "使用 React 和 Tailwind CSS 构建的现代单页应用。生成内容将是一个单 HTML 文件(使用 CDN)。" | |
| }, | |
| REACT_TAILWIND_CHARTJS: { # Added new framework spec | |
| "display_name": "React + Tailwind + Chart.js", | |
| "description": "使用 React, Tailwind CSS 和 Chart.js 构建数据可视化单页应用。生成内容将是一个单 HTML 文件(使用 CDN)。" | |
| }, | |
| REACT_THREE_FIBER: { | |
| "display_name": "React 3D (R3F)", | |
| "description": "基于 React Three Fiber 的 3D 场景,配合 Tailwind CSS。适合酷炫的 3D 交互效果。" | |
| }, | |
| OLD_SCHOOL_HTML: { | |
| "display_name": "90s 复古风格", | |
| "description": "90 年代风格的纯 HTML + CSS,无 JavaScript。致敬 Web 1.0 时代,适合怀旧风格。" | |
| } | |
| } | |
| # --- Utility Functions --- | |
| _current_provider_name = OPEN_AI_PROVIDER | |
| def set_current_provider(provider_name: str): | |
| """Sets the current API provider name.""" | |
| global _current_provider_name | |
| _current_provider_name = provider_name | |
| def get_current_provider_name() -> str: | |
| """Returns the current API provider name.""" | |
| return _current_provider_name | |
| def get_model_id(model_constant: str) -> str: | |
| """ | |
| Retrieves the internal model ID for a given model constant. | |
| This is typically what's passed to the underlying API. | |
| """ | |
| return CHAT_MODEL_SPECS.get(model_constant, {}).get("model_id", model_constant) | |
| def get_model_display_name(model_constant: str) -> str: | |
| """ | |
| Retrieves the display name for a given model constant. | |
| This is what's shown in the UI. | |
| """ | |
| return CHAT_MODEL_SPECS.get(model_constant, {}).get("display_name", model_constant) | |