soka 0.0.2 → 0.0.4

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.
@@ -15,7 +15,6 @@ module Soka
15
15
  thoughts: result.thoughts || [],
16
16
  final_answer: result.final_answer,
17
17
  status: result.status,
18
- confidence_score: result.confidence_score,
19
18
  timestamp: Time.now
20
19
  }
21
20
 
@@ -52,14 +51,6 @@ module Soka
52
51
  @sessions.select { |s| s[:status] == :failed }
53
52
  end
54
53
 
55
- def average_confidence_score
56
- successful = successful_sessions
57
- return 0.0 if successful.empty?
58
-
59
- total = successful.sum { |s| s[:confidence_score] || 0.0 }
60
- total / successful.size
61
- end
62
-
63
54
  def average_iterations
64
55
  return 0 if @sessions.empty?
65
56
 
@@ -80,7 +71,6 @@ module Soka
80
71
  total: size,
81
72
  successful: successful_sessions.size,
82
73
  failed: failed_sessions.size,
83
- avg_confidence: format('%.2f', average_confidence_score),
84
74
  avg_iterations: format('%.1f', average_iterations)
85
75
  }
86
76
  end
@@ -88,7 +78,6 @@ module Soka
88
78
  def format_stats_string(stats)
89
79
  "<Soka::ThoughtsMemory> (#{stats[:total]} sessions, " \
90
80
  "#{stats[:successful]} successful, #{stats[:failed]} failed, " \
91
- "avg confidence: #{stats[:avg_confidence]}, " \
92
81
  "avg iterations: #{stats[:avg_iterations]})"
93
82
  end
94
83
 
@@ -103,7 +92,6 @@ module Soka
103
92
  total_sessions: size,
104
93
  successful_sessions: successful_sessions.size,
105
94
  failed_sessions: failed_sessions.size,
106
- average_confidence_score: average_confidence_score,
107
95
  average_iterations: average_iterations
108
96
  }
109
97
  }
data/lib/soka/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Soka
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiunjiun
@@ -53,6 +53,8 @@ files:
53
53
  - LICENSE
54
54
  - README.md
55
55
  - Rakefile
56
+ - examples/10_dynamic_instructions.rb
57
+ - examples/11_think_in_languages.rb
56
58
  - examples/1_basic.rb
57
59
  - examples/2_event_handling.rb
58
60
  - examples/3_memory.rb
@@ -61,6 +63,7 @@ files:
61
63
  - examples/6_retry.rb
62
64
  - examples/7_tool_conditional.rb
63
65
  - examples/8_multi_provider.rb
66
+ - examples/9_custom_instructions.rb
64
67
  - lib/soka.rb
65
68
  - lib/soka/agent.rb
66
69
  - lib/soka/agent_tool.rb
@@ -73,7 +76,9 @@ files:
73
76
  - lib/soka/configuration.rb
74
77
  - lib/soka/engines/base.rb
75
78
  - lib/soka/engines/concerns/prompt_template.rb
79
+ - lib/soka/engines/concerns/response_parser.rb
76
80
  - lib/soka/engines/concerns/response_processor.rb
81
+ - lib/soka/engines/concerns/result_builder.rb
77
82
  - lib/soka/engines/react.rb
78
83
  - lib/soka/engines/reasoning_context.rb
79
84
  - lib/soka/llm.rb
@@ -83,7 +88,6 @@ files:
83
88
  - lib/soka/llms/openai.rb
84
89
  - lib/soka/memory.rb
85
90
  - lib/soka/result.rb
86
- - lib/soka/test_helpers.rb
87
91
  - lib/soka/thoughts_memory.rb
88
92
  - lib/soka/version.rb
89
93
  - sig/soka.rbs
@@ -1,162 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Soka
4
- # RSpec test helpers for Soka framework
5
- module TestHelpers
6
- def self.included(base)
7
- base.class_eval do
8
- let(:mock_llm_response) { nil }
9
- let(:mock_tool_responses) { {} }
10
- end
11
- end
12
-
13
- def mock_ai_response(response_data)
14
- @mock_llm_response = response_data
15
-
16
- # Create a mock LLM that returns the specified response
17
- mock_llm = instance_double(Soka::LLM::Base)
18
-
19
- # Format the response content based on the response data
20
- content = build_react_content(response_data)
21
-
22
- result = create_mock_llm_result(content)
23
-
24
- allow(mock_llm).to receive(:chat).and_return(result)
25
- allow(Soka::LLM).to receive(:new).and_return(mock_llm)
26
-
27
- mock_llm
28
- end
29
-
30
- def create_mock_llm_result(content)
31
- Soka::LLM::Result.new(
32
- model: 'mock-model',
33
- content: content,
34
- input_tokens: 100,
35
- output_tokens: 200,
36
- finish_reason: 'stop',
37
- raw_response: { mock: true }
38
- )
39
- end
40
-
41
- def mock_tool_response(tool_class, response)
42
- @mock_tool_responses[tool_class] = response
43
-
44
- # Create a mock instance of the tool
45
- mock_tool = instance_double(tool_class)
46
- allow(mock_tool).to receive(:class).and_return(tool_class)
47
- allow(mock_tool).to receive(:execute).and_return(response)
48
-
49
- # Allow the tool class to be instantiated with the mock
50
- allow(tool_class).to receive(:new).and_return(mock_tool)
51
-
52
- mock_tool
53
- end
54
-
55
- def allow_tool_to_fail(tool_class, error)
56
- mock_tool = instance_double(tool_class)
57
- allow(mock_tool).to receive(:class).and_return(tool_class)
58
- allow(mock_tool).to receive(:execute).and_raise(error)
59
-
60
- allow(tool_class).to receive(:new).and_return(mock_tool)
61
-
62
- mock_tool
63
- end
64
-
65
- def create_test_agent(options = {})
66
- Class.new(Soka::Agent) do
67
- provider :gemini
68
- model 'gemini-2.5-flash'
69
- max_iterations 5
70
- timeout 10
71
- end.new(**options)
72
- end
73
-
74
- def create_test_tool(name: 'test_tool', description: 'Test tool', &block)
75
- Class.new(Soka::AgentTool) do
76
- desc description
77
-
78
- define_singleton_method :tool_name do
79
- name
80
- end
81
-
82
- define_method :call, &block || -> { 'Test response' }
83
- end
84
- end
85
-
86
- def stub_env(env_vars)
87
- env_vars.each do |key, value|
88
- allow(ENV).to receive(:fetch).with(key).and_return(value)
89
- allow(ENV).to receive(:[]).with(key).and_return(value)
90
- end
91
- end
92
-
93
- def with_configuration
94
- original_config = Soka.configuration
95
- Soka.reset!
96
- yield
97
- ensure
98
- Soka.configuration = original_config
99
- end
100
-
101
- private
102
-
103
- def build_react_content(response_data)
104
- content = []
105
-
106
- # Build thoughts and actions
107
- response_data[:thoughts].each_with_index do |thought_data, _index|
108
- content << "<Thought>#{thought_data[:thought]}</Thought>"
109
-
110
- next unless thought_data[:action]
111
-
112
- action = thought_data[:action]
113
- params_json = action[:params].to_json
114
-
115
- content << build_action_content(action[:tool], params_json)
116
-
117
- # The observation will be added by the engine
118
- end
119
-
120
- # Add final answer if present
121
- content << "<Final_Answer>#{response_data[:final_answer]}</Final_Answer>" if response_data[:final_answer]
122
-
123
- content.join("\n")
124
- end
125
-
126
- def build_action_content(tool, params_json)
127
- <<~ACTION
128
- <Action>
129
- Tool: #{tool}
130
- Parameters: #{params_json}
131
- </Action>
132
- ACTION
133
- end
134
-
135
- # Matcher helpers for RSpec
136
- module Matchers
137
- def be_successful
138
- satisfy(&:successful?)
139
- end
140
-
141
- def be_failed
142
- satisfy(&:failed?)
143
- end
144
-
145
- def final_answer?(expected = nil)
146
- if expected
147
- satisfy { |result| result.final_answer == expected }
148
- else
149
- satisfy { |result| !result.final_answer.nil? }
150
- end
151
- end
152
-
153
- def thoughts_count?(count)
154
- satisfy { |result| result.thoughts.length == count }
155
- end
156
-
157
- def confidence_score_above?(threshold)
158
- satisfy { |result| result.confidence_score > threshold }
159
- end
160
- end
161
- end
162
- end