util

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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 ClearConsole

func ClearConsole()

ClearConsole clears the console screen

func FindAvailablePort

func FindAvailablePort(startPort int) int

FindAvailablePort finds an available port starting from the given port

func GenerateRandomDigits added in v0.1.5

func GenerateRandomDigits(length int) string

GenerateRandomDigits generates a string of random digits with the specified length

func GenerateRandomString added in v0.1.5

func GenerateRandomString(length int) string

GenerateRandomString generates a random string with the specified length

func GetPlatformInfo

func GetPlatformInfo(userAgent string, ip string, cidr []string) string

GetPlatformInfo extracts platform information from User-Agent

func IsIPInCidr added in v0.1.5

func IsIPInCidr(ip string, cidr string) bool

func IsPortAvailable

func IsPortAvailable(port int) bool

IsPortAvailable checks if a port is available

func Min

func Min(a, b int) int

Min returns the minimum of two integers

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

type ColorInfo struct {
	Color       color.RGBA
	Name        string
	ChineseName string
}

ColorInfo represents a basic color with its name

func GenerateRandomImage

func GenerateRandomImage(width, height int) (image.Image, []ColorInfo)

GenerateRandomImage creates a random colored image with a pattern

func GetRandomUniqueColors

func GetRandomUniqueColors(n int) []ColorInfo

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

func GetIPInfo

func GetIPInfo(ip string) (*IPInfo, error)

GetIPInfo retrieves location and ISP information for an IP address

type ImageURL

type ImageURL struct {
	URL    string `json:"url"`
	Detail string `json:"detail,omitempty"`
}

ImageURL represents an image URL

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

Jump to

Keyboard shortcuts

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