package composer
import "github.com/samgozman/fin-thread/composer"
Index
- type ComposedMeta
- type ComposedNews
-
type Composer
- func NewComposer(oaiToken, tgrAiToken, geminiToken string) *Composer
- func (c *Composer) Compose(ctx context.Context, news journalist.NewsList) ([]*ComposedNews, error)
- func (c *Composer) Filter(ctx context.Context, news journalist.NewsList) (journalist.NewsList, error)
- func (c *Composer) Summarise(ctx context.Context, headlines []*Headline, headlinesLimit, maxTokens int) ([]*SummarisedHeadline, error)
- type Error
- type GoogleGemini
- type GoogleGeminiClientInterface
- type GoogleGeminiRequest
- type Headline
- type SummarisedHeadline
- type TogetherAI
- type TogetherAIResponse
Types
type ComposedMeta
type ComposedMeta struct { Tickers []string `json:"tickers"` Markets []string `json:"markets"` []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. []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
func (c *Composer) Filter(ctx context.Context, news journalist.NewsList) (journalist.NewsList, error)
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
type Error struct { // contains filtered or unexported fields }
Error is an error that occurs during news composing process.
func (*Error) Error
func (e *Error) Error() string
func (*Error) Unwrap
func (e *Error) Unwrap() error
func (*Error) WithValue
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.