executeAI53Workflow 执行 53AI 工作流
(c *gin.Context, workflowRequest *WorkflowRunRequest, agent *model.Agent, channel *model.Channel, modelName string)
| 562 | |
| 563 | // executeAI53Workflow 执行 53AI 工作流 |
| 564 | func executeAI53Workflow(c *gin.Context, workflowRequest *WorkflowRunRequest, agent *model.Agent, channel *model.Channel, modelName string) (*custom.WorkflowResponseData, error) { |
| 565 | // 检查 Agent 类型是否为工作流类型 |
| 566 | if agent.AgentType != model.AgentTypeWorkflow { |
| 567 | return nil, fmt.Errorf("Agent 类型不是工作流类型,当前类型: %d", agent.AgentType) |
| 568 | } |
| 569 | |
| 570 | // 获取元数据 |
| 571 | meta := GetByContext(c) |
| 572 | meta.APIType = model.GetApiType(channel.Type) |
| 573 | meta.OriginModelName = modelName |
| 574 | meta.ChannelId = int(channel.ChannelID) |
| 575 | if channel.BaseURL != nil { |
| 576 | meta.BaseURL = *channel.BaseURL |
| 577 | } |
| 578 | meta.APIKey = channel.Key |
| 579 | |
| 580 | // 应用模型映射 |
| 581 | mappedModel, _ := getMappedModelName(modelName, meta.ModelMapping) |
| 582 | meta.ActualModelName = mappedModel |
| 583 | |
| 584 | logger.SysLogf("53AI工作流执行 - 模型映射,OriginModel: %s, ActualModel: %s", |
| 585 | meta.OriginModelName, meta.ActualModelName) |
| 586 | |
| 587 | // 创建工作流适配器 |
| 588 | workflowAdaptor := &adaptor53AI.AI53WorkflowAdaptor{} |
| 589 | workflowAdaptor.Init(meta) |
| 590 | |
| 591 | // 设置自定义配置 |
| 592 | user_id := config.GetUserId(c) |
| 593 | conversation, err := GetSessionConversation(c) |
| 594 | if err == nil { |
| 595 | customConfig := &custom.CustomConfig{ |
| 596 | UserId: "angethub_u" + fmt.Sprintf("%d", user_id), |
| 597 | ConversationId: conversation.ChannelConversationID, |
| 598 | ConversationExpirationTime: conversation.ChannelConversationExpirationTime, |
| 599 | AIHubConversationId: conversation.ConversationID, |
| 600 | } |
| 601 | workflowAdaptor.CustomConfig = customConfig |
| 602 | } |
| 603 | |
| 604 | // 转换工作流请求为 53AI 工作流请求 |
| 605 | ai53Request, err := workflowAdaptor.ConvertWorkflowToAI53Request(workflowRequest.Parameters) |
| 606 | if err != nil { |
| 607 | return nil, fmt.Errorf("转换53AI工作流请求失败: %v", err) |
| 608 | } |
| 609 | |
| 610 | // 序列化请求 |
| 611 | requestBody, err := json.Marshal(ai53Request) |
| 612 | if err != nil { |
| 613 | return nil, fmt.Errorf("序列化53AI工作流请求失败: %v", err) |
| 614 | } |
| 615 | |
| 616 | // 执行请求 |
| 617 | resp, err := workflowAdaptor.DoRequest(c, meta, bytes.NewReader(requestBody)) |
| 618 | if err != nil { |
| 619 | return nil, fmt.Errorf("执行53AI工作流请求失败: %v", err) |
| 620 | } |
| 621 |
no test coverage detected