Documentation
¶
Index ¶
- type ComposedMeta
- type ComposedNews
- type 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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ComposedMeta ¶
type ComposedNews ¶
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 ¶
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.
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.
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 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 ¶
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.