Skip to content

Commit

Permalink
chore: fix formatters and remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ann Vasileva committed Nov 5, 2024
1 parent 2a5a67f commit 48d14e4
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 50 deletions.
28 changes: 14 additions & 14 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func NewYandexGPTClientWithAPIKey(
}
}

// TODO: change type any maybe
func (c *YandexGPTClient) newRequest(
ctx context.Context,
method,
Expand All @@ -64,7 +63,7 @@ func (c *YandexGPTClient) newRequest(
if err != nil {
return nil, err
}

c.setHeaders(request)

return request, nil
Expand Down
2 changes: 0 additions & 2 deletions completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func (c *YandexGPTClient) GetCompletion(
ctx context.Context,
request YandexGPTRequest,
) (response YandexGPTResponse, err error) {
// TODO:
// 1. Validate Request

endpoint := completionURL + "/completion"

Expand Down
1 change: 0 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "net/http"
type YandexGPTClientConfig struct {
ApiKey string
IAMToken string
BaseURL string
HTTPClient *http.Client
}

Expand Down
8 changes: 4 additions & 4 deletions error.go
Original file line number Diff line number Diff line change
@@ -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"`
}
5 changes: 2 additions & 3 deletions examples/completion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand Down
19 changes: 9 additions & 10 deletions examples/completionAsync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -21,20 +20,20 @@ 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,
MaxTokens: 100,
},
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",
},
},
}
Expand All @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ type YandexGPTCompletionOptions struct {
}

type YandexIAMRequest struct {
APIKey string `json:"yandexPassportOauthToken"`
APIKey string `json:"yandexPassportOauthToken"`
}
24 changes: 12 additions & 12 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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"`
Expand Down

0 comments on commit 48d14e4

Please sign in to comment.