<commit_before>package utils

import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/lambda"
)

// the format for the lambda thumbnail
type LambdaThumbnail struct {
	Bucket    string `json:"bucket"`
	Filename  string `json:"filename"`
	Thumbnail string `json:"thumbnail"`
	MaxWidth  int    `json:"max_width"`
	MaxHeight int    `json:"max_height"`
}

// the format of the lambda context response
type LambdaResponse struct {
	Success string `json:"successMessage"`
	Error   string `json:"errorMessage"`
	Width   int    `json:"thumbWidth"`
	Height  int    `json:"thumbHeight"`
}

// posts to our api endpoint
func (t *LambdaThumbnail) Execute() (width, height int, err error) {

	// Marshal the structs into JSON
	output, err := json.Marshal(t)
	if err != nil {
		return
	}

	session, err := AWSSession()
	if err != nil {
		return
	}

	// params for lambda invocation
	params := &lambda.InvokeInput{
		FunctionName:   aws.String("resize_image"),
		InvocationType: aws.String(lambda.InvocationTypeRequestResponse),
		Payload:        output,
	}

	svc := lambda.New(session)

	// invoke lambda function
	resp, err := svc.Invoke(params)
	if err != nil {
		return
	}

	response := LambdaResponse{}

	err = json.Unmarshal(resp.Payload, &response)
	if err != nil {
		return
	}

	if response.Error != "" {
		return errors.New(fmt.Sprintf("Error creating thumbnail: %s", response.Error))
	}

	// return our values
	width = response.Width
	height = response.Height

	return

}<commit_msg>use sdk to execute lambda instead<commit_after>package utils

import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/lambda"
)

// the format for the lambda thumbnail
type LambdaThumbnail struct {
	Bucket    string `json:"bucket"`
	Filename  string `json:"filename"`
	Thumbnail string `json:"thumbnail"`
	MaxWidth  int    `json:"max_width"`
	MaxHeight int    `json:"max_height"`
}

// the format of the lambda context response
type LambdaResponse struct {
	Success string `json:"successMessage"`
	Error   string `json:"errorMessage"`
	Width   int    `json:"thumbWidth"`
	Height  int    `json:"thumbHeight"`
}

// posts to our api endpoint
func (t *LambdaThumbnail) Execute() (width, height int, err error) {

	// Marshal the structs into JSON
	output, err := json.Marshal(t)
	if err != nil {
		return
	}

	session, err := AWSSession()
	if err != nil {
		return
	}

	// params for lambda invocation
	params := &lambda.InvokeInput{
		FunctionName:   aws.String("resize_image"),
		InvocationType: aws.String(lambda.InvocationTypeRequestResponse),
		Payload:        output,
	}

	svc := lambda.New(session)

	// invoke lambda function
	resp, err := svc.Invoke(params)
	if err != nil {
		return
	}

	response := LambdaResponse{}

	err = json.Unmarshal(resp.Payload, &response)
	if err != nil {
		return
	}

	if response.Error != "" {
		err = errors.New(fmt.Sprintf("Error creating thumbnail: %s", response.Error))
		return
	}

	// return our values
	width = response.Width
	height = response.Height

	return

}
{'fraction_non_alphanumeric': 0.12702003878474466, 'fraction_numerical': 0.0, 'mean_word_length': 3.7615384615384615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4690795', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1013, 'n_words': 278}