geekdict 0.0.6 → 0.1.0

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
- SHA1:
3
- metadata.gz: 952461255f9764ffca6126ca2a9b615254766635
4
- data.tar.gz: e10a7a202e547f70a4b2ad9558c5d0b2690c2de8
2
+ SHA256:
3
+ metadata.gz: 90e371d728887d96bd825b2e512e8a3ba093c49c6cdb788474f899bba185f1ae
4
+ data.tar.gz: 79362e55a2fb8d5012f2801c7bc7efd96d8cdcbda5a780eff92329a6f33deeb3
5
5
  SHA512:
6
- metadata.gz: f36218d7a3c6347e8d698f5797e075fea62dd451606c80bd35d01dc36152e7dd8fb88a3f6e9cf3522a8254d19a32e926e3bce155a4f9019109dcfeb5f7eebb4f
7
- data.tar.gz: 234ada5db1419584f5addd3a2d36776a45a10b0cd20e202ccedeb968cd6fe57f699596373f9f69ea32cdd76a78f328aded5871b6d7d2a9549a46a136340c8512
6
+ metadata.gz: a1eb6eb1992e3f962d600c44230af5c91bd4ed84f8df4c426a3ce4a2851d3972a4636d030bc5535d71203a123516538583fc5fe97f2157dc03128d5641c45716
7
+ data.tar.gz: 0fbb842f9fe9db24768bcd861779c70a540c7344d4d02610f6d9ec2c41e8114e92cec7dffa3f28aec07217249125268518680de11985cb8f0bd4f8a02c319567
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Geek Dict
4
4
  ---------
5
- A command line tool for translation.
5
+ A command line tool for English-Chinese translation.
6
6
 
7
7
  Install
8
8
  -------
@@ -48,12 +48,20 @@ bin/console
48
48
  pry>GeekDict::CLI.start(['t','test'])
49
49
  ```
50
50
 
51
- TODOs
52
- -----
53
- It's under active development until it satisfy my needs. Below are something in my mind:
54
- * geekdict list : List all words you have searched
55
- * geekdict remove : Remove word you know from your new words list
56
- * Use google translate engine as alternative, as well as supporting other target language. Low priority, only focus on Chinese.
51
+ ### Test
52
+ ```
53
+ rspec
54
+ ```
55
+
56
+ ### Build
57
+ ```
58
+ gem build geekdict.gemspec
59
+ ```
60
+
61
+ ### Publish
62
+ ```
63
+ gem push geekdict-<VERSION>.gem
64
+ ```
57
65
 
58
66
  License
59
67
  -------
data/geekdict.gemspec CHANGED
@@ -26,7 +26,8 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency "pry"
27
27
  s.add_development_dependency "rspec", "~> 2.13.0"
28
28
 
29
- s.add_runtime_dependency "thor", "~> 0.19.4"
30
- s.add_runtime_dependency "httpclient", "~> 2.8.3"
29
+ s.add_runtime_dependency "thor", "~> 1.2.1"
30
+ s.add_runtime_dependency "httpclient", "~> 2.7.1"
31
+ s.add_runtime_dependency "ruby-openai"
31
32
 
32
33
  end
data/lib/geekdict/cli.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "thor"
2
2
  require_relative 'local_history'
3
3
  require_relative 'version'
4
+ require_relative 'openai/gpt.rb'
4
5
 
5
6
  module GeekDict
6
7
 
@@ -12,16 +13,8 @@ module GeekDict
12
13
  def t(word)
13
14
  GeekDict.debugger options[:debug]
14
15
  LocalHistory.save word
15
- if options[:open]
16
- page = GeekDict::Youdao.url word
17
- puts "Open Web page : #{page}"
18
- `open #{page}`
19
- else
20
- result = GeekDict::Youdao.translate word
21
- output = result.join "\n"
22
- puts output
23
- output
24
- end
16
+ result = GeekDict::OpenAI.translate word
17
+ puts result
25
18
  end
26
19
 
27
20
  desc "v", "version"
@@ -0,0 +1,32 @@
1
+ require 'json'
2
+ require 'openai'
3
+
4
+ module GeekDict
5
+ module OpenAI
6
+
7
+ #Youdao API version
8
+
9
+ module_function
10
+
11
+ def translate(word)
12
+ @debugger = GeekDict.debugger
13
+ client = ::OpenAI::Client.new(access_token: ENV.fetch('OPENAI_API_KEY'))
14
+ response = client.chat(
15
+ parameters: {
16
+ model: "gpt-3.5-turbo",
17
+ messages: [
18
+ { role: "system", content: system_prompt(word)},
19
+ { role: "user", content: word}
20
+ ],
21
+ temperature: 0.7,
22
+ })
23
+ return response.dig("choices", 0, "message", "content")
24
+ end
25
+
26
+ def system_prompt(word)
27
+ <<-EOS
28
+ You are helpful and enthusiastic language translator. If the word or sentense is Chinese, translate it into English. If it is English, translate into Chinese. If the word is incorrect spelled, try your best to translate and give a correct word. Besides translate, give more detailed explanation of the word, and one or two examples. Do NOT add Pinyin in the example sentense for Chinese.
29
+ EOS
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module GeekDict
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geekdict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wenbing Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-11 00:00:00.000000000 Z
11
+ date: 2023-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -58,28 +58,42 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.19.4
61
+ version: 1.2.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.19.4
68
+ version: 1.2.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: httpclient
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 2.8.3
75
+ version: 2.7.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 2.8.3
82
+ version: 2.7.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: ruby-openai
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: A command line tool for translation.
84
98
  email:
85
99
  - wbinglee@gmail.com
@@ -98,6 +112,7 @@ files:
98
112
  - lib/geekdict/cli.rb
99
113
  - lib/geekdict/debugger.rb
100
114
  - lib/geekdict/local_history.rb
115
+ - lib/geekdict/openai/gpt.rb
101
116
  - lib/geekdict/version.rb
102
117
  - lib/geekdict/youdao/api.rb
103
118
  - lib/geekdict/youdao/config.rb
@@ -123,8 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
138
  - !ruby/object:Gem::Version
124
139
  version: '0'
125
140
  requirements: []
126
- rubyforge_project: geekdict
127
- rubygems_version: 2.5.1
141
+ rubygems_version: 3.3.26
128
142
  signing_key:
129
143
  specification_version: 4
130
144
  summary: A command line tool for translation.