Class: EasyAI::Command::GPT
Constant Summary
DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS
Instance Attribute Summary
#args_help_flag
Class Method Summary
collapse
Instance Method Summary
collapse
run
Constructor Details
#initialize(argv) ⇒ GPT
Returns a new instance of GPT.
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/easyai/command/gpt.rb', line 45
def initialize(argv)
@no_keychain = argv.flag?('no-keychain')
@verbose_mode = argv.flag?('verbose')
super
remaining_args = @argv.remainder!
if remaining_args.first && File.exist?(remaining_args.first) && remaining_args.first.end_with?('.json')
@config_file = remaining_args.shift
end
@gpt_args = remaining_args
end
|
Class Method Details
.options ⇒ Object
38
39
40
41
42
43
|
# File 'lib/easyai/command/gpt.rb', line 38
def self.options
[
['--no-keychain', '禁用自动密码存储'],
['--verbose', '显示详细信息']
].concat(super)
end
|
Instance Method Details
#run ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/easyai/command/gpt.rb', line 68
def run
begin
remote_config = nil
if @config_file
print_status("📁 使用本地配置", File.basename(@config_file))
remote_config = load_local_config(@config_file)
print_success("配置加载成功") if remote_config
else
print_status("🔄 获取远程配置", "默认用户")
options = {
no_keychain: @no_keychain,
verbose: @verbose_mode,
tool_type: "gpt" }
remote_config = ConfigManager.download_user_config(nil, options)
if remote_config == :user_cancelled
print_error("用户取消了授权登录")
exit 0
end
print_success("配置加载成功") if remote_config
end
if remote_config.nil?
print_warning("使用本地配置")
remote_config = load_local_yaml_config
if remote_config.empty?
print_error("未找到有效配置")
puts " 请先运行: #{'easyai --setup'.yellow}"
exit 1
end
end
env = build_environment(remote_config)
print_status("🚀 启动 OpenAI", "openai #{@gpt_args.join(' ')}")
exec(env, 'openai', *@gpt_args)
rescue Interrupt
puts "\n已取消"
exit 0
rescue => e
print_error("运行失败: #{e.message}")
puts e.backtrace if @verbose_mode
exit 1
end
end
|
#validate! ⇒ Object
63
64
65
66
|
# File 'lib/easyai/command/gpt.rb', line 63
def validate!
super
help! '未找到 OpenAI CLI。请安装:pip install openai' unless gpt_available?
end
|