soka 0.0.4 → 0.0.6

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.
@@ -1,121 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Soka
4
- module Engines
5
- module Concerns
6
- # Module for handling prompt templates in ReAct engine
7
- module PromptTemplate
8
- private
9
-
10
- def system_prompt
11
- # Use custom instructions if provided, otherwise use default ReAct prompt
12
- if custom_instructions
13
- combine_with_react_format(custom_instructions)
14
- else
15
- default_react_prompt
16
- end
17
- end
18
-
19
- def default_react_prompt
20
- tools_description = format_tools_description(tools)
21
-
22
- <<~PROMPT
23
- You are an AI assistant that uses the ReAct (Reasoning and Acting) framework to solve problems step by step.
24
-
25
- You have access to the following tools:
26
- #{tools_description}
27
-
28
- #{format_instructions}
29
- PROMPT
30
- end
31
-
32
- def combine_with_react_format(instructions)
33
- tools_description = format_tools_description(tools)
34
-
35
- <<~PROMPT
36
- #{instructions}
37
-
38
- You have access to the following tools:
39
- #{tools_description}
40
-
41
- #{format_instructions}
42
- PROMPT
43
- end
44
-
45
- def format_instructions
46
- thinking_instruction = build_thinking_instruction(think_in)
47
-
48
- <<~INSTRUCTIONS
49
- You must follow this exact format for each step:
50
-
51
- #{thinking_instruction}
52
-
53
- <Thought>Your reasoning about what to do next</Thought>
54
- <Action>
55
- Tool: tool_name
56
- Parameters: {"param1": "value1", "param2": "value2"}
57
- </Action>
58
-
59
- #{action_format_rules}
60
- INSTRUCTIONS
61
- end
62
-
63
- # Build thinking instruction based on language
64
- # @param language [String, nil] The language to use for thinking
65
- # @return [String] The thinking instruction
66
- def build_thinking_instruction(language)
67
- return '' unless language
68
-
69
- "Use #{language} for your reasoning in <Thought> tags."
70
- end
71
-
72
- # Action format rules
73
- # @return [String] The action format rules
74
- def action_format_rules
75
- <<~RULES
76
- STOP HERE after each Action. Do NOT include <Observation> in your response.
77
- The system will execute the tool and provide the observation.
78
-
79
- After receiving the observation, you can continue with more Thought/Action cycles or provide a final answer:
80
-
81
- <Final_Answer>Your complete answer to the user's question</Final_Answer>
82
-
83
- Important rules:
84
- 1. Always start with a <Thought> to analyze the problem
85
- 2. Use tools when you need information or to perform actions
86
- 3. Parameters MUST be valid JSON format (e.g., {"query": "weather"} not {query: "weather"})
87
- 4. For tools without parameters, use empty JSON object: {}
88
- 5. NEVER include <Observation> tags - wait for the system to provide them
89
- 6. Provide a clear and complete <Final_Answer> when done
90
- 7. If you cannot complete the task, explain why in the <Final_Answer>
91
- RULES
92
- end
93
-
94
- def format_tools_description(tools)
95
- return 'No tools available.' if tools.empty?
96
-
97
- tools.map do |tool|
98
- schema = tool.class.to_h
99
- params_desc = format_parameters(schema[:parameters])
100
-
101
- "- #{schema[:name]}: #{schema[:description]}\n Parameters: #{params_desc}"
102
- end.join("\n")
103
- end
104
-
105
- def format_parameters(params_schema)
106
- return 'none' if params_schema[:properties].empty?
107
-
108
- properties = params_schema[:properties].map do |name, config|
109
- required = params_schema[:required].include?(name.to_s) ? '(required)' : '(optional)'
110
- type = config[:type]
111
- desc = config[:description]
112
-
113
- "#{name} #{required} [#{type}] - #{desc}"
114
- end
115
-
116
- properties.join(', ')
117
- end
118
- end
119
- end
120
- end
121
- end