yptools 1.0.13 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 276c61f364337b2cc8b8722c6060df1a87d5643634d15cf5c84e6e1850492a4d
4
- data.tar.gz: f58da3b69b9931638a8c53a47ef1c0d331006bb1ccb4296ba22a288a6ea7b724
3
+ metadata.gz: f3c5473ec775d2207469ca880a82a6f519c56ec05f47025397427aa2ba829981
4
+ data.tar.gz: 33ae67ab59e2b4ccbb9797f882a34627058de7f01f92f9ad5dca2b71c6b6d021
5
5
  SHA512:
6
- metadata.gz: 42bb09836176c232ffe649f7474618ea0090ffb62ca4119ea788d4b7f8076706bb0aa8063287ca1c93901c76721ad620329b23da8904dd1cdeebd896876951a8
7
- data.tar.gz: 3c0c3fb63c48de64a679cea26e6822cc66015489467daddd0811e6b2c8ce70654a3ab231300090425bc3c6507e632ceaab46a829224824767290fe94a57fe696
6
+ metadata.gz: 865be63f0212e98c8bdec185e608fd1a3191f625ecbd9a2ea1fb1dbbe62024e5f96bea096a326f345e71e9b8eba4667facedc1f39e718d83721f90d33e877146
7
+ data.tar.gz: 76c379471377f5ff4cc8285d1a18491369e1a7ebb5a5673cb37ebe5137b6a39841f235f34ee485098600ba2ecb83c72313ba86421ffe5a9af7efe3c3fae64c31
@@ -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
@@ -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.13
4
+ version: 1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - chenghengsheng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-19 00:00:00.000000000 Z
11
+ date: 2023-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: net/http
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: Some useful tools make me happy
126
140
  email:
127
141
  - 2534550460@qq.com
@@ -134,6 +148,7 @@ files:
134
148
  - lib/yptools.rb
135
149
  - lib/yptools/autocre/yp_autocre.rb
136
150
  - lib/yptools/autocre/yp_autoinit.rb
151
+ - lib/yptools/chatai/yp_chatai.rb
137
152
  - lib/yptools/file/yp_updatecreatedate.rb
138
153
  - lib/yptools/help/yp_help.rb
139
154
  - lib/yptools/install/yp_install.rb