Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add session/prefix cache for doubao #2027

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion relay/adaptor/doubao/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions relay/controller/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions relay/meta/relay_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Meta struct {
RequestURLPath string
PromptTokens int // only for DoResponse
SystemPrompt string
Cache bool
}

func GetByContext(c *gin.Context) *Meta {
Expand Down
2 changes: 2 additions & 0 deletions relay/model/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down