kaba 0.3.2 → 0.5.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
2
  SHA256:
3
- metadata.gz: cf8ec2d335097ccfe7a540e2d2fa7253d181db9a255517fd32118707c3bbee0d
4
- data.tar.gz: f6d150a528511f20b0523a1c1e30268c526386ed3d309b3faa6ff524cb2b7659
3
+ metadata.gz: 986fbab4a45443b0ffc9676cbe6ea2857a7eaec7ba74294561c4d8abe8bf8869
4
+ data.tar.gz: e5a2254a5f2dc1778083df00141c59654749e2538eb695384c3528c49a8820dd
5
5
  SHA512:
6
- metadata.gz: c2fa2925775abd5bc7e04e0ff58ed3066f321dbe6c796f40eb66048945f8b3860ab8ee721b2aa4e612fac7b79f3dc57880c7b35e2e4e0ba29cc01de72db894b7
7
- data.tar.gz: ba270bbcb84f5e89ad5154e1a789515c5200cf92dacaab1252f2bc60440e93d1c1fe999eaad98d9c2eb29bf73b720bb27608f22fff62f1d3d4eec52c9b5aefc1
6
+ metadata.gz: 42b2a10981e7133b1b34b5a9e38ea5c12a0b7965ce4b12b689a8840b2d45b672ba1b04d6a6462b2d4f93ce8fa2d34fbd77769ee09725801f217f3f25145a5a8c
7
+ data.tar.gz: ba4cfed522723fca973d6c265eeb5e9d97edad4326bbbd36086cf385bae31ed8d37b7607e368dd40129311d37f43711e5749fd88cbd79e29e3c0f99a74592b97
data/README.md CHANGED
@@ -30,4 +30,15 @@ alias kaba='docker run -it --rm -v "${PWD}:/workdir" ghcr.io/mjason/kaba:latest'
30
30
  ## 关联项目
31
31
  - [lisa_typechat_server](https://github.com/mjason/lisa_typechat_server)
32
32
 
33
- 如果要修改服务地址你有两个方式,一个通过 `.env` 来处理,还有就是自己设置环境变量,变量名 `LISA_TYPECHAT_ENDPOINT`
33
+ 如果要修改服务地址你有两个方式,一个通过 `.env` 来处理,还有就是自己设置环境变量,变量名 `LISA_TYPECHAT_ENDPOINT`
34
+
35
+ ## changelog
36
+
37
+ .env 需要更新
38
+ ```
39
+ ; LISA_TYPECHAT_ENDPOINT=https://lisa-typechat.listenai.com
40
+ LISA_ACCESS_TOKEN=聆思平台的KEY
41
+
42
+ JUDGE_ACCCESS_TOKEN=可以和LISA_ACCESS_TOKEN
43
+ JUDGE_LLM_URI_BASE=如果需要其他提供商可以填,默认不填
44
+ ```
data/exe/kaba CHANGED
@@ -6,14 +6,42 @@ require 'dotenv'
6
6
  Dotenv.load
7
7
 
8
8
  require "kaba"
9
+ require 'thor'
9
10
 
10
- if ARGV[0] == 'test'
11
- # 运行测试程序
12
- load DatasetSource.testfile
13
- elsif ARGV[0] == 'version'
14
- # 显示版本号
15
- puts Kaba::VERSION
16
- else
17
- # 运行 DPodfile 文件,DPodfile 是一个 Ruby 文件
18
- load DatasetSource.podfile
19
- end
11
+ class KabaCommand < Thor
12
+ desc "test", "Run the test program"
13
+ def test
14
+ load DatasetSource.testfile
15
+ end
16
+
17
+ desc "version", "Show the version"
18
+ def version
19
+ puts Kaba::VERSION
20
+ end
21
+
22
+ desc "exec FILE", "Run a specified Ruby file"
23
+ def exec(file)
24
+ load file
25
+ end
26
+
27
+ desc "create", "Run the DPodfile (default behavior)"
28
+ def create
29
+ load DatasetSource.podfile
30
+ end
31
+
32
+ desc "validate", "Validate the environment"
33
+ def validate
34
+ Boot.validate
35
+ end
36
+
37
+ # 默认行为处理(兼容现有行为)
38
+ def self.start(args = ARGV, config = {})
39
+ if args.empty?
40
+ new.create
41
+ else
42
+ super
43
+ end
44
+ end
45
+ end
46
+
47
+ KabaCommand.start
data/kaba.gemspec CHANGED
@@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
40
40
  spec.add_dependency "dotenv", "~> 3.1"
41
41
  spec.add_dependency "ruby-openai", "~> 7.3"
42
42
  spec.add_dependency "json-repair", "~> 0.2.0"
43
+ spec.add_dependency "thor", '~> 1.3', '>= 1.3.2'
43
44
 
44
45
  # For more information and examples about making a new gem, check out our
45
46
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -19,6 +19,17 @@ class Application
19
19
  end
20
20
  end
21
21
 
22
+ def judge_llm_client
23
+ @judge_llm_client ||= OpenAI::Client.new(
24
+ log_errors: true,
25
+ access_token: env!("JUDGE_ACCCESS_TOKEN"),
26
+ request_timeout: ENV.fetch("LISA_LLM_REQUEST_TIMEOUT", 120).to_i,
27
+ uri_base: ENV.fetch("JUDGE_LLM_URI_BASE", "https://api.listenai.com")
28
+ ) do |faraday|
29
+ faraday.adapter Faraday.default_adapter, clients: Async::HTTP::Faraday::PersistentClients
30
+ end
31
+ end
32
+
22
33
  def llm_client_extra_headers=(headers)
23
34
  OpenAI.configure do |config|
24
35
  config.extra_headers = headers
data/lib/kaba/boot.rb ADDED
@@ -0,0 +1,32 @@
1
+ module Boot
2
+ module_function
3
+ def init
4
+ # 判断 .env 文件是否存在, 不存在则创建
5
+ unless File.exist?(".env")
6
+ File.open(".env", "w") do |f|
7
+ f.write("LISA_ACCESS_TOKEN=<Lisa access token, visit: https://platform.listenai.com/>\n")
8
+ f.write("JUDGE_ACCCESS_TOKEN=<Judge access token, visit: https://platform.listenai.com/>\n")
9
+
10
+ f.write("; if you are using a different typechat endpoint, please fill in the following line\n")
11
+ f.write("; LISA_TYPECHAT_ENDPOINT=https://lisa-typechat.listenai.com\n")
12
+
13
+ f.write("; if you are using a different LLM endpoint, please fill in the following line\n")
14
+ f.write("; LISA_LLM_URI_BASE=https://api.listenai.com\n")
15
+
16
+ f.write("; if you are using a different JUDGE LLM endpoint, please fill in the following line\n")
17
+ f.write("; JUDGE_LLM_URI_BASE=https://api.listenai.com\n")
18
+ end
19
+
20
+ puts "Created .env file, please fill in the necessary information."
21
+ end
22
+ end
23
+
24
+ def validate
25
+ puts "Validating..."
26
+ Application.env!('LISA_ACCESS_TOKEN')
27
+ Application.env!('JUDGE_ACCCESS_TOKEN')
28
+ puts "Validation passed."
29
+ rescue => e
30
+ puts "Validation failed: #{e.message}"
31
+ end
32
+ end
@@ -26,7 +26,8 @@ class TestRunner
26
26
  model: 'spark-general-4.0',
27
27
  judge_model: 'spark-general-4.0',
28
28
  judge_temperature: 0.1,
29
- temperature: 0.1
29
+ temperature: 0.1,
30
+ semaphore_limit: 5
30
31
  )
31
32
 
32
33
  progressbar = TTY::ProgressBar.new(
@@ -37,8 +38,9 @@ class TestRunner
37
38
  progressbar.start
38
39
 
39
40
  Async do
41
+ semaphore = Async::Semaphore.new(semaphore_limit)
40
42
  _each(limit: limit) do |row|
41
- Async do |task|
43
+ semaphore.async do |task|
42
44
  input = @prompt.render(File.read row.input_file)
43
45
 
44
46
  target = <<~Markdown
@@ -64,7 +66,7 @@ class TestRunner
64
66
  @type_right_total += 1 if type_check_response["success"]
65
67
 
66
68
  judge_input = Judge.new(input: input, output: output, target: target).render
67
- judge_response = Application.llm_client.chat(
69
+ judge_response = Application.judge_llm_client.chat(
68
70
  parameters: {
69
71
  model: judge_model,
70
72
  messages: [ { role: 'user', content: judge_input } ],
data/lib/kaba/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kaba
4
- VERSION = "0.3.2"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/kaba.rb CHANGED
@@ -19,6 +19,7 @@ require_relative "kaba/prompt"
19
19
  require_relative "kaba/validate"
20
20
  require_relative "kaba/judge"
21
21
  require_relative "kaba/test_runner"
22
+ require_relative "kaba/boot"
22
23
 
23
24
  module Kaba
24
25
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MJ
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-16 00:00:00.000000000 Z
11
+ date: 2024-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -122,6 +122,26 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.2.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: thor
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.3'
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 1.3.2
135
+ type: :runtime
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: '1.3'
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 1.3.2
125
145
  description: 用来做数据集的工具
126
146
  email:
127
147
  - tywf91@gmail.com
@@ -140,6 +160,7 @@ files:
140
160
  - lib/kaba/_DPodfile_
141
161
  - lib/kaba/_DTestfile_
142
162
  - lib/kaba/application.rb
163
+ - lib/kaba/boot.rb
143
164
  - lib/kaba/dataset.rb
144
165
  - lib/kaba/dataset_source.rb
145
166
  - lib/kaba/json.rb