Documentation ¶
Index ¶
- func AnalyzeSentimentDiscord(messages []string, model string, prompt string) (string, string, error)
- func AnalyzeSentimentTweets(tweets []*twitterscraper.Tweet, model string, prompt string) (string, string, error)
- func AnalyzeSentimentWeb(data string, model string, prompt string) (string, string, error)
- func ConcatenateTweets(tweets []*twitterscraper.Tweet) string
- func CreatePayload(tweetsContent string, model string, prompt string) ([]byte, error)
- func ParseResponse(resp *http.Response) (string, error)
- func SanitizeResponse(str string) string
- type ClaudeAPIConfig
- type ClaudeClient
- type Content
- type GPTAPIConfig
- type GPTClient
- type Message
- type Payload
- type Response
- type ResponseContent
- type ResponseError
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnalyzeSentimentDiscord ¶
func AnalyzeSentimentDiscord(messages []string, model string, prompt string) (string, string, error)
AnalyzeSentimentDiscord analyzes the sentiment of the provided Discord messages by sending them to the sentiment analysis API. It concatenates the messages, creates a payload, sends a request to the sentiment analysis service, parses the response, and returns the concatenated messages content, a sentiment summary, and any error.
func AnalyzeSentimentTweets ¶
func AnalyzeSentimentTweets(tweets []*twitterscraper.Tweet, model string, prompt string) (string, string, error)
AnalyzeSentimentTweets analyzes the sentiment of the provided tweets by sending them to the Claude API. It concatenates the tweets, creates a payload, sends a request to Claude, parses the response, and returns the concatenated tweets content, a sentiment summary, and any error.
func AnalyzeSentimentWeb ¶
AnalyzeSentimentWeb analyzes the sentiment of the provided web page text data by sending them to the Claude API. It concatenates the text, creates a payload, sends a request to Claude, parses the response, and returns the concatenated content, a sentiment summary, and any error.
func ConcatenateTweets ¶
func ConcatenateTweets(tweets []*twitterscraper.Tweet) string
ConcatenateTweets concatenates the text of the provided tweets into a single string, with each tweet separated by a newline character.
func CreatePayload ¶
CreatePayload generates a JSON payload for the OpenAI API from the given tweetsContent string. This payload configures the model, max tokens, temperature and prompt to analyze the sentiment of the tweets without bias and summarize the overall sentiment.
func ParseResponse ¶
ParseResponse takes an http.Response, reads its body, and attempts to unmarshal it into a Response struct. It then sanitizes the text content of each ResponseContent within the Response and returns a summary string. Parameters: - resp: A pointer to an http.Response object that contains the server's response to an HTTP request. Returns: - A string that represents a sanitized summary of the response content. - An error if reading the response body or unmarshalling fails.
func SanitizeResponse ¶
SanitizeResponse removes non-ASCII characters and unnecessary whitespace from a string. It also strips away double quotes for cleaner presentation. Parameters: - str: The input string to be sanitized. Returns: A sanitized string with only ASCII characters, reduced whitespace, and no double quotes.
Types ¶
type ClaudeAPIConfig ¶
func NewClaudeAPIConfig ¶
func NewClaudeAPIConfig() *ClaudeAPIConfig
NewClaudeAPIConfig creates a new ClaudeAPIConfig instance with values loaded from the application config.
type ClaudeClient ¶
type ClaudeClient struct {
// contains filtered or unexported fields
}
func NewClaudeClient ¶
func NewClaudeClient() *ClaudeClient
NewClaudeClient creates a new ClaudeClient instance with default configuration.
func (*ClaudeClient) SendRequest ¶
func (c *ClaudeClient) SendRequest(payloadBytes []byte) (*http.Response, error)
SendRequest sends an HTTP request to the Claude API with the given payload. It sets the required headers like Content-Type, x-api-key etc. Returns the HTTP response and any error.
type GPTAPIConfig ¶
type GPTAPIConfig struct {
APIKey string
}
func NewGPTConfig ¶
func NewGPTConfig() *GPTAPIConfig
NewGPTConfig creates a new GPTConfig instance with values loaded from the application config.
type GPTClient ¶
type GPTClient struct {
// contains filtered or unexported fields
}
func NewGPTClient ¶
func NewGPTClient() *GPTClient
NewGPTClient creates a new GPTClient instance with default configuration.
type Response ¶
type Response struct { ID string `json:"id"` Type string `json:"type"` Role string `json:"role"` Content []ResponseContent `json:"content"` Model string `json:"model"` StopReason string `json:"stop_reason"` StopSequence *string `json:"stop_sequence"` // Use *string for nullable fields Usage Usage `json:"usage"` }
type ResponseContent ¶
type ResponseContent struct { Type string `json:"type"` Text string `json:"text,omitempty"` Error *ResponseError `json:"error,omitempty"` }