geekdict 0.0.5 → 0.1.0
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 +16 -7
- data/geekdict.gemspec +4 -3
- data/lib/geekdict/cli.rb +10 -10
- data/lib/geekdict/openai/gpt.rb +32 -0
- data/lib/geekdict/version.rb +1 -1
- metadata +23 -9
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 90e371d728887d96bd825b2e512e8a3ba093c49c6cdb788474f899bba185f1ae
         | 
| 4 | 
            +
              data.tar.gz: 79362e55a2fb8d5012f2801c7bc7efd96d8cdcbda5a780eff92329a6f33deeb3
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 | 
             
            -------
         | 
| @@ -46,13 +46,22 @@ Development | |
| 46 46 | 
             
            ```
         | 
| 47 47 | 
             
            bin/console
         | 
| 48 48 | 
             
            pry>GeekDict::CLI.start(['t','test'])
         | 
| 49 | 
            +
            ```
         | 
| 49 50 |  | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 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 | 
            +
            ```
         | 
| 56 65 |  | 
| 57 66 | 
             
            License
         | 
| 58 67 | 
             
            -------
         | 
    
        data/geekdict.gemspec
    CHANGED
    
    | @@ -5,7 +5,7 @@ require "geekdict/version" | |
| 5 5 | 
             
            Gem::Specification.new do |s|
         | 
| 6 6 | 
             
              s.name        = "geekdict"
         | 
| 7 7 | 
             
              s.version     = GeekDict::VERSION
         | 
| 8 | 
            -
              s.authors     = [" | 
| 8 | 
            +
              s.authors     = ["Wenbing Li"]
         | 
| 9 9 | 
             
              s.email       = ["wbinglee@gmail.com"]
         | 
| 10 10 | 
             
              s.licenses = ['MIT']
         | 
| 11 11 | 
             
              s.homepage    = "https://github.com/wbinglee/geekdict"
         | 
| @@ -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", "~>  | 
| 30 | 
            -
              s.add_runtime_dependency "httpclient", "~> 2. | 
| 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,5 +1,8 @@ | |
| 1 1 | 
             
            require "thor"
         | 
| 2 2 | 
             
            require_relative 'local_history'
         | 
| 3 | 
            +
            require_relative 'version'
         | 
| 4 | 
            +
            require_relative 'openai/gpt.rb'
         | 
| 5 | 
            +
             | 
| 3 6 | 
             
            module GeekDict
         | 
| 4 7 |  | 
| 5 8 | 
             
                class CLI < Thor
         | 
| @@ -10,16 +13,13 @@ module GeekDict | |
| 10 13 | 
             
                    def t(word)
         | 
| 11 14 | 
             
                        GeekDict.debugger options[:debug]
         | 
| 12 15 | 
             
                        LocalHistory.save word
         | 
| 13 | 
            -
                         | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
                          puts output
         | 
| 21 | 
            -
                          output
         | 
| 22 | 
            -
                        end
         | 
| 16 | 
            +
                        result = GeekDict::OpenAI.translate word
         | 
| 17 | 
            +
                        puts result
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    desc "v", "version"
         | 
| 21 | 
            +
                    def v()
         | 
| 22 | 
            +
                      puts GeekDict::VERSION
         | 
| 23 23 | 
             
                    end
         | 
| 24 24 |  | 
| 25 25 | 
             
                end
         | 
| @@ -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
         | 
    
        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.0 | 
| 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:  | 
| 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:  | 
| 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.2.2
         | 
| 141 | 
            +
            rubygems_version: 3.3.26
         | 
| 128 142 | 
             
            signing_key: 
         | 
| 129 143 | 
             
            specification_version: 4
         | 
| 130 144 | 
             
            summary: A command line tool for translation.
         |