File size: 1,256 Bytes
7def60a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package langchain

type PredictOptions struct {
	Model string `json:"model"`
	// MaxTokens is the maximum number of tokens to generate.
	MaxTokens int `json:"max_tokens"`
	// Temperature is the temperature for sampling, between 0 and 1.
	Temperature float64 `json:"temperature"`
	// StopWords is a list of words to stop on.
	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
	}
}

// NewPredictOptions Create a new PredictOptions object with the given options.
func NewPredictOptions(opts ...PredictOption) PredictOptions {
	p := DefaultOptions
	for _, opt := range opts {
		opt(&p)
	}
	return p
}