mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-21 04:22:30 +08:00
Merge branch 'master' into session_refactor
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/uixt/option"
|
||||
)
|
||||
|
||||
@@ -24,43 +25,66 @@ func NewLLMService(modelType option.LLMServiceType) (ILLMService, error) {
|
||||
|
||||
// NewLLMServiceWithOptionConfig creates a new LLM service with different models for each component
|
||||
func NewLLMServiceWithOptionConfig(config *option.LLMServiceConfig) (ILLMService, error) {
|
||||
// Get model configs for each component
|
||||
plannerModelConfig, err := GetModelConfig(config.PlannerModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
combinedLLMService := &combinedLLMService{}
|
||||
|
||||
// Planner
|
||||
if config.PlannerModel == option.WINGS_SERVICE {
|
||||
planner, err := NewWingsService()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
combinedLLMService.planner = planner
|
||||
} else {
|
||||
plannerModelConfig, err := GetModelConfig(config.PlannerModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
planner, err := NewPlanner(context.Background(), plannerModelConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
combinedLLMService.planner = planner
|
||||
}
|
||||
|
||||
asserterModelConfig, err := GetModelConfig(config.AsserterModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// Asserter
|
||||
if config.AsserterModel == option.WINGS_SERVICE {
|
||||
asserter, err := NewWingsService()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
combinedLLMService.asserter = asserter
|
||||
} else {
|
||||
asserterModelConfig, err := GetModelConfig(config.AsserterModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
asserter, err := NewAsserter(context.Background(), asserterModelConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
combinedLLMService.asserter = asserter
|
||||
}
|
||||
|
||||
querierModelConfig, err := GetModelConfig(config.QuerierModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// Querier
|
||||
if config.QuerierModel == option.WINGS_SERVICE {
|
||||
querier, err := NewWingsService()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
combinedLLMService.querier = querier
|
||||
} else {
|
||||
querierModelConfig, err := GetModelConfig(config.QuerierModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
querier, err := NewQuerier(context.Background(), querierModelConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
combinedLLMService.querier = querier
|
||||
}
|
||||
|
||||
// Create components with their respective model configs
|
||||
planner, err := NewPlanner(context.Background(), plannerModelConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
asserter, err := NewAsserter(context.Background(), asserterModelConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
querier, err := NewQuerier(context.Background(), querierModelConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &combinedLLMService{
|
||||
planner: planner,
|
||||
asserter: asserter,
|
||||
querier: querier,
|
||||
}, nil
|
||||
return combinedLLMService, nil
|
||||
}
|
||||
|
||||
// combinedLLMService 实现了 ILLMService 接口,组合了规划、断言和查询功能
|
||||
|
||||
@@ -16,41 +16,40 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/code"
|
||||
"github.com/httprunner/httprunner/v5/internal/builtin"
|
||||
)
|
||||
|
||||
// WingsService implements ILLMService interface using external Wings API
|
||||
type WingsService struct {
|
||||
apiURL string
|
||||
bizId string
|
||||
isExternal bool
|
||||
accessKey string
|
||||
secretKey string
|
||||
apiURL string
|
||||
bizId string
|
||||
accessKey string
|
||||
secretKey string
|
||||
}
|
||||
|
||||
// NewWingsService creates a new Wings service instance
|
||||
func NewWingsService() ILLMService {
|
||||
func NewWingsService() (ILLMService, error) {
|
||||
// Check for environment variables for external API access
|
||||
accessKey := ""
|
||||
secretKey := ""
|
||||
isExternal := false
|
||||
apiURL := "https://vedem-algorithm.bytedance.net/algorithm/StepActionDecision"
|
||||
apiURL := os.Getenv("VEDEM_WINGS_API_URL")
|
||||
accessKey := os.Getenv("VEDEM_WINGS_AK")
|
||||
secretKey := os.Getenv("VEDEM_WINGS_SK")
|
||||
bizID := os.Getenv("VEDEM_WINGS_BIZ_ID")
|
||||
|
||||
// If environment variables are set, use external API with authentication
|
||||
if ak, sk := os.Getenv("VEDEM_WINGS_AK"), os.Getenv("VEDEM_WINGS_SK"); ak != "" && sk != "" {
|
||||
accessKey = ak
|
||||
secretKey = sk
|
||||
isExternal = true
|
||||
apiURL = "https://vedem-algorithm.zijieapi.com/algorithm/StepActionDecision"
|
||||
// check required env
|
||||
if apiURL == "" {
|
||||
return nil, errors.Wrap(code.LLMEnvMissedError, "missed env VEDEM_WINGS_API_URL")
|
||||
}
|
||||
if bizID == "" {
|
||||
return nil, errors.Wrap(code.LLMEnvMissedError, "missed env VEDEM_WINGS_BIZ_ID")
|
||||
}
|
||||
|
||||
return &WingsService{
|
||||
apiURL: apiURL,
|
||||
bizId: "489fdae44de048e0922a32834ea668af",
|
||||
isExternal: isExternal,
|
||||
accessKey: accessKey,
|
||||
secretKey: secretKey,
|
||||
}
|
||||
apiURL: apiURL,
|
||||
bizId: bizID,
|
||||
accessKey: accessKey,
|
||||
secretKey: secretKey,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Plan implements the ILLMService.Plan method using Wings API
|
||||
@@ -346,8 +345,8 @@ func (w *WingsService) extractScreenshotFromMessage(message *schema.Message) (st
|
||||
}
|
||||
|
||||
// getDeviceInfoFromContext gets device info from context with fallback
|
||||
func (w *WingsService) getDeviceInfoFromContext(ctx context.Context, screenshot string) WingsDeviceInfo {
|
||||
// Fallback to default device info
|
||||
func (w *WingsService) getDeviceInfoFromContext(_ context.Context, screenshot string) WingsDeviceInfo {
|
||||
// use default device info
|
||||
return WingsDeviceInfo{
|
||||
DeviceID: "default-device",
|
||||
NowImage: screenshot,
|
||||
@@ -393,7 +392,7 @@ func (w *WingsService) callWingsAPI(ctx context.Context, request WingsActionRequ
|
||||
httpReq.Header.Set("Accept", "application/json")
|
||||
|
||||
// Add authentication headers if using external API
|
||||
if w.isExternal {
|
||||
if w.accessKey != "" && w.secretKey != "" {
|
||||
signToken := "UNSIGNED-PAYLOAD"
|
||||
token := builtin.Sign("auth-v2", w.accessKey, w.secretKey, []byte(signToken))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user