update
This commit is contained in:
10
.idea/.gitignore
generated
vendored
Normal file
10
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# 依赖于环境的 Maven 主目录路径
|
||||||
|
/mavenHomeManager.xml
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/vision-tool.iml" filepath="$PROJECT_DIR$/.idea/vision-tool.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
7
.idea/vcs.xml
generated
Normal file
7
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
10
.idea/vision-tool.iml
generated
Normal file
10
.idea/vision-tool.iml
generated
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
38
config.go
38
config.go
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -13,7 +12,7 @@ type Config struct {
|
|||||||
APIKey string `json:"api_key"`
|
APIKey string `json:"api_key"`
|
||||||
Model string `json:"model"`
|
Model string `json:"model"`
|
||||||
BaseURL string `json:"base_url"`
|
BaseURL string `json:"base_url"`
|
||||||
Provider string `json:"provider"` // "agnes" or "zhipu" or "custom"
|
Provider string `json:"provider"` // "agnes"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provider presets
|
// Provider presets
|
||||||
@@ -25,18 +24,18 @@ var providerPresets = map[string]struct {
|
|||||||
Model: "agnes-2.0-flash",
|
Model: "agnes-2.0-flash",
|
||||||
BaseURL: "https://apihub.agnes-ai.com/v1/chat/completions",
|
BaseURL: "https://apihub.agnes-ai.com/v1/chat/completions",
|
||||||
},
|
},
|
||||||
"zhipu": {
|
|
||||||
Model: "glm-4.6v-flash",
|
|
||||||
BaseURL: "https://open.bigmodel.cn/api/paas/v4/chat/completions",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hardcoded API key
|
||||||
|
const hardcodedAPIKey = "sk-68FL9xXRrJhxcY5TCGxoaFlQ94oCBioIJhyGfeDMCkCvA0SV"
|
||||||
|
|
||||||
// DefaultConfig returns a Config with sensible defaults (Agnes AI).
|
// DefaultConfig returns a Config with sensible defaults (Agnes AI).
|
||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Provider: "agnes",
|
Provider: "agnes",
|
||||||
Model: "agnes-2.0-flash",
|
Model: "agnes-2.0-flash",
|
||||||
BaseURL: "https://apihub.agnes-ai.com/v1/chat/completions",
|
BaseURL: "https://apihub.agnes-ai.com/v1/chat/completions",
|
||||||
|
APIKey: hardcodedAPIKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,26 +43,24 @@ func DefaultConfig() *Config {
|
|||||||
func (c *Config) ApplyProvider(provider string) {
|
func (c *Config) ApplyProvider(provider string) {
|
||||||
if preset, ok := providerPresets[provider]; ok {
|
if preset, ok := providerPresets[provider]; ok {
|
||||||
c.Provider = provider
|
c.Provider = provider
|
||||||
// Only override model/baseURL if user hasn't set custom ones
|
if c.Model == "" || c.Model == "agnes-2.0-flash" {
|
||||||
if c.Model == "" || c.Model == "agnes-2.0-flash" || c.Model == "glm-4.6v-flash" {
|
|
||||||
c.Model = preset.Model
|
c.Model = preset.Model
|
||||||
}
|
}
|
||||||
if c.BaseURL == "" || c.BaseURL == "https://apihub.agnes-ai.com/v1/chat/completions" ||
|
if c.BaseURL == "" || c.BaseURL == "https://apihub.agnes-ai.com/v1/chat/completions" {
|
||||||
c.BaseURL == "https://open.bigmodel.cn/api/paas/v4/chat/completions" {
|
|
||||||
c.BaseURL = preset.BaseURL
|
c.BaseURL = preset.BaseURL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadConfig loads configuration from multiple sources in priority order:
|
// LoadConfig loads configuration from multiple sources in priority order:
|
||||||
// 1. Command-line --apikey flag (highest)
|
// 1. Command-line --apikey flag (highest)
|
||||||
// 2. ZHIPU_API_KEY environment variable
|
// 2. AGNES_API_KEY environment variable
|
||||||
// 3. config.json in the same directory as the executable
|
// 3. config.json in the same directory as the executable
|
||||||
// 4. Default built-in key (lowest)
|
// 4. Hardcoded default key (lowest)
|
||||||
func LoadConfig(flagKey, configPath string) (*Config, error) {
|
func LoadConfig(flagKey, configPath string) (*Config, error) {
|
||||||
cfg := DefaultConfig()
|
cfg := DefaultConfig()
|
||||||
|
|
||||||
// Load from config file if it exists (lowest priority)
|
// Load from config file if it exists
|
||||||
if configPath == "" {
|
if configPath == "" {
|
||||||
execDir := getExecDir()
|
execDir := getExecDir()
|
||||||
configPath = filepath.Join(execDir, "config.json")
|
configPath = filepath.Join(execDir, "config.json")
|
||||||
@@ -88,22 +85,13 @@ func LoadConfig(flagKey, configPath string) (*Config, error) {
|
|||||||
if envKey := os.Getenv("AGNES_API_KEY"); envKey != "" {
|
if envKey := os.Getenv("AGNES_API_KEY"); envKey != "" {
|
||||||
cfg.APIKey = envKey
|
cfg.APIKey = envKey
|
||||||
}
|
}
|
||||||
if envKey := os.Getenv("ZHIPU_API_KEY"); envKey != "" {
|
|
||||||
cfg.APIKey = envKey
|
|
||||||
}
|
|
||||||
|
|
||||||
// Highest priority: command-line flag
|
// Highest priority: command-line flag
|
||||||
if flagKey != "" {
|
if flagKey != "" {
|
||||||
cfg.APIKey = flagKey
|
cfg.APIKey = flagKey
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.APIKey == "" {
|
// API key is always available thanks to hardcoded default
|
||||||
return cfg, fmt.Errorf("API key not configured. Set it via:\n" +
|
|
||||||
" 1. --apikey flag\n" +
|
|
||||||
" 2. AGNES_API_KEY environment variable\n" +
|
|
||||||
" 3. config.json file in the tools directory")
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
main.go
3
main.go
@@ -24,7 +24,7 @@ func main() {
|
|||||||
flag.BoolVar(&quiet, "q", false, "Quiet mode — only output the model's response text")
|
flag.BoolVar(&quiet, "q", false, "Quiet mode — only output the model's response text")
|
||||||
flag.BoolVar(&noThink, "no-think", false, "Disable thinking mode (faster, lower server load)")
|
flag.BoolVar(&noThink, "no-think", false, "Disable thinking mode (faster, lower server load)")
|
||||||
flag.BoolVar(&saveConfig, "save-config", false, "Save the API key to config.json and exit")
|
flag.BoolVar(&saveConfig, "save-config", false, "Save the API key to config.json and exit")
|
||||||
provider := flag.String("provider", "agnes", "AI provider: agnes (default), zhipu, or custom")
|
provider := flag.String("provider", "agnes", "AI provider: agnes (default)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Handle --save-config: persist the key and exit
|
// Handle --save-config: persist the key and exit
|
||||||
@@ -71,7 +71,6 @@ func main() {
|
|||||||
fmt.Fprintln(os.Stderr, " vision-tool photo.jpg")
|
fmt.Fprintln(os.Stderr, " vision-tool photo.jpg")
|
||||||
fmt.Fprintln(os.Stderr, ` vision-tool -prompt "这张图里有什么文字?" screenshot.png`)
|
fmt.Fprintln(os.Stderr, ` vision-tool -prompt "这张图里有什么文字?" screenshot.png`)
|
||||||
fmt.Fprintln(os.Stderr, " vision-tool -q img1.png img2.png")
|
fmt.Fprintln(os.Stderr, " vision-tool -q img1.png img2.png")
|
||||||
fmt.Fprintln(os.Stderr, " vision-tool --provider zhipu photo.jpg")
|
|
||||||
fmt.Fprintln(os.Stderr, " vision-tool --apikey YOUR_KEY photo.jpg")
|
fmt.Fprintln(os.Stderr, " vision-tool --apikey YOUR_KEY photo.jpg")
|
||||||
fmt.Fprintln(os.Stderr, " vision-tool --save-config --apikey YOUR_KEY")
|
fmt.Fprintln(os.Stderr, " vision-tool --save-config --apikey YOUR_KEY")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user