Skip to content

Commit

Permalink
#131: Moved auth to client
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger12 committed Feb 15, 2024
1 parent 8974888 commit 32ef411
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 1 addition & 12 deletions pkg/providers/bedrock/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ import (
"fmt"
"time"

//"glide/pkg/providers/clients"

"glide/pkg/api/schemas"

"go.uber.org/zap"

"github.com/google/uuid"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/bedrockruntime"
)

Expand Down Expand Up @@ -88,14 +84,7 @@ func (c *Client) doChatRequest(ctx context.Context, payload *ChatRequest) (*sche
return nil, fmt.Errorf("unable to marshal chat request payload: %w", err)
}

cfg, _ := config.LoadDefaultConfig(ctx,
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(c.config.AccessKey, c.config.SecretKey, "")),
config.WithRegion(c.config.AWSRegion),
)

client := bedrockruntime.NewFromConfig(cfg)

result, err := client.InvokeModel(ctx, &bedrockruntime.InvokeModelInput{
result, err := c.bedrockClient.InvokeModel(ctx, &bedrockruntime.InvokeModelInput{
ModelId: aws.String(c.config.Model),
ContentType: aws.String("application/json"),
Body: rawPayload,
Expand Down
14 changes: 14 additions & 0 deletions pkg/providers/bedrock/client.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package bedrock

import (
"context"
"errors"
"net/http"
"net/url"

"glide/pkg/providers/clients"
"glide/pkg/telemetry"

"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/bedrockruntime"
)

const (
Expand All @@ -21,6 +26,7 @@ var (
// Client is a client for accessing OpenAI API
type Client struct {
baseURL string
bedrockClient *bedrockruntime.Client
chatURL string
chatRequestTemplate *ChatRequest
config *Config
Expand All @@ -35,8 +41,16 @@ func NewClient(providerConfig *Config, clientConfig *clients.ClientConfig, tel *
return nil, err
}

cfg, _ := config.LoadDefaultConfig(context.TODO(), // Is this the right context?
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(providerConfig.AccessKey, providerConfig.SecretKey, "")),
config.WithRegion(providerConfig.AWSRegion),
)

bedrockClient := bedrockruntime.NewFromConfig(cfg)

c := &Client{
baseURL: providerConfig.BaseURL,
bedrockClient: bedrockClient,
chatURL: chatURL,
config: providerConfig,
chatRequestTemplate: NewChatRequestFromConfig(providerConfig),
Expand Down

0 comments on commit 32ef411

Please sign in to comment.