yptools 1.0.13 → 1.0.15
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 +49 -0
- data/lib/yptools/help/yp_help.rb +2 -0
- data/lib/yptools.rb +14 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c441f47e39864bee85572ea544f706e132046da59558541e96fa4c92767a087f
|
4
|
+
data.tar.gz: 7803c926317702d8072b1ff42c7b35beb275caa11b06f99d985be92d4c396c85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52c7d88b1effa8b95c23426df53ea49e6aa65bf4071189c482a833d3b326fe507c4fd1d04357581d64e27ac863ae1598377eceddfbcf944101f940a55fb64b6e
|
7
|
+
data.tar.gz: 3f2595618b09f5965386b9a0ed45c751bd44f07924f6da3c27ada7bc836859eb6da27902a9912b88c1db9d57a13ddb2fa1afa0b4e84c0491979549cd2f4f8240
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../log/yp_log'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class YPChatAI
|
6
|
+
|
7
|
+
def self.message(message)
|
8
|
+
yp_log_doing "你的问题:#{message}"
|
9
|
+
yp_log_msg "请求中,请等待..."
|
10
|
+
yp_chataiURL = 'https://api.openai.com/v1/completions'
|
11
|
+
|
12
|
+
# 开始发送网络请求
|
13
|
+
url = URI.parse(yp_chataiURL)
|
14
|
+
http = Net::HTTP.new(url.host, url.port)
|
15
|
+
http.use_ssl = true
|
16
|
+
# 设置请求头
|
17
|
+
headers = {
|
18
|
+
'Content-Type' => 'application/json',
|
19
|
+
'Authorization' => 'Bearer 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'
|
20
|
+
}
|
21
|
+
# 设置请body
|
22
|
+
data = {
|
23
|
+
'model' => 'text-davinci-003', # 然后GPT-3模型会根据您的输入文本自动生成文本补全或摘要。
|
24
|
+
'prompt' => message, # 问的问题
|
25
|
+
'max_tokens' => 999, # 设置回答最多多少个字符
|
26
|
+
'temperature' => 0.9, # 文本创意度,默认 1
|
27
|
+
}
|
28
|
+
|
29
|
+
request = Net::HTTP::Post.new(url.path, headers)
|
30
|
+
request.body = data.to_json
|
31
|
+
response = http.request(request)
|
32
|
+
|
33
|
+
yp_message_response = JSON(response.body)
|
34
|
+
if !yp_message_response["error"]
|
35
|
+
created = yp_message_response["created"]
|
36
|
+
choices = yp_message_response["choices"]
|
37
|
+
if !choices.empty?
|
38
|
+
text = choices.first["text"]
|
39
|
+
yp_log_success "chatGPT:" + text.gsub(/\n+/, "\n")
|
40
|
+
else
|
41
|
+
yp_log_fail "请求失败," + yp_message_response
|
42
|
+
end
|
43
|
+
else
|
44
|
+
message = yp_message_response["error"]["message"]
|
45
|
+
yp_log_fail "请求失败,请稍后再试!!!\n" + message
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/lib/yptools/help/yp_help.rb
CHANGED
@@ -3,6 +3,8 @@ class YPHelp
|
|
3
3
|
def self.message
|
4
4
|
puts %q{
|
5
5
|
|
6
|
+
chatai: use [yptools chatai ...] 快速与 chatgpt 沟通(科学上网)
|
7
|
+
|
6
8
|
autocre: use [yptools autocre ...] 自动化工具命令
|
7
9
|
use [yptools autocre -objc ...] 根据 json 自动创建 Objective-C 数据库操作文件 .h|.m 文件。(依赖三方库 FMDB )
|
8
10
|
use [yptools autocre -init] 构建数据库操作文件的json模板
|
data/lib/yptools.rb
CHANGED
@@ -10,12 +10,22 @@ require_relative 'yptools/file/yp_updatecreatedate'
|
|
10
10
|
require_relative 'yptools/package/yp_package'
|
11
11
|
require_relative 'yptools/autocre/yp_autocre'
|
12
12
|
require_relative 'yptools/autocre/yp_autoinit'
|
13
|
+
require_relative 'yptools/chatai/yp_chatai'
|
13
14
|
|
14
15
|
class YPTools
|
15
16
|
|
16
17
|
def self.cmd_dispatch(argvs)
|
17
18
|
cmd = argvs[0]
|
18
19
|
case cmd
|
20
|
+
|
21
|
+
when 'chatai'
|
22
|
+
if argvs.size > 1
|
23
|
+
name = argvs[1]
|
24
|
+
self.chatai name
|
25
|
+
else
|
26
|
+
yp_log_fail "'yptools chatai ..' 参数缺失"
|
27
|
+
self.help
|
28
|
+
end
|
19
29
|
when 'autocre'
|
20
30
|
if argvs.size > 1
|
21
31
|
name = argvs[1]
|
@@ -94,6 +104,10 @@ class YPTools
|
|
94
104
|
YPHelp.message
|
95
105
|
end
|
96
106
|
|
107
|
+
def self.chatai(message)
|
108
|
+
YPChatAI.message(message)
|
109
|
+
end
|
110
|
+
|
97
111
|
def self.ufct
|
98
112
|
path = `pwd`
|
99
113
|
path = path.sub("\n","")
|
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.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chenghengsheng
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/yptools.rb
|
135
135
|
- lib/yptools/autocre/yp_autocre.rb
|
136
136
|
- lib/yptools/autocre/yp_autoinit.rb
|
137
|
+
- lib/yptools/chatai/yp_chatai.rb
|
137
138
|
- lib/yptools/file/yp_updatecreatedate.rb
|
138
139
|
- lib/yptools/help/yp_help.rb
|
139
140
|
- lib/yptools/install/yp_install.rb
|