Skip to content

Commit

Permalink
feat: add seed for deterministic sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
kardolus committed Oct 27, 2024
1 parent e7ef59d commit 102bd72
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ environment variables, a config.yaml file, and default values, in that respectiv
| `frequency_penalty` | Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far. | 0.0 |
| `top_p` | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. | 1.0 |
| `presence_penalty` | Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far. | 0.0 |
| `seed` | Sets the seed for deterministic sampling (Beta). Repeated requests with the same seed and parameters aim to return the same result. | 0 |
| `url` | The base URL for the OpenAI API. | 'https://api.openai.com' |
| `completions_path` | The API endpoint for completions. | '/v1/chat/completions' |
| `models_path` | The API endpoint for accessing model information. | '/v1/models' |
Expand Down Expand Up @@ -619,8 +620,9 @@ data. If you have any concerns about this, please feel free to delete this direc
Thank you for using ChatGPT CLI!
<div align="center" align-items: center;">
<a href="#top">
<img src="https://img.shields.io/badge/Back%20to%20Top-000000?style=for-the-badge&logo=github&logoColor=white" alt="Back to Top">
</a>
<div align="center" style="text-align: center; display: flex; justify-content: center; align-items: center;">
<a href="#top">
<img src="https://img.shields.io/badge/Back%20to%20Top-000000?style=for-the-badge&logo=github&logoColor=white" alt="Back to Top">
</a>
</div>
1 change: 1 addition & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func (c *Client) createBody(stream bool) ([]byte, error) {
TopP: c.Config.TopP,
FrequencyPenalty: c.Config.FrequencyPenalty,
PresencePenalty: c.Config.PresencePenalty,
Seed: c.Config.Seed,
Stream: stream,
}

Expand Down
2 changes: 2 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ func createBody(messages []types.Message, stream bool) ([]byte, error) {
FrequencyPenalty: config.FrequencyPenalty,
MaxTokens: config.MaxTokens,
PresencePenalty: config.PresencePenalty,
Seed: config.Seed,
}

return json.Marshal(req)
Expand Down Expand Up @@ -547,5 +548,6 @@ func MockConfig() types.Config {
TrackTokenUsage: true,
SkipTLSVerify: false,
Debug: false,
Seed: 1,
}
}
2 changes: 2 additions & 0 deletions cmd/chatgpt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var configMetadata = []ConfigMetadata{
{"skip_tls_verify", "set-skip-tls-verify", false, "Skip TLS certificate verification"},
{"debug", "set-debug", false, "Enable debug mode"},
{"multiline", "set-multiline", false, "Enables multiline mode while in interactive mode"},
{"seed", "set-seed", 0, "Sets the seed for deterministic sampling (Beta)"},
{"name", "set-name", "openai", "The prefix for environment variable overrides"},
}

Expand Down Expand Up @@ -726,6 +727,7 @@ func createConfigFromViper() types.Config {
SkipTLSVerify: viper.GetBool("skip_tls_verify"),
Debug: viper.GetBool("debug"),
Multiline: viper.GetBool("multiline"),
Seed: viper.GetInt("seed"),
}
}

Expand Down
1 change: 1 addition & 0 deletions types/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type CompletionsRequest struct {
PresencePenalty float64 `json:"presence_penalty,omitempty"`
Messages []Message `json:"messages"`
Stream bool `json:"stream"`
Seed int `json:"seed,omitempty"`
}

type Message struct {
Expand Down
1 change: 1 addition & 0 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ type Config struct {
SkipTLSVerify bool `yaml:"skip_tls_verify"`
Debug bool `yaml:"debug"`
Multiline bool `yaml:"multiline"`
Seed int `yaml:"seed"`
}

0 comments on commit 102bd72

Please sign in to comment.