paraphrase

package
v0.0.0-...-9042912 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidProvider = errors.New("invalid value for provider")
	ErrInvalidTone     = errors.New("invalid value for tone")
	ErrInvalidText     = errors.New("invalid value for text")
)
View Source
var AvailableProviders = []Provider{ChatGpt, Gemini}
View Source
var (
	ErrNoConfiguredParaphraser = errors.New("no paraphraser configured for provider")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Timeout time.Duration `envconfig:"PARAPHRASE_TIMEOUT" default:"15s"`
}

Config contains the configuration for the Paraphrase Service.

func ConfigFromEnv

func ConfigFromEnv() *Config

ConfigFromEnv loads the configuration from the environment variables.

type MockParaphraser

type MockParaphraser struct {
	mock.Mock
}

MockParaphraser is an autogenerated mock type for the Paraphraser type

func NewMockParaphraser

func NewMockParaphraser(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockParaphraser

NewMockParaphraser creates a new instance of MockParaphraser. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockParaphraser) EXPECT

func (*MockParaphraser) Paraphrase

func (_m *MockParaphraser) Paraphrase(ctx context.Context, tone string, text string) (string, error)

Paraphrase provides a mock function with given fields: ctx, tone, text

type MockParaphraser_Expecter

type MockParaphraser_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockParaphraser_Expecter) Paraphrase

func (_e *MockParaphraser_Expecter) Paraphrase(ctx interface{}, tone interface{}, text interface{}) *MockParaphraser_Paraphrase_Call

Paraphrase is a helper method to define mock.On call

  • ctx context.Context
  • tone string
  • text string

type MockParaphraser_Paraphrase_Call

type MockParaphraser_Paraphrase_Call struct {
	*mock.Call
}

MockParaphraser_Paraphrase_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Paraphrase'

func (*MockParaphraser_Paraphrase_Call) Return

func (*MockParaphraser_Paraphrase_Call) Run

func (*MockParaphraser_Paraphrase_Call) RunAndReturn

type Paraphraser

type Paraphraser interface {
	// Paraphrase rewords the given text to sound more like the given tone.
	Paraphrase(ctx context.Context, tone string, text string) (string, error)
}

Paraphraser is the interface that will be implemented by concrete paraphrasing providers.

type Payload

type Payload struct {
	Provider `json:"provider"`
	Tone     `json:"tone"`
	Text     string `json:"text"`
}

Payload represents the body for the paraphrase request.

func (*Payload) Validate

func (p *Payload) Validate() error

Validate throws an error if the Payload is invalid.

type Provider

type Provider string

Provider is the type for representing possible paraphrasing providers.

const (
	ChatGpt Provider = "chatgpt"
	Gemini  Provider = "gemini"
)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the service layer containing functionality for paraphrasing.

func NewService

func NewService(cfg *Config, paraphrasers map[Provider]Paraphraser) *Service

func (*Service) Paraphrase

func (s *Service) Paraphrase(ctx context.Context, provider Provider, tone Tone, text string) (string, error)

Paraphrase forwards the paraphrasing request to the configured paraphraser for the given provider. A timeout is set for the request based on the service configuration.

type Tone

type Tone string

Tone is the type for representing possible paraphrasing tones.

const (
	Formal      Tone = "formal"
	Amicable    Tone = "amicable"
	Fun         Tone = "fun"
	Casual      Tone = "casual"
	Sympathetic Tone = "sympathetic"
	Persuasive  Tone = "persuasive"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL