mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 12:47:28 +08:00
feat: implement apiToken failover mechanism (#1256)
This commit is contained in:
@@ -3,7 +3,6 @@ package provider
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/alibaba/higress/plugins/wasm-go/pkg/wrapper"
|
||||
"github.com/higress-group/proxy-wasm-go-sdk/proxywasm"
|
||||
)
|
||||
@@ -18,6 +17,13 @@ func decodeChatCompletionRequest(body []byte, request *chatCompletionRequest) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func decodeEmbeddingsRequest(body []byte, request *embeddingsRequest) error {
|
||||
if err := json.Unmarshal(body, request); err != nil {
|
||||
return fmt.Errorf("unable to unmarshal request: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func replaceJsonRequestBody(request interface{}, log wrapper.Log) error {
|
||||
body, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
@@ -31,6 +37,15 @@ func replaceJsonRequestBody(request interface{}, log wrapper.Log) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func replaceHttpJsonRequestBody(body []byte, log wrapper.Log) error {
|
||||
log.Debugf("request body: %s", string(body))
|
||||
err := proxywasm.ReplaceHttpRequestBody(body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to replace the original request body: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertContextMessage(request *chatCompletionRequest, content string) {
|
||||
fileMessage := chatMessage{
|
||||
Role: roleSystem,
|
||||
|
||||
Reference in New Issue
Block a user