Skip to content

Commit

Permalink
fix dashscope max tokens and hunyuan top_p param
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Nov 23, 2023
1 parent 5cfd8a7 commit 7fe63c1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func createChatRequest(props *ChatProps, hook globals.Hook) error {
return dashscope.NewChatInstanceFromConfig().CreateStreamChatRequest(&dashscope.ChatProps{
Model: props.Model,
Message: props.Message,
Token: utils.Multi(props.Infinity || props.Plan, nil, utils.ToPtr(2500)),
Token: utils.Multi(props.Infinity || props.Plan, 2048, props.Token),
Temperature: props.Temperature,
TopP: props.TopP,
TopK: props.TopK,
Expand Down
6 changes: 4 additions & 2 deletions adapter/dashscope/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type ChatProps struct {
Model string
Token *int
Token int
Temperature *float32
TopP *float32
TopK *int
Expand All @@ -26,6 +26,9 @@ func (c *ChatInstance) GetHeader() map[string]string {
}

func (c *ChatInstance) GetChatBody(props *ChatProps) ChatRequest {
if props.Token <= 0 || props.Token > 1500 {
props.Token = 1500
}
return ChatRequest{
Model: strings.TrimSuffix(props.Model, "-net"),
Input: ChatInput{
Expand Down Expand Up @@ -77,7 +80,6 @@ func (c *ChatInstance) CreateStreamChatRequest(props *ChatProps, callback global
return nil
}

fmt.Println(slice)
globals.Debug(fmt.Sprintf("dashscope error: cannot unmarshal data %s", slice))

return nil
Expand Down
2 changes: 1 addition & 1 deletion adapter/dashscope/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ChatInput struct {
type ChatParam struct {
IncrementalOutput bool `json:"incremental_output"`
EnableSearch *bool `json:"enable_search,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
MaxTokens int `json:"max_tokens"`
Temperature *float32 `json:"temperature,omitempty"`
TopP *float32 `json:"top_p,omitempty"`
TopK *int `json:"top_k,omitempty"`
Expand Down
5 changes: 2 additions & 3 deletions adapter/hunyuan/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bufio"
"bytes"
"chat/globals"
"chat/utils"
"context"
"crypto/hmac"
"crypto/sha1"
Expand Down Expand Up @@ -124,8 +123,8 @@ func NewRequest(mod int, messages []globals.Message, temperature *float32, topP
return ChatRequest{
Timestamp: int(time.Now().Unix()),
Expired: int(time.Now().Unix()) + 24*60*60,
Temperature: float64(utils.GetPtrVal(temperature, 0)),
TopP: float64(utils.GetPtrVal(topP, 0.8)),
Temperature: 0,
TopP: 0.8,
Messages: messages,
QueryID: queryID,
Stream: mod,
Expand Down

0 comments on commit 7fe63c1

Please sign in to comment.