ForcePilot/web/src/utils/kb_utils.js

62 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Database, Waypoints, DatabaseZap } from 'lucide-vue-next'
export const getKbTypeLabel = (type) => {
const labels = {
lightrag: 'LightRAG',
milvus: 'CommonRAG',
dify: 'Dify'
}
return labels[type] || type
}
export const getKbTypeIcon = (type) => {
const icons = {
lightrag: Waypoints,
milvus: DatabaseZap,
dify: Database
}
return icons[type] || Database
}
export const getKbTypeColor = (type) => {
const colors = {
lightrag: 'purple',
milvus: 'red',
dify: 'gold'
}
return colors[type] || 'blue'
}
// 解析模型 spec 为 { model_spec, provider, model_name }
// V2 格式: provider_id:model_id冒号分隔
// V1 格式: provider/model_name斜杠分隔model_name 可包含冒号)
export const parseModelSpec = (spec) => {
if (typeof spec !== 'string' || !spec) return null
const slashIndex = spec.indexOf('/')
const colonIndex = spec.indexOf(':')
const index = slashIndex !== -1 ? slashIndex : colonIndex
return {
model_spec: spec,
provider: index !== -1 ? spec.slice(0, index) : '',
model_name: index !== -1 ? spec.slice(index + 1) : ''
}
}
// 从 llm_info 构造显示用的 spec 字符串
export const buildDisplaySpec = (llmInfo) => {
if (llmInfo?.model_spec) return llmInfo.model_spec
const provider = llmInfo?.provider || ''
const modelName = llmInfo?.model_name || ''
return provider && modelName ? `${provider}/${modelName}` : ''
}
// 构造提交给后端的 llm_info避免旧数据写入空 model_spec
export const buildLlmInfoPayload = (llmInfo) => {
const payload = {
provider: llmInfo?.provider || '',
model_name: llmInfo?.model_name || ''
}
if (llmInfo?.model_spec) payload.model_spec = llmInfo.model_spec
return payload
}