Skip to content

Commit

Permalink
fix pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Nov 21, 2023
1 parent 460f87b commit b753511
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions adapter/hunyuan/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,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: utils.Multi[float64](temperature == nil, 0, float64(*temperature)),
TopP: utils.Multi[float64](topP == nil, 0.8, float64(*topP)),
Temperature: float64(utils.GetPtrVal(temperature, 0)),
TopP: float64(utils.GetPtrVal(topP, 0.8)),
Messages: messages,
QueryID: queryID,
Stream: mod,
Expand Down
12 changes: 6 additions & 6 deletions adapter/skylark/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func (c *ChatInstance) CreateRequest(props *ChatProps) *api.ChatReq {
},
Messages: getMessages(props.Message),
Parameters: &api.Parameters{
TopP: utils.Multi(props.TopP == nil, 0., *props.TopP),
TopK: utils.Multi(props.TopK == nil, 0, int64(*props.TopK)),
Temperature: utils.Multi(props.Temperature == nil, 0., *props.Temperature),
PresencePenalty: utils.Multi(props.PresencePenalty == nil, 0., *props.PresencePenalty),
FrequencyPenalty: utils.Multi(props.FrequencyPenalty == nil, 0., *props.FrequencyPenalty),
RepetitionPenalty: utils.Multi(props.RepeatPenalty == nil, 0., *props.RepeatPenalty),
TopP: utils.GetPtrVal(props.TopP, 0.),
TopK: int64(utils.GetPtrVal(props.TopK, 0)),
Temperature: utils.GetPtrVal(props.Temperature, 0.),
PresencePenalty: utils.GetPtrVal(props.PresencePenalty, 0.),
FrequencyPenalty: utils.GetPtrVal(props.FrequencyPenalty, 0.),
RepetitionPenalty: utils.GetPtrVal(props.RepeatPenalty, 0.),
MaxTokens: int64(props.Token),
},
Functions: getFunctions(props.Tools),
Expand Down
7 changes: 7 additions & 0 deletions utils/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,10 @@ func EachNotNil[T any, U any](arr []T, f func(T) *U) []U {
func Sleep(ms int) {
time.Sleep(time.Duration(ms) * time.Millisecond)
}

func GetPtrVal[T any](ptr *T, def T) T {
if ptr == nil {
return def
}
return *ptr
}

0 comments on commit b753511

Please sign in to comment.