kaba 0.3.0 → 0.4.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: 17f06505d496fef06c186773df25fa37d7a2e465fac06682f51a300933e286d5
4
- data.tar.gz: caefca3868f25c1cd15e6bf441ae3e595a2be4b5fb7574431c1a57284ca00327
3
+ metadata.gz: 0add8ecf9ac4613decb084b678c044809896db95136b59e24602ae47a426d448
4
+ data.tar.gz: 2dda3c5fa0152b4928c4a2fadc11b18ed429cc724e87c5b38c794083cb731c69
5
5
  SHA512:
6
- metadata.gz: '09d533d49ac00fd23230ae8ea81f2c189d81b285738142e323b07bb5ea9cbac3cd91ae8f41daa56c37ea1c5297d99573e8dac2c411ec5add299644e8d888ea1e'
7
- data.tar.gz: 15751ae8ef5e041b5ac8638626bac0e938fe989a5647af4c59c8a9cdc803e0796889f4353adf0a5fefe0af0430187f82ca21ccdd9dcd0a53c88a3edd8829c45d
6
+ metadata.gz: 622be2e55740919481236e525f2c2045f9f633eccfa36363a55d959c8d25cd859cfc349e6668df429571052d9501077f8068c35e1a72bac25ced650188c3407e
7
+ data.tar.gz: 56c1a740604cb48c6bfb14f5c93854597fa53922c2befd03e58cf192d29e2b2b1ac87d9480255ae6c6ef175d2652299b67b0cba8cb1e0deccf405adce9efa22b
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/kaba.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "用来做数据集的工具"
13
13
  spec.homepage = "https://github.com/mjason/kaba.git"
14
14
  spec.required_ruby_version = ">= 3.3.0"
15
+ spec.license = "MIT"
15
16
 
16
17
  # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
17
18
 
@@ -10,11 +10,23 @@ class Application
10
10
 
11
11
  def llm_client
12
12
  @llm_client ||= OpenAI::Client.new(
13
+ log_errors: true,
13
14
  access_token: env!("LISA_ACCESS_TOKEN"),
14
15
  request_timeout: ENV.fetch("LISA_LLM_REQUEST_TIMEOUT", 120).to_i,
15
16
  uri_base: ENV.fetch("LISA_LLM_URI_BASE", "https://api.listenai.com")
16
17
  ) do |faraday|
17
- faraday.adapter :async_http, clients: Async::HTTP::Faraday::PersistentClients
18
+ faraday.adapter Faraday.default_adapter, clients: Async::HTTP::Faraday::PersistentClients
19
+ end
20
+ end
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
18
30
  end
19
31
  end
20
32
 
@@ -28,4 +40,4 @@ class Application
28
40
  ENV[name] or raise "missing environment variable: #{name}"
29
41
  end
30
42
  end
31
- end
43
+ 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
@@ -46,14 +48,17 @@ class TestRunner
46
48
  #{JSON.pretty_generate(JSON.parse(File.read(row.target_path)))}
47
49
  ```
48
50
  Markdown
49
- output = Application.llm_client.chat(
51
+ output = ""
52
+ Application.llm_client.chat(
50
53
  parameters: {
51
54
  model: model,
52
55
  messages: [ { role: 'user', content: input } ],
53
56
  temperature: temperature,
57
+ stream: proc do |chunk, _bytesize|
58
+ output += chunk.dig("choices", 0, "delta", "content")
59
+ end
54
60
  }
55
- ).dig("choices", 0, "message", "content")
56
-
61
+ )
57
62
 
58
63
  output_json = JSON.parse_llm_response output
59
64
 
@@ -61,7 +66,7 @@ class TestRunner
61
66
  @type_right_total += 1 if type_check_response["success"]
62
67
 
63
68
  judge_input = Judge.new(input: input, output: output, target: target).render
64
- judge_response = Application.llm_client.chat(
69
+ judge_response = Application.judge_llm_client.chat(
65
70
  parameters: {
66
71
  model: judge_model,
67
72
  messages: [ { role: 'user', content: judge_input } ],
@@ -106,4 +111,4 @@ class TestRunner
106
111
  end
107
112
  end
108
113
 
109
- end
114
+ end
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.0"
4
+ VERSION = "0.4.0"
5
5
  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.0
4
+ version: 0.4.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-15 00:00:00.000000000 Z
11
+ date: 2024-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -153,7 +153,8 @@ files:
153
153
  - lib/kaba/version.rb
154
154
  - sig/kaba.rbs
155
155
  homepage: https://github.com/mjason/kaba.git
156
- licenses: []
156
+ licenses:
157
+ - MIT
157
158
  metadata:
158
159
  homepage_uri: https://github.com/mjason/kaba.git
159
160
  source_code_uri: https://github.com/mjason/kaba.git