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

llms: Add Seed option to all supporting backends #732

Merged
merged 2 commits into from
Mar 31, 2024
Merged
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
1 change: 1 addition & 0 deletions llms/mistral/mistralmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func mistralChatParamsFromCallOptions(callOpts *llms.CallOptions) sdk.ChatReques
chatOpts := sdk.DefaultChatRequestParams
chatOpts.MaxTokens = callOpts.MaxTokens
chatOpts.Temperature = callOpts.Temperature
chatOpts.RandomSeed = callOpts.Seed
chatOpts.Tools = make([]sdk.Tool, 0)
for _, function := range callOpts.Functions {
chatOpts.Tools = append(chatOpts.Tools, sdk.Tool{
Expand Down
1 change: 1 addition & 0 deletions llms/openai/internal/openaiclient/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ChatRequest struct {
Stream bool `json:"stream,omitempty"`
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
PresencePenalty float64 `json:"presence_penalty,omitempty"`
Seed int `json:"seed,omitempty"`

ResponseFormat *ResponseFormat `json:"response_format,omitempty"`

Expand Down
2 changes: 2 additions & 0 deletions llms/openai/internal/openaiclient/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type CompletionRequest struct {
PresencePenalty float64 `json:"presence_penalty,omitempty"`
TopP float64 `json:"top_p,omitempty"`
StopWords []string `json:"stop,omitempty"`
Seed int `json:"seed,omitempty"`

// StreamingFunc is a function to be called for each chunk of a streaming response.
// Return an error to stop streaming early.
Expand Down Expand Up @@ -85,5 +86,6 @@ func (c *Client) createCompletion(ctx context.Context, payload *CompletionReques
FrequencyPenalty: payload.FrequencyPenalty,
PresencePenalty: payload.PresencePenalty,
StreamingFunc: payload.StreamingFunc,
Seed: payload.Seed,
})
}
1 change: 1 addition & 0 deletions llms/openai/openaillm.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (o *LLM) GenerateContent(ctx context.Context, messages []llms.MessageConten
FrequencyPenalty: opts.FrequencyPenalty,
PresencePenalty: opts.PresencePenalty,
FunctionCallBehavior: openaiclient.FunctionCallBehavior(opts.FunctionCallBehavior),
Seed: opts.Seed,
}
if opts.JSONMode {
req.ResponseFormat = ResponseFormatJSON
Expand Down
Loading