-
Notifications
You must be signed in to change notification settings - Fork 11
/
ernie_custom_plugin.go
58 lines (50 loc) · 1.79 KB
/
ernie_custom_plugin.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 go_ernie
import (
"context"
"fmt"
"net/http"
)
const ernireCustomPluginUrl = "/rpc/2.0/ai_custom/v1/wenxinworkshop/plugin/"
type ErnieCustomPluginRequest struct {
PluginName string `json:"-"`
Query string `json:"query"`
Stream bool `json:"stream"`
Plugins []string `json:"plugins"`
LLM any `json:"llm,omitempty"`
InputVariables any `json:"input_variables,omitempty"`
History []ChatCompletionMessage `json:"history,omitempty"`
Verbose bool `json:"verbose,omitempty"`
FileUrl string `json:"fileurl,omitempty"`
}
type ErnieCustomPluginResponse struct {
LogId int64 `json:"log_id"`
Id string `json:"id"`
Object string `json:"object"`
Created int `json:"created"`
SentenceId int `json:"sentence_id"`
IsEnd bool `json:"is_end"`
Result string `json:"result"`
NeedClearHistory bool `json:"need_clear_history"`
BanRound int `json:"ban_round"`
Usage ErnieUsage `json:"usage"`
MetaInfo any `json:"meta_info"`
APIError
}
func (c *Client) CreateErnieCustomPluginChatCompletion(
ctx context.Context,
request ErnieCustomPluginRequest,
) (response ErnieCustomPluginResponse, err error) {
if request.Stream {
err = ErrChatCompletionStreamNotSupported
return
}
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(fmt.Sprintf("%s%s/", ernireCustomPluginUrl, request.PluginName)), withBody(request))
if err != nil {
return
}
err = c.sendRequest(req, &response)
if response.ErrorCode != 0 {
err = &response.APIError
}
return
}