chore: customize llm
This commit is contained in:
@@ -1556,14 +1556,15 @@ def set_language_api(req: LanguageRequest):
|
||||
|
||||
class LLMConfigDTO(BaseModel):
|
||||
base_url: str
|
||||
api_key: str
|
||||
api_key: Optional[str] = ""
|
||||
model_name: str
|
||||
fast_model_name: str
|
||||
mode: str
|
||||
max_concurrent_requests: Optional[int] = 10
|
||||
|
||||
class TestConnectionRequest(BaseModel):
|
||||
base_url: str
|
||||
api_key: str
|
||||
api_key: Optional[str] = ""
|
||||
model_name: str
|
||||
|
||||
@app.get("/api/config/llm")
|
||||
@@ -1574,7 +1575,8 @@ def get_llm_config():
|
||||
"api_key": getattr(CONFIG.llm, "key", ""),
|
||||
"model_name": getattr(CONFIG.llm, "model_name", ""),
|
||||
"fast_model_name": getattr(CONFIG.llm, "fast_model_name", ""),
|
||||
"mode": getattr(CONFIG.llm, "mode", "default")
|
||||
"mode": getattr(CONFIG.llm, "mode", "default"),
|
||||
"max_concurrent_requests": getattr(CONFIG.ai, "max_concurrent_requests", 10)
|
||||
}
|
||||
|
||||
@app.post("/api/config/llm/test")
|
||||
@@ -1619,6 +1621,12 @@ async def save_llm_config(req: LLMConfigDTO):
|
||||
CONFIG.llm.fast_model_name = req.fast_model_name
|
||||
CONFIG.llm.mode = req.mode
|
||||
|
||||
# 更新 ai 配置
|
||||
if req.max_concurrent_requests:
|
||||
if not hasattr(CONFIG, "ai"):
|
||||
CONFIG.ai = OmegaConf.create({})
|
||||
CONFIG.ai.max_concurrent_requests = req.max_concurrent_requests
|
||||
|
||||
# 2. Persist to local_config.yml
|
||||
# 使用 src/utils/config.py 中类似的路径逻辑
|
||||
# 注意:这里我们假设是在项目根目录下运行,或者静态文件路径是相对固定的
|
||||
@@ -1641,6 +1649,12 @@ async def save_llm_config(req: LLMConfigDTO):
|
||||
conf.llm.model_name = req.model_name
|
||||
conf.llm.fast_model_name = req.fast_model_name
|
||||
conf.llm.mode = req.mode
|
||||
|
||||
# Ensure ai section exists and update
|
||||
if req.max_concurrent_requests:
|
||||
if "ai" not in conf:
|
||||
conf.ai = {}
|
||||
conf.ai.max_concurrent_requests = req.max_concurrent_requests
|
||||
|
||||
OmegaConf.save(conf, local_config_path)
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ const config = ref<LLMConfigDTO>({
|
||||
api_key: '',
|
||||
model_name: '',
|
||||
fast_model_name: '',
|
||||
mode: 'default'
|
||||
mode: 'default',
|
||||
max_concurrent_requests: 10
|
||||
})
|
||||
|
||||
const modeOptions = computed(() => [
|
||||
@@ -107,10 +108,6 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
async function handleTestAndSave() {
|
||||
if (!config.value.api_key) {
|
||||
message.warning(t('llm.api_key_required'))
|
||||
return
|
||||
}
|
||||
if (!config.value.base_url) {
|
||||
message.warning(t('llm.base_url_required'))
|
||||
return
|
||||
@@ -185,6 +182,19 @@ onMounted(() => {
|
||||
class="input-field"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label>{{ t('llm.labels.max_concurrent_requests') }}</label>
|
||||
<div class="desc">{{ t('llm.descs.max_concurrent_requests') }}</div>
|
||||
<input
|
||||
v-model.number="config.max_concurrent_requests"
|
||||
type="number"
|
||||
min="1"
|
||||
max="50"
|
||||
:placeholder="t('llm.placeholders.max_concurrent_requests')"
|
||||
class="input-field"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 模型配置 -->
|
||||
|
||||
@@ -61,17 +61,20 @@
|
||||
"base_url": "Base URL",
|
||||
"normal_model": "智能模型 (Normal)",
|
||||
"fast_model": "快速模型 (Fast)",
|
||||
"max_concurrent_requests": "最大并发数",
|
||||
"what_is_api": "什么是 API / 如何获取?"
|
||||
},
|
||||
"descs": {
|
||||
"normal_model": "用于处理复杂逻辑、剧情生成等任务",
|
||||
"fast_model": "用于简单判定、频繁交互等任务"
|
||||
"fast_model": "用于简单判定、频繁交互等任务",
|
||||
"max_concurrent_requests": "同时请求 AI 的线程数。调大可加快速度,但可能触发 API 速率限制 (Rate Limit)。建议值:5-20。"
|
||||
},
|
||||
"placeholders": {
|
||||
"api_key": "在此填入你自己的 API Key (通常以 sk- 开头)",
|
||||
"base_url": "https://api.example.com/v1",
|
||||
"normal_model": "例如: gpt-4, claude-3-opus, qwen-plus",
|
||||
"fast_model": "例如: gpt-3.5-turbo, qwen-flash"
|
||||
"fast_model": "例如: gpt-3.5-turbo, qwen-flash",
|
||||
"max_concurrent_requests": "默认: 10"
|
||||
},
|
||||
"modes": {
|
||||
"default": "均衡 (Default)",
|
||||
|
||||
@@ -123,6 +123,7 @@ export interface LLMConfigDTO {
|
||||
model_name: string;
|
||||
fast_model_name: string;
|
||||
mode: string;
|
||||
max_concurrent_requests?: number;
|
||||
}
|
||||
|
||||
export interface GameStartConfigDTO {
|
||||
|
||||
Reference in New Issue
Block a user