From 48d14e473951431382a54e002a53e1abbe29e81e Mon Sep 17 00:00:00 2001 From: Ann Vasileva Date: Wed, 6 Nov 2024 01:04:57 +0300 Subject: [PATCH] chore: fix formatters and remove comments --- auth.go | 28 ++++++++++++++-------------- client.go | 3 +-- completions.go | 2 -- config.go | 1 - error.go | 8 ++++---- examples/completion/main.go | 5 ++--- examples/completionAsync/main.go | 19 +++++++++---------- message.go | 2 +- request.go | 2 +- response.go | 24 ++++++++++++------------ 10 files changed, 44 insertions(+), 50 deletions(-) diff --git a/auth.go b/auth.go index 5112c4a..bd76dad 100644 --- a/auth.go +++ b/auth.go @@ -13,19 +13,19 @@ const getIAMUrl = "https://iam.api.cloud.yandex.net/iam/v1/tokens" // // If you will use it when API key is specified, method CreateRequest(...) will always use API key. func (c *YandexGPTClient) UpdateIAMToken(ctx context.Context) error { - iamRq := YandexIAMRequest{APIKey: c.config.ApiKey} - req, err := c.newRequest(ctx, http.MethodPost, getIAMUrl, iamRq) - if err != nil { - return err - } - - var resp YandexIAMResponse - err = c.sendRequest(req, &resp) - if err != nil { - return err - } + iamRq := YandexIAMRequest{APIKey: c.config.ApiKey} + req, err := c.newRequest(ctx, http.MethodPost, getIAMUrl, iamRq) + if err != nil { + return err + } - //set new IAMToken - c.config.updateIAMToken(resp.IAMToken) - return nil + var resp YandexIAMResponse + err = c.sendRequest(req, &resp) + if err != nil { + return err + } + + //set new IAMToken + c.config.updateIAMToken(resp.IAMToken) + return nil } diff --git a/client.go b/client.go index 6850a1b..ba418f0 100644 --- a/client.go +++ b/client.go @@ -53,7 +53,6 @@ func NewYandexGPTClientWithAPIKey( } } -// TODO: change type any maybe func (c *YandexGPTClient) newRequest( ctx context.Context, method, @@ -64,7 +63,7 @@ func (c *YandexGPTClient) newRequest( if err != nil { return nil, err } - + c.setHeaders(request) return request, nil diff --git a/completions.go b/completions.go index a99c195..43eb505 100644 --- a/completions.go +++ b/completions.go @@ -18,8 +18,6 @@ func (c *YandexGPTClient) GetCompletion( ctx context.Context, request YandexGPTRequest, ) (response YandexGPTResponse, err error) { - // TODO: - // 1. Validate Request endpoint := completionURL + "/completion" diff --git a/config.go b/config.go index a6ed967..b542309 100644 --- a/config.go +++ b/config.go @@ -5,7 +5,6 @@ import "net/http" type YandexGPTClientConfig struct { ApiKey string IAMToken string - BaseURL string HTTPClient *http.Client } diff --git a/error.go b/error.go index 930bb3f..45ffa34 100644 --- a/error.go +++ b/error.go @@ -1,8 +1,8 @@ package yandexgpt type YandexGPTError struct { - HTTPCode int `json:"httpCode"` - Message string `json:"message"` - HTTPStatus string `json:"httpStatus"` - Details DetailsResponse `json:"error.details"` + HTTPCode int `json:"httpCode"` + Message string `json:"message"` + HTTPStatus string `json:"httpStatus"` + Details DetailsResponse `json:"error.details"` } diff --git a/examples/completion/main.go b/examples/completion/main.go index 4595123..7b6ff0b 100644 --- a/examples/completion/main.go +++ b/examples/completion/main.go @@ -3,13 +3,12 @@ package main import ( "context" "fmt" - "os" "github.com/sheeiavellie/go-yandexgpt" ) func main() { - client := yandexgpt.NewYandexGPTClientWithAPIKey(os.Getenv("YAAPI_KEY")) + client := yandexgpt.NewYandexGPTClientWithAPIKey("API_KEY") // get, update and set iam token ctx := context.Background() @@ -19,7 +18,7 @@ func main() { } request := yandexgpt.YandexGPTRequest{ - ModelURI: yandexgpt.MakeModelURI(os.Getenv("CATALOG_ID"), yandexgpt.YandexGPT4ModelLite), + ModelURI: yandexgpt.MakeModelURI("CATALOG_ID", yandexgpt.YandexGPT4ModelLite), CompletionOptions: yandexgpt.YandexGPTCompletionOptions{ Stream: false, Temperature: 0.7, diff --git a/examples/completionAsync/main.go b/examples/completionAsync/main.go index f083c96..43f1a51 100644 --- a/examples/completionAsync/main.go +++ b/examples/completionAsync/main.go @@ -4,14 +4,13 @@ import ( "context" "fmt" "log" - "os" "time" "github.com/sheeiavellie/go-yandexgpt" ) func main() { - client := yandexgpt.NewYandexGPTClientWithAPIKey(os.Getenv("YAAPI_KEY")) + client := yandexgpt.NewYandexGPTClientWithAPIKey("API_KEY") // get, update and set iam token ctx := context.Background() @@ -21,7 +20,7 @@ func main() { } request := yandexgpt.YandexGPTRequest{ - ModelURI: yandexgpt.MakeModelURI(os.Getenv("CATALOG_ID"), yandexgpt.YandexGPT4ModelLite), + ModelURI: yandexgpt.MakeModelURI("CATALOG_ID", yandexgpt.YandexGPT4ModelLite), CompletionOptions: yandexgpt.YandexGPTCompletionOptions{ Stream: false, Temperature: 0.7, @@ -29,12 +28,12 @@ func main() { }, Messages: []yandexgpt.YandexGPTMessage{ { - Role: yandexgpt.YandexGPTMessageRoleSystem, - Text: "Every time you get ONE you answer just TWO", + Role: yandexgpt.YandexGPTMessageRoleSystem, + Text: "Every time you get ONE you answer just TWO", }, { - Role: yandexgpt.YandexGPTMessageRoleUser, - Text: "ONE", + Role: yandexgpt.YandexGPTMessageRoleUser, + Text: "ONE", }, }, } @@ -53,10 +52,10 @@ func main() { if status.Done { isCompleted = true - fmt.Println("\n Chat answer: \n") + fmt.Println("\n Chat answer: \n") fmt.Println(status.Response.Alternatives[0].Message.Text) } else { - time.Sleep(5 * time.Second) - } + time.Sleep(5 * time.Second) + } } } diff --git a/message.go b/message.go index cd95385..1921830 100644 --- a/message.go +++ b/message.go @@ -3,7 +3,7 @@ package yandexgpt type YandexGPTMessage struct { Role yandexGPTRole `json:"role"` Text string `json:"text"` - ToolCallList *ToolCallList `json:"toolCallList"` + ToolCallList *ToolCallList `json:"toolCallList"` } type YandexToolResultList struct { diff --git a/request.go b/request.go index 3475067..b4dd2de 100644 --- a/request.go +++ b/request.go @@ -13,5 +13,5 @@ type YandexGPTCompletionOptions struct { } type YandexIAMRequest struct { - APIKey string `json:"yandexPassportOauthToken"` + APIKey string `json:"yandexPassportOauthToken"` } diff --git a/response.go b/response.go index 7b8bae6..52e7494 100644 --- a/response.go +++ b/response.go @@ -49,14 +49,14 @@ type YandexIAMResponse struct { } type YandexCompletionResponse struct { - ID string `json:"id"` - Description string `json:"description"` - CreatedAt string `json:"createdAt"` - ModifiedAt string `json:"modifiedAt"` - Done bool `json:"done"` + ID string `json:"id"` + Description string `json:"description"` + CreatedAt string `json:"createdAt"` + ModifiedAt string `json:"modifiedAt"` + Done bool `json:"done"` Metadata *MetadataResponse `json:"metadata"` Error *StatusResponse `json:"error"` - Response string `json:"response"` + Response string `json:"response"` httpHeader } @@ -77,12 +77,12 @@ type DetailsResponse struct { } type OperationResponse struct { - ID string `json:"id"` - Description string `json:"description"` - CreatedAt string `json:"createdAt"` - CreatedBy string `json:"createdBy"` - ModifiedAt string `json:"modifiedAt"` - Done bool `json:"done"` + ID string `json:"id"` + Description string `json:"description"` + CreatedAt string `json:"createdAt"` + CreatedBy string `json:"createdBy"` + ModifiedAt string `json:"modifiedAt"` + Done bool `json:"done"` Metadata *MetadataResponse `json:"metadata"` Error *StatusResponse `json:"error"` Response *YandexResponse `json:"response"`