revisor

package
v0.0.0-...-407f28a Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package revisor contains services for processing and retrieving articles.

Index

Constants

This section is empty.

Variables

View Source
var ErrTooManyTokens = fmt.Errorf("too many tokens")

ErrTooManyTokens is returned when article is too long.

Functions

This section is empty.

Types

type ChatGPT

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

ChatGPT is a client to make requests to OpenAI chatgpt service.

func NewChatGPT

func NewChatGPT(lg *slog.Logger, cl http.Client, token string, maxResponseTokens int) *ChatGPT

NewChatGPT creates new ChatGPT client.

func (*ChatGPT) BulletPoints

func (s *ChatGPT) BulletPoints(ctx context.Context, article store.Article) (string, error)

BulletPoints shortens article.

func (*ChatGPT) CacheStat

func (s *ChatGPT) CacheStat() cache.Stats

CacheStat returns cache stats.

type Extractor

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

Extractor is extracts article from HTML page.

func NewExtractor

func NewExtractor() Extractor

NewExtractor creates new Extractor.

func (Extractor) Extract

func (e Extractor) Extract(rd io.Reader) (store.Article, error)

Extract extracts article from an HTML page.

type OpenAIClient

type OpenAIClient interface {
	CreateChatCompletion(context.Context, openai.ChatCompletionRequest) (openai.ChatCompletionResponse, error)
}

OpenAIClient is interface for OpenAI client with the possibility to mock it

type OpenAIClientMock

type OpenAIClientMock struct {
	// CreateChatCompletionFunc mocks the CreateChatCompletion method.
	CreateChatCompletionFunc func(contextMoqParam context.Context, chatCompletionRequest openai.ChatCompletionRequest) (openai.ChatCompletionResponse, error)
	// contains filtered or unexported fields
}

OpenAIClientMock is a mock implementation of OpenAIClient.

func TestSomethingThatUsesOpenAIClient(t *testing.T) {

	// make and configure a mocked OpenAIClient
	mockedOpenAIClient := &OpenAIClientMock{
		CreateChatCompletionFunc: func(contextMoqParam context.Context, chatCompletionRequest openai.ChatCompletionRequest) (openai.ChatCompletionResponse, error) {
			panic("mock out the CreateChatCompletion method")
		},
	}

	// use mockedOpenAIClient in code that requires OpenAIClient
	// and then make assertions.

}

func (*OpenAIClientMock) CreateChatCompletion

func (mock *OpenAIClientMock) CreateChatCompletion(contextMoqParam context.Context, chatCompletionRequest openai.ChatCompletionRequest) (openai.ChatCompletionResponse, error)

CreateChatCompletion calls CreateChatCompletionFunc.

func (*OpenAIClientMock) CreateChatCompletionCalls

func (mock *OpenAIClientMock) CreateChatCompletionCalls() []struct {
	ContextMoqParam       context.Context
	ChatCompletionRequest openai.ChatCompletionRequest
}

CreateChatCompletionCalls gets all the calls that were made to CreateChatCompletion. Check the length with:

len(mockedOpenAIClient.CreateChatCompletionCalls())

type Service

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

Service is a main application service.

func NewService

func NewService(lg *slog.Logger, cl *http.Client, chatGPT *ChatGPT, extractor Extractor) *Service

NewService creates new service.

func (*Service) GPTCacheStat

func (s *Service) GPTCacheStat() cache.Stats

GPTCacheStat returns cache stats.

func (*Service) GetArticle

func (s *Service) GetArticle(ctx context.Context, u string) (store.Article, error)

GetArticle shortens article.

Jump to

Keyboard shortcuts

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