diff --git a/relay/adaptor/doubao/main.go b/relay/adaptor/doubao/main.go index dd43d06c53..342b966a9e 100644 --- a/relay/adaptor/doubao/main.go +++ b/relay/adaptor/doubao/main.go @@ -7,9 +7,13 @@ import ( ) func GetRequestURL(meta *meta.Meta) (string, error) { + var context = "" + if meta.Cache { + context = "context/" + } switch meta.Mode { case relaymode.ChatCompletions: - return fmt.Sprintf("%s/api/v3/chat/completions", meta.BaseURL), nil + return fmt.Sprintf("%s/api/v3/%schat/completions", meta.BaseURL, context), nil case relaymode.Embeddings: return fmt.Sprintf("%s/api/v3/embeddings", meta.BaseURL), nil default: diff --git a/relay/controller/text.go b/relay/controller/text.go index 9a47c58bc2..9e6456351a 100644 --- a/relay/controller/text.go +++ b/relay/controller/text.go @@ -31,6 +31,7 @@ func RelayTextHelper(c *gin.Context) *model.ErrorWithStatusCode { return openai.ErrorWrapper(err, "invalid_text_request", http.StatusBadRequest) } meta.IsStream = textRequest.Stream + meta.Cache = len(textRequest.ContextId) > 0 // map model name meta.OriginModelName = textRequest.Model diff --git a/relay/meta/relay_meta.go b/relay/meta/relay_meta.go index bcbe10453a..b33a2f99e4 100644 --- a/relay/meta/relay_meta.go +++ b/relay/meta/relay_meta.go @@ -31,6 +31,7 @@ type Meta struct { RequestURLPath string PromptTokens int // only for DoResponse SystemPrompt string + Cache bool } func GetByContext(c *gin.Context) *Meta { diff --git a/relay/model/general.go b/relay/model/general.go index 288c07ffb5..f8fbe82d0a 100644 --- a/relay/model/general.go +++ b/relay/model/general.go @@ -65,6 +65,8 @@ type GeneralOpenAIRequest struct { // Others Instruction string `json:"instruction,omitempty"` NumCtx int `json:"num_ctx,omitempty"` + // SessionCache or PrefixCache context id + ContextId string `json:"context_id,omitempty"` } func (r GeneralOpenAIRequest) ParseInput() []string {