-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcompletions.go
54 lines (44 loc) · 1.38 KB
/
completions.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
package yandexgpt
import (
"context"
"net/http"
)
const completionURL = "https://llm.api.cloud.yandex.net/foundationModels/v1"
// Get completion from YandexGPT.
//
// If you're using IAM token, make sure to update client's IAM token by calling
// GetIAMToken(iamToken string) method first.
//
// Keep in mind that if for some strange reason you provided API key and IAM token to the client,
// this method will use API key.
func (c *YandexGPTClient) GetCompletion(
ctx context.Context,
request YandexGPTRequest,
) (response YandexGPTResponse, err error) {
endpoint := completionURL + "/completion"
req, err := c.newRequest(ctx, http.MethodPost, endpoint, request)
if err != nil {
return
}
err = c.sendRequest(req, &response)
return
}
// Get completion from YandexGPT with async method.
//
// If you're using IAM token, make sure to update client's IAM token by calling
// GetIAMToken(iamToken string) method first.
//
// Keep in mind that if for some strange reason you provided API key and IAM token to the client,
// this method will use API key.
func (c *YandexGPTClient) RunCompletionAsync(
ctx context.Context,
request YandexGPTRequest,
) (response YandexCompletionResponse, err error) {
endpoint := completionURL + "/completionAsync"
req, err := c.newRequest(ctx, http.MethodPost, endpoint, request)
if err != nil {
return
}
err = c.sendRequest(req, &response)
return
}