Skip to content

Commit

Permalink
fix(gemini): refactor maxTokens type to int32 across the codebase (#196)
Browse files Browse the repository at this point in the history
- Change the type of `maxTokens` from `int` to `int32` in multiple files
- Update the function `WithMaxTokens` to accept `int32` instead of `int`
- Adjust the usage of `maxTokens` in the `New` function to match the new type

Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy authored Sep 8, 2024
1 parent 8106c7e commit 93e50b8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewGemini() (*gemini.Client, error) {
return gemini.New(
gemini.WithToken(viper.GetString("openai.api_key")),
gemini.WithModel(viper.GetString("openai.model")),
gemini.WithMaxTokens(viper.GetInt("openai.max_tokens")),
gemini.WithMaxTokens(viper.GetInt32("openai.max_tokens")),
gemini.WithTemperature(float32(viper.GetFloat64("openai.temperature"))),
gemini.WithTopP(float32(viper.GetFloat64("openai.top_p"))),
)
Expand Down
4 changes: 2 additions & 2 deletions gemini/gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type Client struct {
client *genai.GenerativeModel
model string
maxTokens int
maxTokens int32
temperature float32
topP float32
debug bool
Expand Down Expand Up @@ -106,7 +106,7 @@ func New(opts ...Option) (c *Client, err error) {
}

engine.client = client.GenerativeModel(engine.model)
engine.client.MaxOutputTokens = util.Int32Ptr(int32(engine.maxTokens))
engine.client.MaxOutputTokens = util.Int32Ptr(engine.maxTokens)
engine.client.Temperature = util.Float32Ptr(engine.temperature)
engine.client.TopP = util.Float32Ptr(engine.topP)

Expand Down
4 changes: 2 additions & 2 deletions gemini/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func WithModel(val string) Option {
// WithMaxTokens returns a new Option that sets the max tokens for the client configuration.
// The maximum number of tokens to generate in the chat completion.
// The total length of input tokens and generated tokens is limited by the model's context length.
func WithMaxTokens(val int) Option {
func WithMaxTokens(val int32) Option {
if val <= 0 {
val = defaultMaxTokens
}
Expand Down Expand Up @@ -83,7 +83,7 @@ func WithTopP(val float32) Option {
type config struct {
token string
model string
maxTokens int
maxTokens int32
temperature float32
topP float32
}
Expand Down

0 comments on commit 93e50b8

Please sign in to comment.