后端预设列表读取完成
This commit is contained in:
@@ -5,16 +5,64 @@ from ..core.models.chat_history import ChatHistory # 修改导入语句
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# 1. 从本地读取所有的data内容
|
||||
# 从本地读取所有的data内容
|
||||
@router.get("/tool_bar/get_all_role_and_chat")
|
||||
def get_all_role_and_chat_endpoint():
|
||||
# 正确调用函数并返回结果
|
||||
return get_all_role_and_chat()
|
||||
|
||||
# 2. 根据rolename和chatname读取特定聊天记录
|
||||
# 根据rolename和chatname读取特定聊天记录
|
||||
@router.get("/chat_box/get_chat_history")
|
||||
async def get_chat_history_endpoint(role_name: str, chat_name: str):
|
||||
# 实例化工具类
|
||||
reader = ChatHistory.load_from_file(role_name, chat_name)
|
||||
|
||||
return reader.to_chatbox_format()
|
||||
|
||||
|
||||
# 从本地读取所有的预设列表内容
|
||||
@router.get("/presets/list")
|
||||
async def get_presets_list():
|
||||
"""
|
||||
获取所有可用的预设列表
|
||||
返回预设名称列表
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# 预设文件存储目录
|
||||
preset_dir = Path("data/preset")
|
||||
|
||||
# 确保目录存在
|
||||
if not preset_dir.exists():
|
||||
return {"presets": []}
|
||||
|
||||
# 获取所有.json文件
|
||||
preset_files = list(preset_dir.glob("*.json"))
|
||||
|
||||
# 提取文件名(不带扩展名)作为预设名称
|
||||
presets = [file.stem for file in preset_files]
|
||||
|
||||
return {"presets": presets}
|
||||
|
||||
|
||||
# 从本地读取特定预设
|
||||
@router.get("/presets/{preset_name}")
|
||||
async def get_preset_content(preset_name: str):
|
||||
"""
|
||||
获取特定预设的完整内容
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
preset_path = Path("data/preset") / f"{preset_name}.json"
|
||||
|
||||
if not preset_path.exists():
|
||||
raise HTTPException(status_code=404, detail="Preset not found")
|
||||
|
||||
with open(preset_path, 'r', encoding='utf-8') as f:
|
||||
preset_data = json.load(f)
|
||||
|
||||
return preset_data
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ class AIDesignSpec(BaseModel):
|
||||
top_a: float = Field(0.0, description="基于平方概率分布的采样")
|
||||
min_p: float = Field(0.0, description="最小概率阈值")
|
||||
repetition_penalty: float = Field(1.0, description="重复惩罚系数(1.0-1.2)")
|
||||
openai_max_context: int = Field(2048, description="上下文窗口大小(Token上限)")
|
||||
openai_max_tokens: int = Field(250, description="单次回复的最大长度")
|
||||
max_context: int = Field(2048, description="上下文窗口大小(Token上限)")
|
||||
max_tokens: int = Field(250, description="单次回复的最大长度")
|
||||
max_context_unlocked: bool = Field(False, description="是否允许超出限制的上下文")
|
||||
names_behavior: int = Field(0, description="名字处理行为(0=默认,1=始终包含,2=仅角色)")
|
||||
send_if_empty: str = Field("", description="用户发送空消息时自动填充的内容")
|
||||
@@ -30,7 +30,7 @@ class AIDesignSpec(BaseModel):
|
||||
scenario_format: str = Field("{{scenario}}", description="场景描述的格式化字符串")
|
||||
personality_format: str = Field("", description="角色性格的格式化字符串")
|
||||
group_nudge_prompt: str = Field("", description="群组聊天中提示AI仅以特定角色回复的提示词")
|
||||
stream_openai: bool = Field(True, description="是否使用流式输出")
|
||||
stream: bool = Field(True, description="是否使用流式输出")
|
||||
assistant_prefill: str = Field("", description="强制AI回复的开头内容")
|
||||
assistant_impersonation: str = Field("", description="模仿模式下强制AI回复的开头内容")
|
||||
use_sysprompt: bool = Field(True, description="是否强制将提示词注入系统层")
|
||||
|
||||
Reference in New Issue
Block a user