executeFastGPTWorkflow 执行 FastGPT 工作流
(c *gin.Context, workflowRequest *WorkflowRunRequest, agent *model.Agent, channel *model.Channel, modelName string)
| 477 | |
| 478 | // executeFastGPTWorkflow 执行 FastGPT 工作流 |
| 479 | func executeFastGPTWorkflow(c *gin.Context, workflowRequest *WorkflowRunRequest, agent *model.Agent, channel *model.Channel, modelName string) (*custom.WorkflowResponseData, error) { |
| 480 | // 检查 Agent 类型是否为工作流类型 |
| 481 | if agent.AgentType != model.AgentTypeWorkflow { |
| 482 | return nil, fmt.Errorf("Agent 类型不是工作流类型,当前类型: %d", agent.AgentType) |
| 483 | } |
| 484 | |
| 485 | // 获取元数据 |
| 486 | meta := GetByContext(c) |
| 487 | meta.APIType = model.GetApiType(channel.Type) |
| 488 | meta.OriginModelName = modelName |
| 489 | meta.ChannelId = int(channel.ChannelID) |
| 490 | if channel.BaseURL != nil { |
| 491 | meta.BaseURL = *channel.BaseURL |
| 492 | } |
| 493 | meta.APIKey = channel.Key |
| 494 | |
| 495 | // 应用模型映射 |
| 496 | mappedModel, _ := getMappedModelName(modelName, meta.ModelMapping) |
| 497 | meta.ActualModelName = mappedModel |
| 498 | |
| 499 | logger.SysLogf("FastGPT工作流执行 - 模型映射,OriginModel: %s, ActualModel: %s", |
| 500 | meta.OriginModelName, meta.ActualModelName) |
| 501 | |
| 502 | // 创建工作流适配器 |
| 503 | workflowAdaptor := &fastgpt.FastGPTWorkflowAdaptor{} |
| 504 | workflowAdaptor.Init(meta) |
| 505 | |
| 506 | // 设置自定义配置 |
| 507 | user_id := config.GetUserId(c) |
| 508 | conversation, err := GetSessionConversation(c) |
| 509 | if err == nil { |
| 510 | customConfig := &custom.CustomConfig{ |
| 511 | UserId: "angethub_u" + fmt.Sprintf("%d", user_id), |
| 512 | ConversationId: conversation.ChannelConversationID, |
| 513 | ConversationExpirationTime: conversation.ChannelConversationExpirationTime, |
| 514 | AIHubConversationId: conversation.ConversationID, |
| 515 | } |
| 516 | workflowAdaptor.CustomConfig = customConfig |
| 517 | } |
| 518 | |
| 519 | // 转换工作流请求为 FastGPT 工作流请求 |
| 520 | fastgptRequest, err := workflowAdaptor.ConvertWorkflowToWorkflowRequest(workflowRequest.Parameters) |
| 521 | if err != nil { |
| 522 | return nil, fmt.Errorf("转换FastGPT工作流请求失败: %v", err) |
| 523 | } |
| 524 | |
| 525 | // 序列化请求 |
| 526 | requestBody, err := json.Marshal(fastgptRequest) |
| 527 | if err != nil { |
| 528 | return nil, fmt.Errorf("序列化FastGPT工作流请求失败: %v", err) |
| 529 | } |
| 530 | |
| 531 | // 执行请求 |
| 532 | resp, err := workflowAdaptor.DoRequest(c, meta, bytes.NewReader(requestBody)) |
| 533 | if err != nil { |
| 534 | return nil, fmt.Errorf("执行FastGPT工作流请求失败: %v", err) |
| 535 | } |
| 536 |
no test coverage detected