feat: add session/prefix cache for doubao

This commit is contained in:
laoshancun 2025-01-10 16:10:51 +08:00
parent 3915ce9814
commit 111a5faeed
4 changed files with 9 additions and 1 deletions

View File

@ -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:

View File

@ -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

View File

@ -31,6 +31,7 @@ type Meta struct {
RequestURLPath string
PromptTokens int // only for DoResponse
SystemPrompt string
Cache bool
}
func GetByContext(c *gin.Context) *Meta {

View File

@ -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 {