config

package
v0.0.8-beta Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrivKeyFile = "MASA_PRIV_KEY_FILE"
	BootNodes   = "BOOTNODES"
	MasaDir     = "MASA_DIR"
	RpcUrl      = "RPC_URL"
	PortNbr     = "PORT_NBR"
	UDP         = "UDP"
	TCP         = "TCP"
	PrivateKey  = "PRIVATE_KEY"
	StakeAmount = "STAKE_AMOUNT"
	LogLevel    = "LOG_LEVEL"
	LogFilePath = "LOG_FILEPATH"
	Environment = "ENV"
	AllowedPeer = "allowedPeer"
	Signature   = "signature"
	Debug       = "debug"
	Version     = "v0.0.8-beta"
	FilePath    = "FILE_PATH"
	Validator   = "VALIDATOR"
	CachePath   = "CACHE_PATH"
	Faucet      = "FAUCET"

	MasaPrefix           = "/masa"
	OracleProtocol       = "oracle_protocol"
	NodeDataSyncProtocol = "nodeDataSync"
	NodeGossipTopic      = "gossip"
	PublicKeyTopic       = "bootNodePublicKey"
	WorkerTopic          = "workerTopic"
	BlockTopic           = "blockTopic"
	Rendezvous           = "masa-mdns"
	PageSize             = 25

	TwitterUsername  = "TWITTER_USERNAME"
	TwitterPassword  = "TWITTER_PASSWORD"
	Twitter2FaCode   = "TWITTER_2FA_CODE"
	DiscordBotToken  = "DISCORD_BOT_TOKEN"
	ClaudeApiKey     = "CLAUDE_API_KEY"
	ClaudeApiURL     = "CLAUDE_API_URL"
	ClaudeApiVersion = "CLAUDE_API_VERSION"
	GPTApiKey        = "OPENAI_API_KEY"
	TwitterScraper   = "TWITTER_SCRAPER"
	DiscordScraper   = "DISCORD_SCRAPER"
	WebScraper       = "WEB_SCRAPER"
	LlmServer        = "LLM_SERVER"
	LlmChatUrl       = "LLM_CHAT_URL"
	LlmCfUrl         = "LLM_CF_URL"
)

Variables

View Source
var Models = struct {
	ClaudeSonnet35, ClaudeOpus, ClaudeOpus20240229, ClaudeSonnet, ClaudeHaiku, GPT4, GPT4o, GPT4Turbo, GPT35Turbo, LLama2, LLama3, Mistral, Gemma, Mixtral, OpenChat, NeuralChat, CloudflareQwen15Chat, CloudflareLlama27bChatFp16, CloudflareLlama38bInstruct, CloudflareMistral7bInstruct, CloudflareMistral7bInstructV01, HuggingFaceGoogleGemma7bIt, HuggingFaceNousresearchHermes2ProMistral7b, HuggingFaceTheblokeLlama213bChatAwq, HuggingFaceTheblokeNeuralChat7bV31Awq, CloudflareOpenchat350106, CloudflareMicrosoftPhi2 ModelType
}{
	ClaudeSonnet35:                 ClaudeSonnet35,
	ClaudeOpus:                     ClaudeOpus,
	ClaudeOpus20240229:             ClaudeOpus20240229,
	ClaudeSonnet:                   ClaudeSonnet20240229,
	ClaudeHaiku:                    ClaudeHaiku20240307,
	GPT4:                           GPT4,
	GPT4o:                          GPT4o,
	GPT4Turbo:                      GPT4TurboPreview,
	GPT35Turbo:                     GPT35Turbo,
	LLama2:                         LLama2,
	LLama3:                         LLama3,
	Mistral:                        Mistral,
	Gemma:                          Gemma,
	Mixtral:                        Mixtral,
	OpenChat:                       OpenChat,
	NeuralChat:                     NeuralChat,
	CloudflareQwen15Chat:           CloudflareQwen15Chat,
	CloudflareLlama27bChatFp16:     CloudflareLlama27bChatFp16,
	CloudflareLlama38bInstruct:     CloudflareLlama38bInstruct,
	CloudflareMistral7bInstruct:    CloudflareMistral7bInstruct,
	CloudflareMistral7bInstructV01: CloudflareMistral7bInstructV01,
	HuggingFaceGoogleGemma7bIt:     HuggingFaceGoogleGemma7bIt,
	HuggingFaceNousresearchHermes2ProMistral7b: HuggingFaceNousresearchHermes2ProMistral7b,
	HuggingFaceTheblokeLlama213bChatAwq:        HuggingFaceTheblokeLlama213bChatAwq,
	HuggingFaceTheblokeNeuralChat7bV31Awq:      HuggingFaceTheblokeNeuralChat7bV31Awq,
	CloudflareOpenchat350106:                   CloudflareOpenchat350106,
	CloudflareMicrosoftPhi2:                    CloudflareMicrosoftPhi2,
}

Models holds the available models for easy access and iteration.

Functions

func DisplayWelcomeMessage

func DisplayWelcomeMessage(multiAddr, ipAddr, publicKeyHex string, isStaked bool, isValidator bool, isTwitterScraper bool, isDiscordScraper bool, isWebScraper bool, version string)

func GetCloudflareModels

func GetCloudflareModels() ([]string, error)

Function to call the Cloudflare API and parse the response

func ProtocolWithVersion

func ProtocolWithVersion(protocolName string) protocol.ID

ProtocolWithVersion returns a libp2p protocol ID string with the configured version and environment suffix.

func TopicWithVersion

func TopicWithVersion(protocolName string) string

TopicWithVersion returns a topic string with the configured version and environment suffix.

Types

type AppConfig

type AppConfig struct {
	Version              string   `mapstructure:"version"`
	PortNbr              int      `mapstructure:"portNbr"`
	UDP                  bool     `mapstructure:"udp"`
	TCP                  bool     `mapstructure:"tcp"`
	PrivateKey           string   `mapstructure:"privateKey"`
	Signature            string   `mapstructure:"signature"`
	Bootnodes            []string `mapstructure:"bootnodes"`
	Data                 string   `mapstructure:"data"`
	StakeAmount          string   `mapstructure:"stakeAmount"`
	Debug                bool     `mapstructure:"debug"`
	Environment          string   `mapstructure:"env"`
	PrivateKeyFile       string   `mapstructure:"privateKeyFile"`
	MasaDir              string   `mapstructure:"masaDir"`
	RpcUrl               string   `mapstructure:"rpcUrl"`
	AllowedPeer          bool     `mapstructure:"allowedPeer"`
	AllowedPeerId        string   `mapstructure:"allowedPeerId"`
	AllowedPeerPublicKey string   `mapstructure:"allowedPeerPublicKey"`
	LogLevel             string   `mapstructure:"logLevel"`
	LogFilePath          string   `mapstructure:"logFilePath"`
	FilePath             string   `mapstructure:"filePath"`
	Validator            string   `mapstructure:"validator"`
	CachePath            string   `mapstructure:"cachePath"`
	Faucet               bool     `mapstructure:"faucet"`

	// These may be moved to a separate struct
	TwitterCookiesPath string `mapstructure:"twitterCookiesPath"`
	TwitterUsername    string `mapstructure:"twitterUsername"`
	TwitterPassword    string `mapstructure:"twitterPassword"`
	Twitter2FaCode     string `mapstructure:"twitter2FaCode"`
	DiscordBotToken    string `mapstructure:"discordBotToken"`
	ClaudeApiKey       string `mapstructure:"claudeApiKey"`
	ClaudeApiURL       string `mapstructure:"claudeApiURL"`
	ClaudeApiVersion   string `mapstructure:"claudeApiVersion"`
	GPTApiKey          string `mapstructure:"gptApiKey"`
	TwitterScraper     bool   `mapstructure:"twitterScraper"`
	DiscordScraper     bool   `mapstructure:"discordScraper"`
	WebScraper         bool   `mapstructure:"webScraper"`
	LlmServer          bool   `mapstructure:"llmServer"`
	LLMChatUrl         string `mapstructure:"llmChatUrl"`
	LLMCfUrl           string `mapstructure:"llmCfUrl"`
}

AppConfig represents the configuration settings for the application. It holds various parameters and settings that control the behavior and runtime environment of the application. The fields in this struct are tagged with `mapstructure` to facilitate configuration loading from various sources such as configuration files, environment variables, and command-line flags using the `viper` library.

func GetInstance

func GetInstance() *AppConfig

GetInstance returns the singleton instance of AppConfig.

If the instance has not been initialized yet, GetInstance will initialize it by: 1. Creating a new AppConfig instance. 2. Setting default configuration values. 3. Overriding defaults with values from environment variables. 4. Overriding defaults and environment variables with values from the configuration file. 5. Overriding all previous values with command-line flags. 6. Unmarshalling the configuration into the AppConfig instance.

If the unmarshalling fails, the instance is set to nil.

Subsequent calls to GetInstance will return the same initialized instance.

func (*AppConfig) HasBootnodes

func (c *AppConfig) HasBootnodes() bool

HasBootnodes checks if the AppConfig has any bootnodes configured. It returns true if there is at least one bootnode in the Bootnodes slice and it is not an empty string. Otherwise, it returns false, indicating that no bootnodes are configured.

func (*AppConfig) LogConfig

func (c *AppConfig) LogConfig()

LogConfig logs the non-sensitive parts of the AppConfig. Adjust the fields being logged according to your application's needs.

func (*AppConfig) SetupLogging

func (c *AppConfig) SetupLogging()

SetupLogging configures the logging output for the application. It creates the log directory if needed, opens the log file, sets up a MultiWriter to log to both stdout and the log file, and configures the log level based on the Config.LogLevel field.

type ModelType

type ModelType string

ModelType defines a type for model strings.

const (
	ClaudeSonnet35                             ModelType = "claude-3-5-sonnet-20240620"
	ClaudeOpus                                 ModelType = "claude-3-opus"
	ClaudeOpus20240229                         ModelType = "claude-3-opus-20240229"
	ClaudeSonnet20240229                       ModelType = "claude-3-sonnet-20240229"
	ClaudeHaiku20240307                        ModelType = "claude-3-haiku-20240307"
	GPT4                                       ModelType = "gpt-4"
	GPT4o                                      ModelType = "gpt-4o"
	GPT4TurboPreview                           ModelType = "gpt-4-turbo-preview"
	GPT35Turbo                                 ModelType = "gpt-3.5-turbo"
	LLama2                                     ModelType = "ollama/llama2"
	LLama3                                     ModelType = "ollama/llama3"
	Mistral                                    ModelType = "ollama/mistral"
	Gemma                                      ModelType = "ollama/gemma"
	Mixtral                                    ModelType = "ollama/mixtral"
	OpenChat                                   ModelType = "ollama/openchat"
	NeuralChat                                 ModelType = "ollama/neural-chat"
	CloudflareQwen15Chat                       ModelType = "@cf/qwen/qwen1.5-0.5b-chat"
	CloudflareLlama27bChatFp16                 ModelType = "@cf/meta/llama-2-7b-chat-fp16"
	CloudflareLlama38bInstruct                 ModelType = "@cf/meta/llama-3-8b-instruct"
	CloudflareMistral7bInstruct                ModelType = "@cf/mistral/mistral-7b-instruct"
	CloudflareMistral7bInstructV01             ModelType = "@cf/mistral/mistral-7b-instruct-v0.1"
	HuggingFaceGoogleGemma7bIt                 ModelType = "@hf/google/gemma-7b-it"
	HuggingFaceNousresearchHermes2ProMistral7b ModelType = "@hf/nousresearch/hermes-2-pro-mistral-7b"
	HuggingFaceTheblokeLlama213bChatAwq        ModelType = "@hf/thebloke/llama-2-13b-chat-awq"
	HuggingFaceTheblokeNeuralChat7bV31Awq      ModelType = "@hf/thebloke/neural-chat-7b-v3-1-awq"
	CloudflareOpenchat350106                   ModelType = "@cf/openchat/openchat-3.5-0106"
	CloudflareMicrosoftPhi2                    ModelType = "@cf/microsoft/phi-2"
)

Define model constants.

Jump to

Keyboard shortcuts

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