yptools 1.0.17 → 1.1.0
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 +4 -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: 98dd6d1d9b7cc1c72d121fce68e65a6d035ebef4bab15b3fd18c0b550c2e23ec
|
4
|
+
data.tar.gz: 3ddc62e82485cf62bf760a091b73d96769616e45d52de26cf98de7ca2eeb45e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3138ef32c117ca0c53f553fe0b1a95500369fcc186e1a60a569980e1efcaeae041de2c95f4324906162e8d6f780f450df3358f998261aa0f158f004ee740a58
|
7
|
+
data.tar.gz: 0cc0a0b57eb2c8ee090c1f7501342948457397fbc72f91a14d9919dcd09a0a9c80d23a7b64007b026c354db6ff7e76f17d0f5f4d3fe882afce98edf1208f4a7e
|
@@ -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,10 @@ 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
|
+
|
9
|
+
openai: use [yptools openaiimg ...] 根据文本描述生成图像(eg: yptools openaiimg '老虎和狮子大战' )
|
8
10
|
|
9
11
|
autocre: use [yptools autocre ...] 自动化工具命令
|
10
12
|
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.1.0
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|