geekdict 0.0.6 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +19 -7
- data/geekdict.gemspec +3 -3
- data/lib/geekdict/cli.rb +3 -10
- data/lib/geekdict/openai/gpt.rb +32 -0
- data/lib/geekdict/version.rb +1 -1
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f9a7876ba4eddfb0497523ab7f318588fc1ef1abf754b5f75771b0f2bbc29092
|
4
|
+
data.tar.gz: 460d3c363a9622fec12bb463854239355293827327d7d7639338c306a36f99a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a66b0934455eebc3bc5c511510abc261d7c8ddb59cc91f4ea66b4b30ee6b8d709f39451e62d4674731db803ec88f105c064c8722b56b9e073abd0c38597b8c1a
|
7
|
+
data.tar.gz: 64d730010c52a0e5c7a98b169ff7fef55ed34eab4863b32781aefd18889ffa946cab96dbc5d33516668488d87ddb3be830a111a7b75092e552c3fc29f2d106f2
|
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
|
-------
|
@@ -10,6 +10,10 @@ You can install via rubygems:
|
|
10
10
|
|
11
11
|
gem install geekdict
|
12
12
|
|
13
|
+
Configure
|
14
|
+
--------
|
15
|
+
This translate uses OpenAI's GPT-3.5. Ensure you have `OPENAI_API_KEY` configured as environment variable.
|
16
|
+
|
13
17
|
|
14
18
|
Commands
|
15
19
|
--------
|
@@ -48,12 +52,20 @@ bin/console
|
|
48
52
|
pry>GeekDict::CLI.start(['t','test'])
|
49
53
|
```
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
### Test
|
56
|
+
```
|
57
|
+
rspec
|
58
|
+
```
|
59
|
+
|
60
|
+
### Build
|
61
|
+
```
|
62
|
+
gem build geekdict.gemspec
|
63
|
+
```
|
64
|
+
|
65
|
+
### Publish
|
66
|
+
```
|
67
|
+
gem push geekdict-<VERSION>.gem
|
68
|
+
```
|
57
69
|
|
58
70
|
License
|
59
71
|
-------
|
data/geekdict.gemspec
CHANGED
@@ -26,7 +26,7 @@ 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", "~>
|
30
|
-
s.add_runtime_dependency "httpclient", "~> 2.
|
31
|
-
|
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"
|
32
32
|
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
|
-
|
16
|
-
|
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.2,
|
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 incorrectly spelled or it's not a correct word in English or Chinese, try your best to find the closest word. In addition to the translation, offer a comprehensive explanation of the word along with one or two examples to illustrate its usage. Do NOT add Pinyin in the example sentences for Chinese.
|
29
|
+
EOS
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/geekdict/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wenbing Li
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-01 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:
|
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:
|
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.
|
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.
|
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
|
-
|
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.
|