scout-ai 0.2.0 → 1.0.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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +155 -9
  3. data/README.md +296 -0
  4. data/Rakefile +3 -0
  5. data/VERSION +1 -1
  6. data/bin/scout-ai +2 -0
  7. data/doc/Agent.md +279 -0
  8. data/doc/Chat.md +258 -0
  9. data/doc/LLM.md +446 -0
  10. data/doc/Model.md +513 -0
  11. data/doc/RAG.md +129 -0
  12. data/lib/scout/llm/agent/chat.rb +74 -0
  13. data/lib/scout/llm/agent/delegate.rb +39 -0
  14. data/lib/scout/llm/agent/iterate.rb +44 -0
  15. data/lib/scout/llm/agent.rb +51 -30
  16. data/lib/scout/llm/ask.rb +63 -21
  17. data/lib/scout/llm/backends/anthropic.rb +147 -0
  18. data/lib/scout/llm/backends/bedrock.rb +129 -0
  19. data/lib/scout/llm/backends/huggingface.rb +6 -21
  20. data/lib/scout/llm/backends/ollama.rb +62 -35
  21. data/lib/scout/llm/backends/openai.rb +77 -33
  22. data/lib/scout/llm/backends/openwebui.rb +1 -1
  23. data/lib/scout/llm/backends/relay.rb +3 -2
  24. data/lib/scout/llm/backends/responses.rb +320 -0
  25. data/lib/scout/llm/chat.rb +703 -0
  26. data/lib/scout/llm/embed.rb +4 -4
  27. data/lib/scout/llm/mcp.rb +28 -0
  28. data/lib/scout/llm/parse.rb +71 -13
  29. data/lib/scout/llm/rag.rb +9 -0
  30. data/lib/scout/llm/tools/call.rb +66 -0
  31. data/lib/scout/llm/tools/knowledge_base.rb +158 -0
  32. data/lib/scout/llm/tools/mcp.rb +59 -0
  33. data/lib/scout/llm/tools/workflow.rb +69 -0
  34. data/lib/scout/llm/tools.rb +112 -76
  35. data/lib/scout/llm/utils.rb +17 -10
  36. data/lib/scout/model/base.rb +19 -0
  37. data/lib/scout/model/python/base.rb +25 -0
  38. data/lib/scout/model/python/huggingface/causal/next_token.rb +23 -0
  39. data/lib/scout/model/python/huggingface/causal.rb +29 -0
  40. data/lib/scout/model/python/huggingface/classification +0 -0
  41. data/lib/scout/model/python/huggingface/classification.rb +50 -0
  42. data/lib/scout/model/python/huggingface.rb +112 -0
  43. data/lib/scout/model/python/torch/dataloader.rb +57 -0
  44. data/lib/scout/model/python/torch/helpers.rb +84 -0
  45. data/lib/scout/model/python/torch/introspection.rb +34 -0
  46. data/lib/scout/model/python/torch/load_and_save.rb +47 -0
  47. data/lib/scout/model/python/torch.rb +94 -0
  48. data/lib/scout/model/util/run.rb +181 -0
  49. data/lib/scout/model/util/save.rb +81 -0
  50. data/lib/scout-ai.rb +4 -1
  51. data/python/scout_ai/__init__.py +35 -0
  52. data/python/scout_ai/huggingface/data.py +48 -0
  53. data/python/scout_ai/huggingface/eval.py +60 -0
  54. data/python/scout_ai/huggingface/model.py +29 -0
  55. data/python/scout_ai/huggingface/rlhf.py +83 -0
  56. data/python/scout_ai/huggingface/train/__init__.py +34 -0
  57. data/python/scout_ai/huggingface/train/next_token.py +315 -0
  58. data/python/scout_ai/util.py +32 -0
  59. data/scout-ai.gemspec +143 -0
  60. data/scout_commands/agent/ask +89 -14
  61. data/scout_commands/agent/kb +15 -0
  62. data/scout_commands/documenter +148 -0
  63. data/scout_commands/llm/ask +71 -12
  64. data/scout_commands/llm/process +4 -2
  65. data/scout_commands/llm/server +319 -0
  66. data/share/server/chat.html +138 -0
  67. data/share/server/chat.js +468 -0
  68. data/test/data/cat.jpg +0 -0
  69. data/test/scout/llm/agent/test_chat.rb +14 -0
  70. data/test/scout/llm/backends/test_anthropic.rb +134 -0
  71. data/test/scout/llm/backends/test_bedrock.rb +60 -0
  72. data/test/scout/llm/backends/test_huggingface.rb +3 -3
  73. data/test/scout/llm/backends/test_ollama.rb +48 -10
  74. data/test/scout/llm/backends/test_openai.rb +134 -10
  75. data/test/scout/llm/backends/test_responses.rb +239 -0
  76. data/test/scout/llm/test_agent.rb +0 -70
  77. data/test/scout/llm/test_ask.rb +4 -1
  78. data/test/scout/llm/test_chat.rb +256 -0
  79. data/test/scout/llm/test_mcp.rb +29 -0
  80. data/test/scout/llm/test_parse.rb +81 -2
  81. data/test/scout/llm/tools/test_call.rb +0 -0
  82. data/test/scout/llm/tools/test_knowledge_base.rb +22 -0
  83. data/test/scout/llm/tools/test_mcp.rb +11 -0
  84. data/test/scout/llm/tools/test_workflow.rb +39 -0
  85. data/test/scout/model/python/huggingface/causal/test_next_token.rb +59 -0
  86. data/test/scout/model/python/huggingface/test_causal.rb +33 -0
  87. data/test/scout/model/python/huggingface/test_classification.rb +30 -0
  88. data/test/scout/model/python/test_base.rb +44 -0
  89. data/test/scout/model/python/test_huggingface.rb +9 -0
  90. data/test/scout/model/python/test_torch.rb +71 -0
  91. data/test/scout/model/python/torch/test_helpers.rb +14 -0
  92. data/test/scout/model/test_base.rb +117 -0
  93. data/test/scout/model/util/test_save.rb +31 -0
  94. metadata +113 -7
  95. data/README.rdoc +0 -18
  96. data/questions/coach +0 -2
@@ -0,0 +1,14 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/model/python/base'
5
+ class TestTorchHelpers < Test::Unit::TestCase
6
+ def test_del
7
+ ScoutPython.init_scout
8
+ ScoutPython.pyimport :torch
9
+ batch = [[100.0]]
10
+ tensor = TorchModel.tensor(batch, 'cuda', @dtype)
11
+ tensor.del
12
+ end
13
+ end
14
+
@@ -0,0 +1,117 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestClass < Test::Unit::TestCase
5
+ def test_trivial_model
6
+ model = ScoutModel.new
7
+ model.eval do |sample,list=nil|
8
+ if list
9
+ list.collect{|sample|
10
+ sample * 2
11
+ }
12
+ else
13
+ sample * 2
14
+ end
15
+ end
16
+
17
+ assert_equal 2, model.eval(1)
18
+ assert_equal [2, 4], model.eval_list([1, 2])
19
+ end
20
+
21
+ def test_trivial_model_options
22
+ model = ScoutModel.new nil, factor: 4
23
+ model.eval do |sample,list=nil|
24
+ if list
25
+ list.collect{|sample|
26
+ sample * @options[:factor]
27
+ }
28
+ else
29
+ sample * @options[:factor]
30
+ end
31
+ end
32
+
33
+ assert_equal 4, model.eval(1)
34
+ assert_equal [4, 8], model.eval_list([1, 2])
35
+ end
36
+
37
+ def test_R_model
38
+ require 'rbbt-util'
39
+ require 'rbbt/util/R'
40
+
41
+ text =<<-EOF
42
+ 1 0;1;1
43
+ 1 1;0;1
44
+ 1 1;1;1
45
+ 1 0;1;1
46
+ 1 1;;1
47
+ 0 0;1;0
48
+ 0 1;0;0
49
+ 0 0;1;0
50
+ 0 1;0;0
51
+ EOF
52
+
53
+ TmpFile.with_file do |dir|
54
+ Open.mkdir dir
55
+ model = ScoutModel.new dir
56
+
57
+ model.extract_features do |sample|
58
+ sample.split(";")
59
+ end
60
+
61
+ model.train do |list,labels|
62
+ TmpFile.with_file do |feature_file|
63
+ Open.write(feature_file, list.collect{|feats| feats * "\t"} * "\n")
64
+ Open.write(feature_file + '.class', labels * "\n")
65
+ R.run <<-EOF
66
+ features = read.table("#{ feature_file }", sep ="\\t", stringsAsFactors=FALSE);
67
+ labels = scan("#{ feature_file }.class", what=numeric());
68
+ features = cbind(features, class = labels);
69
+ rbbt.require('e1071')
70
+ model = svm(class ~ ., data = features)
71
+ save(model, file="#{ state_file }");
72
+ EOF
73
+ end
74
+ end
75
+
76
+ model.eval do |features|
77
+ TmpFile.with_file do |feature_file|
78
+ TmpFile.with_file do |results|
79
+ Open.write(feature_file, features * "\t")
80
+ R.run <<-EOF
81
+ features = read.table("#{ feature_file }", sep ="\\t", stringsAsFactors=FALSE);
82
+ library(e1071)
83
+ load(file="#{ state_file }")
84
+ label = predict(model, features);
85
+ cat(label, file="#{results}");
86
+ EOF
87
+
88
+ Open.read(results)
89
+ end
90
+ end
91
+ end
92
+
93
+ text.split(/\n/).each do |line|
94
+ label, sample = line.split(" ")
95
+ model.add(sample, label)
96
+ end
97
+
98
+ model.train
99
+
100
+ assert model.eval("1;1;1").to_f > 0.5
101
+ assert model.eval("0;0;0").to_f < 0.5
102
+
103
+ model.save
104
+
105
+ model = ScoutModel.new dir
106
+ assert model.eval("1;1;1").to_f > 0.5
107
+ assert model.eval("0;0;0").to_f < 0.5
108
+
109
+ model.post_process do |result|
110
+ result.to_f < 0.5 ? :bad : :good
111
+ end
112
+
113
+ assert_equal :bad, model.eval("0;0;0")
114
+ end
115
+ end
116
+ end
117
+
@@ -0,0 +1,31 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/model/base'
5
+
6
+ class TestClass < Test::Unit::TestCase
7
+ def test_trivial_model_save
8
+
9
+ TmpFile.with_file do |dir|
10
+ model = ScoutModel.new dir
11
+
12
+ model.eval do |sample,list=nil|
13
+ if list
14
+ list.collect{|sample|
15
+ sample * 2
16
+ }
17
+ else
18
+ sample * 2
19
+ end
20
+ end
21
+
22
+ model.save
23
+
24
+ model = ScoutModel.new dir
25
+
26
+ assert_equal 2, model.eval(1)
27
+ assert_equal [2, 4], model.eval_list([1, 2])
28
+ end
29
+ end
30
+ end
31
+
metadata CHANGED
@@ -1,14 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout-ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-19 00:00:00.000000000 Z
11
- dependencies: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: scout-rig
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: ruby-openai
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: ruby-mcp-client
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
12
54
  description: assorted functionalities to help scouts use AI
13
55
  email: mikisvaz@gmail.com
14
56
  executables:
@@ -17,50 +59,114 @@ extensions: []
17
59
  extra_rdoc_files:
18
60
  - LICENSE
19
61
  - LICENSE.txt
20
- - README.rdoc
62
+ - README.md
21
63
  files:
22
64
  - ".document"
23
65
  - ".vimproject"
24
66
  - LICENSE
25
67
  - LICENSE.txt
26
- - README.rdoc
68
+ - README.md
27
69
  - Rakefile
28
70
  - VERSION
29
71
  - bin/scout-ai
72
+ - doc/Agent.md
73
+ - doc/Chat.md
74
+ - doc/LLM.md
75
+ - doc/Model.md
76
+ - doc/RAG.md
30
77
  - lib/scout-ai.rb
31
78
  - lib/scout/llm/agent.rb
79
+ - lib/scout/llm/agent/chat.rb
80
+ - lib/scout/llm/agent/delegate.rb
81
+ - lib/scout/llm/agent/iterate.rb
32
82
  - lib/scout/llm/ask.rb
83
+ - lib/scout/llm/backends/anthropic.rb
84
+ - lib/scout/llm/backends/bedrock.rb
33
85
  - lib/scout/llm/backends/huggingface.rb
34
86
  - lib/scout/llm/backends/ollama.rb
35
87
  - lib/scout/llm/backends/openai.rb
36
88
  - lib/scout/llm/backends/openwebui.rb
37
89
  - lib/scout/llm/backends/relay.rb
90
+ - lib/scout/llm/backends/responses.rb
91
+ - lib/scout/llm/chat.rb
38
92
  - lib/scout/llm/embed.rb
93
+ - lib/scout/llm/mcp.rb
39
94
  - lib/scout/llm/parse.rb
40
95
  - lib/scout/llm/rag.rb
41
96
  - lib/scout/llm/tools.rb
97
+ - lib/scout/llm/tools/call.rb
98
+ - lib/scout/llm/tools/knowledge_base.rb
99
+ - lib/scout/llm/tools/mcp.rb
100
+ - lib/scout/llm/tools/workflow.rb
42
101
  - lib/scout/llm/utils.rb
43
- - questions/coach
102
+ - lib/scout/model/base.rb
103
+ - lib/scout/model/python/base.rb
104
+ - lib/scout/model/python/huggingface.rb
105
+ - lib/scout/model/python/huggingface/causal.rb
106
+ - lib/scout/model/python/huggingface/causal/next_token.rb
107
+ - lib/scout/model/python/huggingface/classification
108
+ - lib/scout/model/python/huggingface/classification.rb
109
+ - lib/scout/model/python/torch.rb
110
+ - lib/scout/model/python/torch/dataloader.rb
111
+ - lib/scout/model/python/torch/helpers.rb
112
+ - lib/scout/model/python/torch/introspection.rb
113
+ - lib/scout/model/python/torch/load_and_save.rb
114
+ - lib/scout/model/util/run.rb
115
+ - lib/scout/model/util/save.rb
116
+ - python/scout_ai/__init__.py
117
+ - python/scout_ai/huggingface/data.py
118
+ - python/scout_ai/huggingface/eval.py
119
+ - python/scout_ai/huggingface/model.py
120
+ - python/scout_ai/huggingface/rlhf.py
121
+ - python/scout_ai/huggingface/train/__init__.py
122
+ - python/scout_ai/huggingface/train/next_token.py
123
+ - python/scout_ai/util.py
124
+ - scout-ai.gemspec
44
125
  - scout_commands/agent/ask
126
+ - scout_commands/agent/kb
127
+ - scout_commands/documenter
45
128
  - scout_commands/llm/ask
46
129
  - scout_commands/llm/process
130
+ - scout_commands/llm/server
47
131
  - scout_commands/llm/template
132
+ - share/server/chat.html
133
+ - share/server/chat.js
134
+ - test/data/cat.jpg
48
135
  - test/data/person/brothers
49
136
  - test/data/person/identifiers
50
137
  - test/data/person/marriages
51
138
  - test/data/person/parents
139
+ - test/scout/llm/agent/test_chat.rb
140
+ - test/scout/llm/backends/test_anthropic.rb
141
+ - test/scout/llm/backends/test_bedrock.rb
52
142
  - test/scout/llm/backends/test_huggingface.rb
53
143
  - test/scout/llm/backends/test_ollama.rb
54
144
  - test/scout/llm/backends/test_openai.rb
55
145
  - test/scout/llm/backends/test_openwebui.rb
56
146
  - test/scout/llm/backends/test_relay.rb
147
+ - test/scout/llm/backends/test_responses.rb
57
148
  - test/scout/llm/test_agent.rb
58
149
  - test/scout/llm/test_ask.rb
150
+ - test/scout/llm/test_chat.rb
59
151
  - test/scout/llm/test_embed.rb
152
+ - test/scout/llm/test_mcp.rb
60
153
  - test/scout/llm/test_parse.rb
61
154
  - test/scout/llm/test_rag.rb
62
155
  - test/scout/llm/test_tools.rb
63
156
  - test/scout/llm/test_utils.rb
157
+ - test/scout/llm/tools/test_call.rb
158
+ - test/scout/llm/tools/test_knowledge_base.rb
159
+ - test/scout/llm/tools/test_mcp.rb
160
+ - test/scout/llm/tools/test_workflow.rb
161
+ - test/scout/model/python/huggingface/causal/test_next_token.rb
162
+ - test/scout/model/python/huggingface/test_causal.rb
163
+ - test/scout/model/python/huggingface/test_classification.rb
164
+ - test/scout/model/python/test_base.rb
165
+ - test/scout/model/python/test_huggingface.rb
166
+ - test/scout/model/python/test_torch.rb
167
+ - test/scout/model/python/torch/test_helpers.rb
168
+ - test/scout/model/test_base.rb
169
+ - test/scout/model/util/test_save.rb
64
170
  - test/test_helper.rb
65
171
  homepage: http://github.com/mikisvaz/scout-ai
66
172
  licenses:
@@ -80,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
186
  - !ruby/object:Gem::Version
81
187
  version: '0'
82
188
  requirements: []
83
- rubygems_version: 3.6.5
189
+ rubygems_version: 3.7.0.dev
84
190
  specification_version: 4
85
191
  summary: AI gear for scouts
86
192
  test_files: []
data/README.rdoc DELETED
@@ -1,18 +0,0 @@
1
- = scout-ai
2
-
3
- Description goes here.
4
-
5
- == Contributing to scout-ai
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2025 Miguel Vazquez. See LICENSE.txt for
18
- further details.
data/questions/coach DELETED
@@ -1,2 +0,0 @@
1
- system: You write prompts to give instructions to a coding LLM to perform certain task
2
- user: ???