mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-08 00:47:36 +08:00
feat: 支持wings接口调用
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -14,19 +15,41 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
|
"github.com/httprunner/httprunner/v5/internal/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WingsService implements ILLMService interface using external Wings API
|
// WingsService implements ILLMService interface using external Wings API
|
||||||
type WingsService struct {
|
type WingsService struct {
|
||||||
apiURL string
|
apiURL string
|
||||||
bizId string
|
bizId string
|
||||||
|
isExternal bool
|
||||||
|
accessKey string
|
||||||
|
secretKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWingsService creates a new Wings service instance
|
// NewWingsService creates a new Wings service instance
|
||||||
func NewWingsService() ILLMService {
|
func NewWingsService() ILLMService {
|
||||||
|
// Check for environment variables for external API access
|
||||||
|
accessKey := ""
|
||||||
|
secretKey := ""
|
||||||
|
isExternal := false
|
||||||
|
apiURL := "https://vedem-algorithm.bytedance.net/algorithm/StepActionDecision"
|
||||||
|
|
||||||
|
// 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"
|
||||||
|
}
|
||||||
|
|
||||||
return &WingsService{
|
return &WingsService{
|
||||||
apiURL: "https://vedem-algorithm.bytedance.net/algorithm/StepActionDecision",
|
apiURL: apiURL,
|
||||||
bizId: "489fdae44de048e0922a32834ea668af",
|
bizId: "489fdae44de048e0922a32834ea668af",
|
||||||
|
isExternal: isExternal,
|
||||||
|
accessKey: accessKey,
|
||||||
|
secretKey: secretKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,6 +407,16 @@ func (w *WingsService) callWingsAPI(ctx context.Context, request WingsActionRequ
|
|||||||
httpReq.Header.Set("Content-Type", "application/json")
|
httpReq.Header.Set("Content-Type", "application/json")
|
||||||
httpReq.Header.Set("Accept", "application/json")
|
httpReq.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
// Add authentication headers if using external API
|
||||||
|
if w.isExternal {
|
||||||
|
signToken := "UNSIGNED-PAYLOAD"
|
||||||
|
token := builtin.Sign("auth-v2", w.accessKey, w.secretKey, []byte(signToken))
|
||||||
|
|
||||||
|
httpReq.Header.Add("Agw-Auth", token)
|
||||||
|
httpReq.Header.Add("Agw-Auth-Content", signToken)
|
||||||
|
httpReq.Header.Add("Content-Type", "application/json")
|
||||||
|
}
|
||||||
|
|
||||||
// Execute HTTP request
|
// Execute HTTP request
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Timeout: 30 * time.Second,
|
Timeout: 30 * time.Second,
|
||||||
|
|||||||
Reference in New Issue
Block a user