composer

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComposedMeta

type ComposedMeta struct {
	Tickers  []string `json:"tickers"`
	Markets  []string `json:"markets"`
	Hashtags []string `json:"hashtags"`
}

type ComposedNews

type ComposedNews struct {
	ID       string   `json:"id"`
	Text     string   `json:"text"`
	Tickers  []string `json:"tickers"`  // tickers mentioned or/and related to the news
	Markets  []string `json:"markets"`  // US/EU/Asia stocks, bonds, commodities, housing, etc.
	Hashtags []string `json:"hashtags"` // hashtags related to the news (#inflation, #fed, #buybacks, etc.)
}

type Composer

type Composer struct {
	OpenAiClient       openAiClientInterface
	TogetherAIClient   togetherAIClientInterface
	GoogleGeminiClient GoogleGeminiClientInterface
	Config             *promptConfig
}

Composer is used to compose (rephrase) news and events, find some meta information about them, filter out some unnecessary stuff, summarise them and so on.

func NewComposer

func NewComposer(oaiToken, tgrAiToken, geminiToken string) *Composer

NewComposer creates a new Composer instance with OpenAI and TogetherAI clients and default config.

func (*Composer) Compose

func (c *Composer) Compose(ctx context.Context, news journalist.NewsList) ([]*ComposedNews, error)

Compose creates a new AI-composed news from the given news list. It will also find some meta information about the news and events (markets, tickers, hashtags).

func (*Composer) Filter

Filter removes unnecessary news from the given news list using TogetherAI API and returns the same news list with IsFiltered flag set to true for filtered out news.

func (*Composer) Summarise

func (c *Composer) Summarise(ctx context.Context, headlines []*Headline, headlinesLimit, maxTokens int) ([]*SummarisedHeadline, error)

Summarise create a short AI summary for the Headline array of any kind. It will also add Markdown links in summary.

`headlinesLimit` is used to tell AI to use only top N Headlines from the batch for summary (AI will decide).

`maxTokens` is used to limit summary size in tokens. It is the hard limit for AI and also used for dynamically decide how many sentences AI should produce.

type Error added in v1.5.0

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

Error is an error that occurs during news composing process.

func (*Error) Error added in v1.5.0

func (e *Error) Error() string

func (*Error) Unwrap added in v1.5.1

func (e *Error) Unwrap() error

func (*Error) WithValue added in v1.5.0

func (e *Error) WithValue(value string) *Error

WithValue sets the value that caused the error.

type GoogleGemini

type GoogleGemini struct {
	APIKey string
}

GoogleGemini is a structure for Google Gemini AI API client. ! https://ai.google.dev/available_regions#available_regions ! Gemini is not available in EU region yet.

func NewGoogleGemini

func NewGoogleGemini(apiKey string) *GoogleGemini

NewGoogleGemini creates new Google Gemini client.

func (*GoogleGemini) CreateChatCompletion

func (g *GoogleGemini) CreateChatCompletion(ctx context.Context, req GoogleGeminiRequest) (response *genai.GenerateContentResponse, err error)

CreateChatCompletion creates a new chat completion request to Google Gemini API.

type GoogleGeminiClientInterface

type GoogleGeminiClientInterface interface {
	CreateChatCompletion(ctx context.Context, req GoogleGeminiRequest) (response *genai.GenerateContentResponse, err error)
}

type GoogleGeminiRequest

type GoogleGeminiRequest struct {
	Prompt      string  `json:"prompt"`
	MaxTokens   int32   `json:"max_tokens"`
	Temperature float32 `json:"temperature"`
	TopP        float32 `json:"top_p"`
	TopK        int32   `json:"top_k"`
}

GoogleGeminiRequest is a struct that contains options for Google Gemini API requests.

type Headline

type Headline struct {
	ID   string `json:"id"`
	Text string `json:"text"`
	Link string `json:"link"`
}

Headline is the base data structure for the data to summarise.

type SummarisedHeadline

type SummarisedHeadline struct {
	ID      string `json:"id"`      // ID of the news or event
	Verb    string `json:"verb"`    // Main verb of the news or event to be marked in summary
	Summary string `json:"summary"` // Summary of the news or event
	Link    string `json:"link"`    // Link to the publication to use in string Markdown
}

SummarisedHeadline is the base data structure of summarised news or events.

OpenAI fails to apply markdown on selected verbs, but it's good at finding them.

type TogetherAI

type TogetherAI struct {
	APIKey string
	URL    string
}

TogetherAI client to interact with TogetherAI API (replacement for OpenAI API in some cases).

func NewTogetherAI

func NewTogetherAI(apiKey string) *TogetherAI

NewTogetherAI creates new TogetherAI client.

func (*TogetherAI) CreateChatCompletion

func (t *TogetherAI) CreateChatCompletion(ctx context.Context, options togetherAIRequest) (*TogetherAIResponse, error)

CreateChatCompletion creates a new chat completion request to TogetherAI API.

type TogetherAIResponse

type TogetherAIResponse struct {
	ID      string `json:"id"`
	Choices []struct {
		Text string `json:"text"`
	} `json:"choices"`
	Usage struct {
		PromptTokens     int `json:"prompt_tokens"`
		CompletionTokens int `json:"completion_tokens"`
		TotalTokens      int `json:"total_tokens"`
	}
	Created int64  `json:"created"`
	Model   string `json:"model"`
	Object  string `json:"object"`
}

TogetherAIResponse is a struct that contains response from TogetherAI API.

Jump to

Keyboard shortcuts

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