Documentation
¶
Index ¶
- Constants
- Variables
- func ClearConsole()
- func FindAvailablePort(startPort int) int
- func GenerateRandomDigits(length int) string
- func GenerateRandomString(length int) string
- func GetPlatformInfo(userAgent string, ip string, cidr []string) string
- func GetSeparator() string
- func IsIPInCidr(ip string, cidr string) bool
- func IsPortAvailable(port int) bool
- func IsValidURL(input string) bool
- func MaskKey(key string, firstN, lastN int) string
- func MaskString(s string) string
- func Min(a, b int) int
- func NormalizeURL(url string) string
- type APIResponse
- type AddressInfo
- type AddressType
- type ChatResponse
- type Choice
- type Client
- type ColorInfo
- type ErrorResponse
- type IPInfo
- type ImageURL
- type Menu
- type MenuItem
- type Message
- type MessageContent
- type Printer
- func (p *Printer) FormatTitle(title string, emoji string) string
- func (p *Printer) Print(args ...interface{})
- func (p *Printer) PrintError(message string)
- func (p *Printer) PrintSeparator()
- func (p *Printer) PrintSuccess(message string)
- func (p *Printer) PrintTesting()
- func (p *Printer) PrintTitle(title string, emoji string)
- func (p *Printer) PrintWarning(message string)
- func (p *Printer) Printf(format string, args ...interface{})
- func (p *Printer) Println(args ...interface{})
- type Request
- type Response
- type StreamChoice
- type StreamResponse
Constants ¶
const ( EmojiDefault = "⭐" EmojiCustom = "✏️" EmojiOpenAI = "🤖" EmojiExit = "👋" EmojiTool = "🛠️" EmojiUpdate = "🚀" EmojiBack = "🔙" )
Menu-specific emojis
const ( ColorReset = "\033[0m" ColorRed = "\033[31m" ColorGreen = "\033[32m" ColorYellow = "\033[33m" ColorBlue = "\033[36m" ColorGray = "\033[90m" ColorBold = "\033[1m" ColorLightBlue = "\033[94m" )
Colors
const ( EmojiRocket = "🚀" EmojiStar = "⭐" EmojiError = "❌" EmojiCheck = "✅" EmojiKey = "🔑" EmojiGear = "⚙️" EmojiLink = "🔗" EmojiWave = "👋" EmojiWarning = "⚠️" EmojiAPI = "🔍" EmojiDone = "🎯" EmojiSelect = "🔘" // emoji for loading EmojiLoading = "🌐" EmojiCongratulation = "🎉" EmojiDiamond = "💎" )
Emojis
const ( SeparatorChar = "-" SeparatorWidth = 80 )
Common formatting
Variables ¶
var ( MainMenu = Menu{ Title: "GPT 检测工具", TitleEmoji: EmojiTool, } MenuKey = Menu{ Title: "请选择测试模型", TitleEmoji: EmojiGear, Items: []MenuItem{ {ID: 1, Label: "使用默认模型", Emoji: EmojiDefault}, {ID: 2, Label: "自定义测试模型", Emoji: EmojiCustom}, }, Prompt: "请输入选择或输入自定义模型(多个模型用空格分隔): ", ValidChoice: func(choice string) bool { return choice == "1" || choice == "2" || strings.Contains(choice, " ") }, } MenuMain = Menu{ Title: "GPT 检测工具", TitleEmoji: EmojiTool, Description: fmt.Sprintf("%s项目地址: %shttps://github.com/go-coders/check-gpt%s", ColorGray, ColorBlue, ColorReset), Items: []MenuItem{ {ID: 1, Label: "API Key 可用性测试", Emoji: EmojiKey}, {ID: 2, Label: "API 中转链路检测", Emoji: EmojiLink}, {ID: 3, Label: "检查更新", Emoji: EmojiGear}, {ID: 4, Label: "退出", Emoji: EmojiExit}, }, Prompt: "请选择功能 (1-4): ", ValidChoice: func(choice string) bool { return choice >= "1" && choice <= "4" }, } MenuUpdate = Menu{ Title: "检查更新", TitleEmoji: EmojiGear, Items: []MenuItem{ {ID: 1, Label: "立即更新", Emoji: EmojiUpdate}, {ID: 2, Label: "返回主菜单", Emoji: EmojiBack}, }, Prompt: "请选择操作: ", ValidChoice: func(choice string) bool { return choice == "1" || choice == "2" }, } )
Menu constants
var BasicColors = []ColorInfo{ {Color: color.RGBA{R: 255, G: 0, B: 0, A: 255}, Name: "Red", ChineseName: "红色"}, {Color: color.RGBA{R: 0, G: 255, B: 0, A: 255}, Name: "Green", ChineseName: "绿色"}, {Color: color.RGBA{R: 0, G: 0, B: 255, A: 255}, Name: "Blue", ChineseName: "蓝色"}, {Color: color.RGBA{R: 255, G: 255, B: 0, A: 255}, Name: "Yellow", ChineseName: "黄色"}, {Color: color.RGBA{R: 255, G: 0, B: 255, A: 255}, Name: "Magenta", ChineseName: "品红色"}, {Color: color.RGBA{R: 0, G: 255, B: 255, A: 255}, Name: "Cyan", ChineseName: "青色"}, {Color: color.RGBA{R: 255, G: 165, B: 0, A: 255}, Name: "Orange", ChineseName: "橙色"}, {Color: color.RGBA{R: 128, G: 0, B: 128, A: 255}, Name: "Purple", ChineseName: "紫色"}, {Color: color.RGBA{R: 165, G: 42, B: 42, A: 255}, Name: "Brown", ChineseName: "棕色"}, }
BasicColors provides a list of basic colors with their names
Functions ¶
func ClearConsole ¶
func ClearConsole()
func FindAvailablePort ¶
FindAvailablePort finds an available port starting from the given port
func GenerateRandomDigits ¶
GenerateRandomDigits generates a string of random digits with the specified length
func GenerateRandomString ¶
GenerateRandomString generates a random string with the specified length
func GetPlatformInfo ¶
GetPlatformInfo extracts platform information from User-Agent
func GetSeparator ¶
func GetSeparator() string
GetSeparator returns a separator line of standard width
func IsIPInCidr ¶
func IsPortAvailable ¶
IsPortAvailable checks if a port is available
func IsValidURL ¶
func MaskString ¶
MaskString masks a string by showing only the first and last few characters
func NormalizeURL ¶
normalizeURL ensures the URL ends with /v1/chat/completions for OpenAI-compatible APIs
Types ¶
type APIResponse ¶
APIResponse represents an API response
type AddressInfo ¶
type AddressInfo struct { Original string // 原始输入 Type AddressType // 地址类型 Scheme string // 协议 (http/https) Host string // 主机部分 Port string // 端口 IsValid bool // 是否有效 ErrorDetail string // 错误详情 }
AddressInfo 存储地址解析结果
type AddressType ¶
type AddressType int
AddressType 表示地址类型
const ( InvalidAddress AddressType = iota IPv4Address IPv6Address DomainAddress LocalhostAddress )
func (AddressType) String ¶
func (t AddressType) String() string
type ChatResponse ¶
type ChatResponse struct { Choices []struct { Message struct { Content string `json:"content"` } `json:"message"` Delta struct { Content string `json:"content"` } `json:"delta"` } `json:"choices"` }
ChatResponse represents a chat completion response
type Choice ¶
type Choice struct { Message struct { Content string `json:"content"` } `json:"message"` }
Choice represents a response choice
type Client ¶
Client represents an API client
func (*Client) ChatRequest ¶
func (c *Client) ChatRequest(ctx context.Context, contxt string, url, imageURL, key, model string) *APIResponse
ChatRequest sends a chat request to the API and returns the response
type ColorInfo ¶
ColorInfo represents a basic color with its name ColorInfo represents a basic color with its name
func GenerateRandomImage ¶
GenerateRandomImage creates a random colored image with a pattern
func GetRandomUniqueColors ¶
GetRandomUniqueColors returns n unique random colors from the basic colors
type ErrorResponse ¶
type ErrorResponse struct { Error struct { Message string `json:"message"` Type string `json:"type"` Code string `json:"code"` } `json:"error"` }
ErrorResponse represents an API error response
type IPInfo ¶
type IPInfo struct { Status string `json:"status"` Country string `json:"country"` RegionName string `json:"regionName"` City string `json:"city"` ISP string `json:"isp"` Query string `json:"query"` Org string `json:"org"` }
IPInfo represents the response from IP-API
type Menu ¶
type Menu struct { Title string TitleEmoji string Description string Items []MenuItem Prompt string ValidChoice func(string) bool }
Menu represents a menu with title and items
type MenuItem ¶
MenuItem represents a menu item
func ShowMainMenu ¶
ShowMainMenu displays the main menu and returns the user's choice
type Message ¶
type Message struct { Role string `json:"role"` Content []MessageContent `json:"content"` }
Message represents a chat message
type MessageContent ¶
type MessageContent struct { Type string `json:"type"` Text string `json:"text,omitempty"` ImageURL *ImageURL `json:"image_url,omitempty"` }
MessageContent represents the content of a message
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer handles output formatting with configurable writer
func NewPrinter ¶
NewPrinter creates a new Printer with the given writer
func (*Printer) FormatTitle ¶
FormatTitle formats a title with an emoji
func (*Printer) PrintError ¶
PrintError prints an error message
func (*Printer) PrintSeparator ¶
func (p *Printer) PrintSeparator()
PrintSeparator prints a separator line
func (*Printer) PrintSuccess ¶
PrintSuccess prints a success message
func (*Printer) PrintTesting ¶
func (p *Printer) PrintTesting()
func (*Printer) PrintTitle ¶
PrintTitle prints a title with an emoji and separator
func (*Printer) PrintWarning ¶
PrintWarning prints a warning message
type Request ¶
type Request struct { Model string `json:"model"` Messages []Message `json:"messages"` MaxTokens int `json:"max_tokens"` Stream bool `json:"stream"` Temperature float64 `json:"temperature"` }
Request represents a chat request
type Response ¶
type Response struct {
Choices []Choice `json:"choices"`
}
Response represents a chat response
type StreamChoice ¶
type StreamChoice struct { Delta struct { Content string `json:"content"` } `json:"delta"` }
StreamChoice represents a streaming choice
type StreamResponse ¶
type StreamResponse struct {
Choices []StreamChoice `json:"choices"`
}
StreamResponse represents a streaming response