-
Notifications
You must be signed in to change notification settings - Fork 19
/
complete.go
58 lines (47 loc) · 1.35 KB
/
complete.go
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 anthropic
import (
"context"
"net/http"
)
type CompleteRequest struct {
Model Model `json:"model"`
Prompt string `json:"prompt"`
MaxTokensToSample int `json:"max_tokens_to_sample"`
StopSequences []string `json:"stop_sequences,omitempty"`
Temperature *float32 `json:"temperature,omitempty"`
TopP *float32 `json:"top_p,omitempty"`
TopK *int `json:"top_k,omitempty"`
MetaData map[string]any `json:"meta_data,omitempty"`
Stream bool `json:"stream,omitempty"`
}
func (c *CompleteRequest) SetTemperature(t float32) {
c.Temperature = &t
}
func (c *CompleteRequest) SetTopP(p float32) {
c.TopP = &p
}
func (c *CompleteRequest) SetTopK(k int) {
c.TopK = &k
}
type CompleteResponse struct {
httpHeader
Type string `json:"type"`
ID string `json:"id"`
Completion string `json:"completion"`
// possible values are: stop_sequence、max_tokens、null
StopReason string `json:"stop_reason"`
Model Model `json:"model"`
}
func (c *Client) CreateComplete(
ctx context.Context,
request CompleteRequest,
) (response CompleteResponse, err error) {
request.Stream = false
urlSuffix := "/complete"
req, err := c.newRequest(ctx, http.MethodPost, urlSuffix, &request)
if err != nil {
return
}
err = c.sendRequest(req, &response)
return
}