Spaces:
Sleeping
Sleeping
File size: 2,669 Bytes
69ea1a3 711cab1 69ea1a3 ae24f5c 711cab1 ae24f5c 69ea1a3 ae24f5c 69ea1a3 ae24f5c 69ea1a3 ae24f5c | 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 | """
默认内容模块 - 存储预加载的 GDL 规范和 System Prompt
"""
import os
# 默认 GDL 规范文件路径
DEFAULT_GDL_FILE = "牌型压制类游戏通用语法.txt"
# 默认 System Prompt 文件路径
DEFAULT_PROMPT_FILE = "prompt.txt"
# 默认示例 GDL 文档路径
DEFAULT_EXAMPLE_GDL_FILE = "ChainBomb_GDL.txt"
def load_default_gdl():
"""
加载默认的 GDL 规范内容
Returns:
str: GDL 规范文本,如果文件不存在则返回空字符串
"""
try:
gdl_path = os.path.join(os.path.dirname(__file__), DEFAULT_GDL_FILE)
if os.path.exists(gdl_path):
with open(gdl_path, "r", encoding="utf-8") as f:
return f.read()
except Exception as e:
print(f"⚠️ 加载默认 GDL 文件失败:{e}")
return ""
def load_default_prompt():
"""
加载默认的 System Prompt 内容
Returns:
str: System Prompt 文本,如果文件不存在则返回空字符串
"""
try:
prompt_path = os.path.join(os.path.dirname(__file__), DEFAULT_PROMPT_FILE)
if os.path.exists(prompt_path):
with open(prompt_path, "r", encoding="utf-8") as f:
return f.read()
except Exception as e:
print(f"⚠️ 加载默认 Prompt 文件失败:{e}")
return ""
def load_default_example_gdl():
"""
加载默认的示例 GDL 文档内容
Returns:
str: 示例 GDL 文本,如果文件不存在则返回空字符串
"""
try:
example_path = os.path.join(os.path.dirname(__file__), DEFAULT_EXAMPLE_GDL_FILE)
if os.path.exists(example_path):
with open(example_path, "r", encoding="utf-8") as f:
return f.read()
except Exception as e:
print(f"⚠️ 加载默认示例 GDL 文件失败:{e}")
return ""
# 在模块加载时预加载内容(提高性能)
DEFAULT_GDL_CONTENT = load_default_gdl()
DEFAULT_PROMPT_CONTENT = load_default_prompt()
DEFAULT_EXAMPLE_GDL_CONTENT = load_default_example_gdl()
def get_default_gdl():
"""
获取默认的 GDL 规范内容(使用预加载的内容)
Returns:
str: GDL 规范文本
"""
return DEFAULT_GDL_CONTENT
def get_default_prompt():
"""
获取默认的 System Prompt 内容(使用预加载的内容)
Returns:
str: System Prompt 文本
"""
return DEFAULT_PROMPT_CONTENT
def get_default_example_gdl():
"""
获取默认的示例 GDL 文档内容(使用预加载的内容)
Returns:
str: 示例 GDL 文本
"""
return DEFAULT_EXAMPLE_GDL_CONTENT
|