refactor: update LLM configuration to model ID in API and frontend
- Replaced LLMConfig with model_id in TextRelationExtractionRequest and FabriTextRequest interfaces. - Updated related API handlers to retrieve chat models based on model_id. - Adjusted frontend components to pass model_id instead of LLMConfig, enhancing clarity and simplifying the configuration process. These changes streamline the model configuration process across the application, improving maintainability and usability.
This commit is contained in:
@@ -412,7 +412,7 @@ export function testMultimodalFunction(testData: {
|
|||||||
export interface TextRelationExtractionRequest {
|
export interface TextRelationExtractionRequest {
|
||||||
text: string;
|
text: string;
|
||||||
tags: string[];
|
tags: string[];
|
||||||
llm_config: LLMConfig;
|
model_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Node {
|
export interface Node {
|
||||||
@@ -426,13 +426,6 @@ export interface Relation {
|
|||||||
type: string;
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LLMConfig {
|
|
||||||
source: 'local' | 'remote';
|
|
||||||
model_name: string;
|
|
||||||
base_url: string;
|
|
||||||
api_key: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TextRelationExtractionResponse {
|
export interface TextRelationExtractionResponse {
|
||||||
nodes: Node[];
|
nodes: Node[];
|
||||||
relations: Relation[];
|
relations: Relation[];
|
||||||
@@ -454,7 +447,7 @@ export function extractTextRelations(request: TextRelationExtractionRequest): Pr
|
|||||||
|
|
||||||
export interface FabriTextRequest {
|
export interface FabriTextRequest {
|
||||||
tags: string[];
|
tags: string[];
|
||||||
llm_config: LLMConfig;
|
model_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FabriTextResponse {
|
export interface FabriTextResponse {
|
||||||
@@ -476,7 +469,6 @@ export function fabriText(request: FabriTextRequest): Promise<FabriTextResponse>
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface FabriTagRequest {
|
export interface FabriTagRequest {
|
||||||
llm_config: LLMConfig;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FabriTagResponse {
|
export interface FabriTagResponse {
|
||||||
|
|||||||
@@ -150,6 +150,7 @@
|
|||||||
<GraphSettings
|
<GraphSettings
|
||||||
v-if="formData"
|
v-if="formData"
|
||||||
:graph-extract="formData.nodeExtractConfig"
|
:graph-extract="formData.nodeExtractConfig"
|
||||||
|
:model-id="formData.modelConfig.llmModelId"
|
||||||
:all-models="allModels"
|
:all-models="allModels"
|
||||||
@update:graphExtract="handleNodeExtractUpdate"
|
@update:graphExtract="handleNodeExtractUpdate"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -296,8 +296,7 @@
|
|||||||
import { ref, watch, onMounted, computed } from 'vue'
|
import { ref, watch, onMounted, computed } from 'vue'
|
||||||
import { MessagePlugin } from 'tdesign-vue-next'
|
import { MessagePlugin } from 'tdesign-vue-next'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { extractTextRelations, fabriText, fabriTag, type Node, type Relation, type LLMConfig } from '@/api/initialization'
|
import { extractTextRelations, fabriText, fabriTag, type Node, type Relation } from '@/api/initialization'
|
||||||
import { listModels } from '@/api/model'
|
|
||||||
import { getSystemInfo } from '@/api/system'
|
import { getSystemInfo } from '@/api/system'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
@@ -312,6 +311,7 @@ interface GraphExtractConfig {
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
graphExtract: GraphExtractConfig
|
graphExtract: GraphExtractConfig
|
||||||
|
modelId: string
|
||||||
allModels?: any[]
|
allModels?: any[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,14 +333,6 @@ const tagFabring = ref(false)
|
|||||||
const textFabring = ref(false)
|
const textFabring = ref(false)
|
||||||
const extracting = ref(false)
|
const extracting = ref(false)
|
||||||
|
|
||||||
// 模型状态
|
|
||||||
const modelStatus = ref({
|
|
||||||
llm: {
|
|
||||||
available: false,
|
|
||||||
config: null as LLMConfig | null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 系统信息
|
// 系统信息
|
||||||
const systemInfo = ref<any>(null)
|
const systemInfo = ref<any>(null)
|
||||||
|
|
||||||
@@ -438,16 +430,9 @@ const removeRelation = (index: number) => {
|
|||||||
|
|
||||||
// 生成随机标签
|
// 生成随机标签
|
||||||
const handleFabriTag = async () => {
|
const handleFabriTag = async () => {
|
||||||
if (!modelStatus.value.llm.available || !modelStatus.value.llm.config) {
|
|
||||||
MessagePlugin.warning(t('graphSettings.completeModelConfig'))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tagFabring.value = true
|
tagFabring.value = true
|
||||||
try {
|
try {
|
||||||
const response = await fabriTag({
|
const response = await fabriTag({})
|
||||||
llm_config: modelStatus.value.llm.config
|
|
||||||
})
|
|
||||||
localGraphExtract.value.tags = response.tags || []
|
localGraphExtract.value.tags = response.tags || []
|
||||||
handleTagsChange()
|
handleTagsChange()
|
||||||
MessagePlugin.success(t('graphSettings.tagsGenerated'))
|
MessagePlugin.success(t('graphSettings.tagsGenerated'))
|
||||||
@@ -461,7 +446,7 @@ const handleFabriTag = async () => {
|
|||||||
|
|
||||||
// 生成随机文本
|
// 生成随机文本
|
||||||
const handleFabriText = async () => {
|
const handleFabriText = async () => {
|
||||||
if (!modelStatus.value.llm.available || !modelStatus.value.llm.config) {
|
if (!props.modelId) {
|
||||||
MessagePlugin.warning(t('graphSettings.completeModelConfig'))
|
MessagePlugin.warning(t('graphSettings.completeModelConfig'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -470,7 +455,7 @@ const handleFabriText = async () => {
|
|||||||
try {
|
try {
|
||||||
const response = await fabriText({
|
const response = await fabriText({
|
||||||
tags: localGraphExtract.value.tags,
|
tags: localGraphExtract.value.tags,
|
||||||
llm_config: modelStatus.value.llm.config
|
model_id: props.modelId
|
||||||
})
|
})
|
||||||
localGraphExtract.value.text = response.text || ''
|
localGraphExtract.value.text = response.text || ''
|
||||||
handleTextChange()
|
handleTextChange()
|
||||||
@@ -485,7 +470,7 @@ const handleFabriText = async () => {
|
|||||||
|
|
||||||
// 提取实体关系
|
// 提取实体关系
|
||||||
const handleExtract = async () => {
|
const handleExtract = async () => {
|
||||||
if (!modelStatus.value.llm.available || !modelStatus.value.llm.config) {
|
if (!props.modelId) {
|
||||||
MessagePlugin.warning(t('graphSettings.completeModelConfig'))
|
MessagePlugin.warning(t('graphSettings.completeModelConfig'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -500,7 +485,7 @@ const handleExtract = async () => {
|
|||||||
const response = await extractTextRelations({
|
const response = await extractTextRelations({
|
||||||
text: localGraphExtract.value.text,
|
text: localGraphExtract.value.text,
|
||||||
tags: localGraphExtract.value.tags,
|
tags: localGraphExtract.value.tags,
|
||||||
llm_config: modelStatus.value.llm.config
|
model_id: props.modelId
|
||||||
})
|
})
|
||||||
localGraphExtract.value.nodes = response.nodes || []
|
localGraphExtract.value.nodes = response.nodes || []
|
||||||
localGraphExtract.value.relations = response.relations || []
|
localGraphExtract.value.relations = response.relations || []
|
||||||
@@ -543,28 +528,6 @@ const clearExtractExample = () => {
|
|||||||
MessagePlugin.success(t('graphSettings.exampleCleared'))
|
MessagePlugin.success(t('graphSettings.exampleCleared'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载模型状态
|
|
||||||
const loadModelStatus = async () => {
|
|
||||||
try {
|
|
||||||
const models = await listModels()
|
|
||||||
|
|
||||||
// 查找可用的KnowledgeQA模型(对话模型)
|
|
||||||
const llmModels = models.filter((m: any) => m.type === 'KnowledgeQA')
|
|
||||||
if (llmModels.length > 0) {
|
|
||||||
const llmModel = llmModels[0]
|
|
||||||
modelStatus.value.llm.available = true
|
|
||||||
modelStatus.value.llm.config = {
|
|
||||||
source: llmModel.source,
|
|
||||||
model_name: llmModel.name,
|
|
||||||
base_url: llmModel.parameters?.base_url || '',
|
|
||||||
api_key: llmModel.parameters?.api_key || ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Failed to load model status:', error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载系统信息
|
// 加载系统信息
|
||||||
const loadSystemInfo = async () => {
|
const loadSystemInfo = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -586,10 +549,7 @@ const handleOpenGraphGuide = () => {
|
|||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await Promise.all([
|
await loadSystemInfo()
|
||||||
loadModelStatus(),
|
|
||||||
loadSystemInfo()
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1952,16 +1952,9 @@ func (h *InitializationHandler) testMultimodalWithDocReader(
|
|||||||
|
|
||||||
// TextRelationExtractionRequest 文本关系提取请求结构
|
// TextRelationExtractionRequest 文本关系提取请求结构
|
||||||
type TextRelationExtractionRequest struct {
|
type TextRelationExtractionRequest struct {
|
||||||
Text string `json:"text" binding:"required"`
|
Text string `json:"text" binding:"required"`
|
||||||
Tags []string `json:"tags" binding:"required"`
|
Tags []string `json:"tags" binding:"required"`
|
||||||
LLMConfig LLMConfig `json:"llm_config"`
|
ModelID string `json:"model_id" binding:"required"`
|
||||||
}
|
|
||||||
|
|
||||||
type LLMConfig struct {
|
|
||||||
Source string `json:"source"`
|
|
||||||
ModelName string `json:"model_name"`
|
|
||||||
BaseUrl string `json:"base_url"`
|
|
||||||
ApiKey string `json:"api_key"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TextRelationExtractionResponse 文本关系提取响应结构
|
// TextRelationExtractionResponse 文本关系提取响应结构
|
||||||
@@ -2009,8 +2002,16 @@ func (h *InitializationHandler) ExtractTextRelations(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据模型ID获取chat模型
|
||||||
|
chatModel, err := h.modelService.GetChatModel(ctx, req.ModelID)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(ctx, "获取模型失败", err)
|
||||||
|
c.Error(errors.NewBadRequestError("获取模型失败: " + err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 调用模型服务进行文本关系提取
|
// 调用模型服务进行文本关系提取
|
||||||
result, err := h.extractRelationsFromText(ctx, req.Text, req.Tags, req.LLMConfig)
|
result, err := h.extractRelationsFromText(ctx, req.Text, req.Tags, chatModel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(ctx, "文本关系提取失败", err)
|
logger.Error(ctx, "文本关系提取失败", err)
|
||||||
c.Error(errors.NewInternalServerError("文本关系提取失败: " + err.Error()))
|
c.Error(errors.NewInternalServerError("文本关系提取失败: " + err.Error()))
|
||||||
@@ -2028,20 +2029,8 @@ func (h *InitializationHandler) extractRelationsFromText(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
text string,
|
text string,
|
||||||
tags []string,
|
tags []string,
|
||||||
llm LLMConfig,
|
chatModel chat.Chat,
|
||||||
) (*TextRelationExtractionResponse, error) {
|
) (*TextRelationExtractionResponse, error) {
|
||||||
chatModel, err := chat.NewChat(&chat.ChatConfig{
|
|
||||||
ModelID: "initialization",
|
|
||||||
APIKey: llm.ApiKey,
|
|
||||||
BaseURL: llm.BaseUrl,
|
|
||||||
ModelName: llm.ModelName,
|
|
||||||
Source: types.ModelSource(llm.Source),
|
|
||||||
}, h.ollamaService)
|
|
||||||
if err != nil {
|
|
||||||
logger.Error(ctx, "初始化模型服务失败", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
template := &types.PromptTemplateStructured{
|
template := &types.PromptTemplateStructured{
|
||||||
Description: h.config.ExtractManager.ExtractGraph.Description,
|
Description: h.config.ExtractManager.ExtractGraph.Description,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
@@ -2066,8 +2055,8 @@ func (h *InitializationHandler) extractRelationsFromText(
|
|||||||
|
|
||||||
// FabriTextRequest is a request for generating example text
|
// FabriTextRequest is a request for generating example text
|
||||||
type FabriTextRequest struct {
|
type FabriTextRequest struct {
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
LLMConfig LLMConfig `json:"llm_config"`
|
ModelID string `json:"model_id" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FabriTextResponse is a response for generating example text
|
// FabriTextResponse is a response for generating example text
|
||||||
@@ -2097,7 +2086,14 @@ func (h *InitializationHandler) FabriText(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := h.fabriText(ctx, req.Tags, req.LLMConfig)
|
chatModel, err := h.modelService.GetChatModel(ctx, req.ModelID)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(ctx, "获取模型失败", err)
|
||||||
|
c.Error(errors.NewBadRequestError("获取模型失败: " + err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := h.fabriText(ctx, req.Tags, chatModel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(ctx, "failed to generate fabri text", err)
|
logger.Error(ctx, "failed to generate fabri text", err)
|
||||||
c.Error(errors.NewInternalServerError("failed to generate fabri text: " + err.Error()))
|
c.Error(errors.NewInternalServerError("failed to generate fabri text: " + err.Error()))
|
||||||
@@ -2111,19 +2107,7 @@ func (h *InitializationHandler) FabriText(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fabriText generates example text
|
// fabriText generates example text
|
||||||
func (h *InitializationHandler) fabriText(ctx context.Context, tags []string, llm LLMConfig) (string, error) {
|
func (h *InitializationHandler) fabriText(ctx context.Context, tags []string, chatModel chat.Chat) (string, error) {
|
||||||
chatModel, err := chat.NewChat(&chat.ChatConfig{
|
|
||||||
ModelID: "initialization",
|
|
||||||
APIKey: llm.ApiKey,
|
|
||||||
BaseURL: llm.BaseUrl,
|
|
||||||
ModelName: llm.ModelName,
|
|
||||||
Source: types.ModelSource(llm.Source),
|
|
||||||
}, h.ollamaService)
|
|
||||||
if err != nil {
|
|
||||||
logger.Error(ctx, "初始化模型服务失败", err)
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
content := h.config.ExtractManager.FabriText.WithNoTag
|
content := h.config.ExtractManager.FabriText.WithNoTag
|
||||||
if len(tags) > 0 {
|
if len(tags) > 0 {
|
||||||
tagStr, _ := json.Marshal(tags)
|
tagStr, _ := json.Marshal(tags)
|
||||||
@@ -2146,9 +2130,7 @@ func (h *InitializationHandler) fabriText(ctx context.Context, tags []string, ll
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FabriTagRequest is a request for generating tags
|
// FabriTagRequest is a request for generating tags
|
||||||
type FabriTagRequest struct {
|
type FabriTagRequest struct{}
|
||||||
LLMConfig LLMConfig `json:"llm_config"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// FabriTagResponse is a response for generating tags
|
// FabriTagResponse is a response for generating tags
|
||||||
type FabriTagResponse struct {
|
type FabriTagResponse struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user