yptools 1.0.17 → 1.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yptools/chatai/yp_chatai.rb +59 -0
- data/lib/yptools/help/yp_help.rb +3 -2
- data/lib/yptools.rb +14 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b0c0ac65980ab31a4c668af14aea11d9c2d7ab7dcf0b8c20b072c797b0bea35
|
4
|
+
data.tar.gz: 7451143c8b5d160ff9176532a2570cfef65461e5f78dfa25f0b3627f28bf3653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6664fa97f413646ca8926eef8df0d4a227e46b87af6f87ed53b96b0900e5596931fbc3f1cafb2e4bb4afccc1cbaefdd9c6e54788afeaf5c0e48c93314f603445
|
7
|
+
data.tar.gz: 05036757b34371ad309a41e42b8d2835720571aea0063efeff899dda29d163960c8a4adf6b99a9960aa1800abd04d750a2670ca9b311381001e375f213651c9e
|
@@ -115,4 +115,63 @@ class YPChatAI
|
|
115
115
|
yp_log_success "chatGPT:" + yp_answer.gsub(/\n+/, "\n")
|
116
116
|
end
|
117
117
|
|
118
|
+
def self.openaiimg(message)
|
119
|
+
yp_chataiURL = 'https://api.openai.com/v1/images/generations'
|
120
|
+
# 开始发送网络请求
|
121
|
+
url = URI.parse(yp_chataiURL)
|
122
|
+
http = Net::HTTP.new(url.host, url.port)
|
123
|
+
http.use_ssl = true
|
124
|
+
# 简单了加了下密,免费的apikey,就不要扒去用了(我的代码是开源放到GitHub,加密的目的是ChatGPT会检测秘钥是否在网络泄露)
|
125
|
+
yp_token = "c2stTVRVMVZqeUdpNWxzYlU1TmNlU1pUM0JsYmtGSmNYam5iUk5ROENVYUd2QVR4WXpp"
|
126
|
+
# 将Base64字符串解码为原始二进制数据
|
127
|
+
decoded_data = Base64.decode64(yp_token).force_encoding("UTF-8")
|
128
|
+
# 设置请求头
|
129
|
+
headers = {
|
130
|
+
'Content-Type' => 'application/json',
|
131
|
+
'Authorization' => 'Bearer ' + decoded_data
|
132
|
+
}
|
133
|
+
# 设置ai根据上下文
|
134
|
+
question = message
|
135
|
+
|
136
|
+
# 设置请body
|
137
|
+
data = {
|
138
|
+
# 'model' => 'text-davinci-003', # 然后GPT-3模型会根据您的输入文本自动生成文本补全或摘要。
|
139
|
+
'prompt' => question, # 问的问题
|
140
|
+
"n": 3, #几个回答
|
141
|
+
"size": "512x512"
|
142
|
+
}
|
143
|
+
|
144
|
+
request = Net::HTTP::Post.new(url.path, headers)
|
145
|
+
request.body = data.to_json
|
146
|
+
|
147
|
+
begin
|
148
|
+
response = http.request(request)
|
149
|
+
# 处理响应数据
|
150
|
+
yp_message_response = JSON(response.body)
|
151
|
+
if !yp_message_response["error"]
|
152
|
+
created = yp_message_response["created"]
|
153
|
+
data = yp_message_response["data"]
|
154
|
+
puts ""
|
155
|
+
if !data.empty?
|
156
|
+
index = 1
|
157
|
+
for item in data
|
158
|
+
yp_log_success "图#{index} 【复制下面链接到浏览器打开或者 command + 鼠标左键快速打开 】"
|
159
|
+
yp_log_msg item["url"]
|
160
|
+
index = index + 1
|
161
|
+
puts ""
|
162
|
+
end
|
163
|
+
else
|
164
|
+
yp_log_fail "请求失败," + yp_message_response
|
165
|
+
end
|
166
|
+
else
|
167
|
+
message = yp_message_response["error"]["message"]
|
168
|
+
yp_log_fail "请求失败,请稍后再试!!!\n" + message
|
169
|
+
end
|
170
|
+
rescue StandardError => e
|
171
|
+
# 处理异常
|
172
|
+
yp_log_fail "请求的次数太多了,请稍后再试!!!"
|
173
|
+
yp_log_fail "发生异常:#{e.message}"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
118
177
|
end
|
data/lib/yptools/help/yp_help.rb
CHANGED
@@ -3,8 +3,9 @@ class YPHelp
|
|
3
3
|
def self.message
|
4
4
|
puts %q{
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
chatgpt: use [yptools chatgpt] 创建会话列表与 chatgpt 聊天,会记录上下内容(科学上网)
|
7
|
+
[yptools chatgpt ...] 快速与 chatgpt 沟通,不会记录上下内容
|
8
|
+
openai: use [yptools openaiimg ...] 根据文本描述生成图像(eg: yptools openaiimg '高冷 少妇 黑丝 短裤 真人照片' )
|
8
9
|
|
9
10
|
autocre: use [yptools autocre ...] 自动化工具命令
|
10
11
|
use [yptools autocre -objc ...] 根据 json 自动创建 Objective-C 数据库操作文件 .h|.m 文件。(依赖三方库 FMDB )
|
data/lib/yptools.rb
CHANGED
@@ -18,13 +18,22 @@ class YPTools
|
|
18
18
|
cmd = argvs[0]
|
19
19
|
case cmd
|
20
20
|
|
21
|
-
when '
|
21
|
+
when 'chatgpt'
|
22
22
|
if argvs.size > 1
|
23
23
|
name = argvs[1]
|
24
24
|
self.chatai name
|
25
25
|
else
|
26
26
|
self.startChat
|
27
27
|
end
|
28
|
+
when 'openaiimg'
|
29
|
+
if argvs.size > 1
|
30
|
+
name = argvs[1..-1]
|
31
|
+
name = name.join(' ')
|
32
|
+
self.openaiimg name
|
33
|
+
else
|
34
|
+
yp_log_fail "'yptools openaiimg ..' 参数缺失"
|
35
|
+
self.help
|
36
|
+
end
|
28
37
|
when 'autocre'
|
29
38
|
if argvs.size > 1
|
30
39
|
name = argvs[1]
|
@@ -144,6 +153,10 @@ class YPTools
|
|
144
153
|
def self.startChat
|
145
154
|
YPChatAI.startChatAI()
|
146
155
|
end
|
156
|
+
|
157
|
+
def self.openaiimg(message)
|
158
|
+
YPChatAI.openaiimg(message)
|
159
|
+
end
|
147
160
|
|
148
161
|
end
|
149
162
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yptools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chenghengsheng
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|