Documentation ¶
Index ¶
- Constants
- Variables
- func ChatRequest(ctx context.Context, url, key, model, imageURL string, maxTokens int, ...) (string, error)
- 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 IsIPInCidr(ip string, cidr string) bool
- func IsPortAvailable(port int) bool
- func Min(a, b int) int
- type Choice
- type ColorInfo
- type IPInfo
- type ImageURL
- type Message
- type MessageContent
- type Request
- type Response
- type StreamChoice
- type StreamResponse
Constants ¶
const ( ColorReset = "\033[0m" ColorRed = "\033[31m" ColorGreen = "\033[32m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" ColorPurple = "\033[35m" ColorCyan = "\033[36m" ColorGray = "\033[37m" )
ANSI color codes
Variables ¶
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 ChatRequest ¶
func ChatRequest(ctx context.Context, url, key, model, imageURL string, maxTokens int, useStream bool) (string, error)
ChatRequest sends a chat request to the API and returns the response
func FindAvailablePort ¶
FindAvailablePort finds an available port starting from the given port
func GenerateRandomDigits ¶ added in v0.1.5
GenerateRandomDigits generates a string of random digits with the specified length
func GenerateRandomString ¶ added in v0.1.5
GenerateRandomString generates a random string with the specified length
func GetPlatformInfo ¶
GetPlatformInfo extracts platform information from User-Agent
func IsIPInCidr ¶ added in v0.1.5
func IsPortAvailable ¶
IsPortAvailable checks if a port is available
Types ¶
type Choice ¶ added in v0.1.2
type Choice struct { Message struct { Content string `json:"content"` } `json:"message"` }
Choice represents a response choice
type ColorInfo ¶
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 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 Message ¶ added in v0.1.2
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 Request ¶ added in v0.1.2
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 ¶ added in v0.1.2
type Response struct {
Choices []Choice `json:"choices"`
}
Response represents a chat response
type StreamChoice ¶ added in v0.1.2
type StreamChoice struct { Delta struct { Content string `json:"content"` } `json:"delta"` }
StreamChoice represents a streaming choice
type StreamResponse ¶ added in v0.1.2
type StreamResponse struct {
Choices []StreamChoice `json:"choices"`
}
StreamResponse represents a streaming response