llmbridge

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

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 AnalyzeSentimentTelegram added in v0.5.1

func AnalyzeSentimentTelegram(messages []*tg.Message, model string, prompt string) (string, string, error)

AnalyzeSentimentTelegram analyzes the sentiment of the provided Telegram messages by sending them to the sentiment analysis API.

func AnalyzeSentimentTweets

func AnalyzeSentimentTweets(tweets []*twitterscraper.TweetResult, 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

func AnalyzeSentimentWeb(data string, model string, prompt string) (string, string, error)

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.TweetResult) string

ConcatenateTweets concatenates the text of the provided tweets into a single string, with each tweet separated by a newline character.

func CreatePayload

func CreatePayload(tweetsContent string, model string, prompt string) ([]byte, error)

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

func ParseResponse(resp *http.Response) (string, error)

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

func SanitizeResponse(str string) string

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

type ClaudeAPIConfig struct {
	URL     string
	APIKey  string
	Version string
}

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 Content

type Content struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

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.

func (*GPTClient) SendRequest

func (c *GPTClient) SendRequest(payload string, model string, prompt string) (string, error)

type Message

type Message struct {
	Role    string    `json:"role"`
	Content []Content `json:"content"`
}

type Payload

type Payload struct {
	Model       string    `json:"model"`
	MaxTokens   int       `json:"max_tokens"`
	Temperature float64   `json:"temperature"`
	System      string    `json:"system"`
	Messages    []Message `json:"messages"`
}

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"`
}

type ResponseError

type ResponseError struct {
	Type    string `json:"type"`
	Message string `json:"message"`
}

type Usage

type Usage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

Jump to

Keyboard shortcuts

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