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 +4 -4
- data/README.md +12 -1
- data/kaba.gemspec +1 -0
- data/lib/kaba/application.rb +14 -2
- data/lib/kaba/test_runner.rb +12 -7
- data/lib/kaba/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0add8ecf9ac4613decb084b678c044809896db95136b59e24602ae47a426d448
|
4
|
+
data.tar.gz: 2dda3c5fa0152b4928c4a2fadc11b18ed429cc724e87c5b38c794083cb731c69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/kaba/application.rb
CHANGED
@@ -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
|
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
|
data/lib/kaba/test_runner.rb
CHANGED
@@ -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
|
-
|
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 =
|
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
|
-
)
|
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.
|
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
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.
|
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-
|
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
|