-
Notifications
You must be signed in to change notification settings - Fork 11
/
ernie_bot_4.go
48 lines (40 loc) · 1.38 KB
/
ernie_bot_4.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
package go_ernie
import (
"context"
"net/http"
)
const ernieBot4URL = "/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro"
type ErnieBot4Request struct {
Messages []ChatCompletionMessage `json:"messages"`
Temperature float32 `json:"temperature,omitempty"`
TopP float32 `json:"top_p,omitempty"`
Stream bool `json:"stream"`
UserId string `json:"user_id,omitempty"`
Functions []ErnieFunction `json:"functions,omitempty"`
PenaltyScore float32 `json:"penalty_score,omitempty"`
System string `json:"system,omitempty"`
Stop []string `json:"stop,omitempty"`
DisableSearch bool `json:"disable_search,omitempty"`
EnableCitation bool `json:"enable_citation,omitempty"`
}
type ErnieBot4Response struct {
ErnieBotResponse
}
func (c *Client) CreateErnieBot4ChatCompletion(
ctx context.Context,
request ErnieBot4Request,
) (response ErnieBot4Response, err error) {
if request.Stream {
err = ErrChatCompletionStreamNotSupported
return
}
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(ernieBot4URL), withBody(request))
if err != nil {
return
}
err = c.sendRequest(req, &response)
if response.ErrorCode != 0 {
err = &response.APIError
}
return
}