|
package langchain |
|
|
|
type PredictOptions struct { |
|
Model string `json:"model"` |
|
|
|
MaxTokens int `json:"max_tokens"` |
|
|
|
Temperature float64 `json:"temperature"` |
|
|
|
StopWords []string `json:"stop_words"` |
|
} |
|
|
|
type PredictOption func(p *PredictOptions) |
|
|
|
var DefaultOptions = PredictOptions{ |
|
Model: "gpt2", |
|
MaxTokens: 200, |
|
Temperature: 0.96, |
|
StopWords: nil, |
|
} |
|
|
|
type Predict struct { |
|
Completion string |
|
} |
|
|
|
func SetModel(model string) PredictOption { |
|
return func(o *PredictOptions) { |
|
o.Model = model |
|
} |
|
} |
|
|
|
func SetTemperature(temperature float64) PredictOption { |
|
return func(o *PredictOptions) { |
|
o.Temperature = temperature |
|
} |
|
} |
|
|
|
func SetMaxTokens(maxTokens int) PredictOption { |
|
return func(o *PredictOptions) { |
|
o.MaxTokens = maxTokens |
|
} |
|
} |
|
|
|
func SetStopWords(stopWords []string) PredictOption { |
|
return func(o *PredictOptions) { |
|
o.StopWords = stopWords |
|
} |
|
} |
|
|
|
|
|
func NewPredictOptions(opts ...PredictOption) PredictOptions { |
|
p := DefaultOptions |
|
for _, opt := range opts { |
|
opt(&p) |
|
} |
|
return p |
|
} |
|
|