ollama-client 0.2.5 → 0.2.7
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +336 -91
- data/RELEASE_NOTES_v0.2.6.md +41 -0
- data/docs/AREAS_FOR_CONSIDERATION.md +325 -0
- data/docs/EXAMPLE_REORGANIZATION.md +412 -0
- data/docs/FEATURES_ADDED.md +12 -1
- data/docs/GETTING_STARTED.md +361 -0
- data/docs/INTEGRATION_TESTING.md +170 -0
- data/docs/NEXT_STEPS_SUMMARY.md +114 -0
- data/docs/PERSONAS.md +383 -0
- data/docs/QUICK_START.md +195 -0
- data/docs/TESTING.md +392 -170
- data/docs/TEST_CHECKLIST.md +450 -0
- data/examples/README.md +62 -63
- data/examples/basic_chat.rb +33 -0
- data/examples/basic_generate.rb +29 -0
- data/examples/mcp_executor.rb +39 -0
- data/examples/mcp_http_executor.rb +45 -0
- data/examples/tool_calling_parsing.rb +59 -0
- data/examples/tool_dto_example.rb +0 -0
- data/exe/ollama-client +128 -1
- data/lib/ollama/agent/planner.rb +7 -2
- data/lib/ollama/chat_session.rb +101 -0
- data/lib/ollama/client.rb +41 -35
- data/lib/ollama/config.rb +9 -4
- data/lib/ollama/document_loader.rb +1 -1
- data/lib/ollama/embeddings.rb +61 -28
- data/lib/ollama/errors.rb +1 -0
- data/lib/ollama/mcp/http_client.rb +149 -0
- data/lib/ollama/mcp/stdio_client.rb +146 -0
- data/lib/ollama/mcp/tools_bridge.rb +72 -0
- data/lib/ollama/mcp.rb +31 -0
- data/lib/ollama/options.rb +3 -1
- data/lib/ollama/personas.rb +287 -0
- data/lib/ollama/version.rb +1 -1
- data/lib/ollama_client.rb +17 -5
- metadata +22 -48
- data/examples/advanced_complex_schemas.rb +0 -366
- data/examples/advanced_edge_cases.rb +0 -241
- data/examples/advanced_error_handling.rb +0 -200
- data/examples/advanced_multi_step_agent.rb +0 -341
- data/examples/advanced_performance_testing.rb +0 -186
- data/examples/chat_console.rb +0 -143
- data/examples/complete_workflow.rb +0 -245
- data/examples/dhan_console.rb +0 -843
- data/examples/dhanhq/README.md +0 -236
- data/examples/dhanhq/agents/base_agent.rb +0 -74
- data/examples/dhanhq/agents/data_agent.rb +0 -66
- data/examples/dhanhq/agents/orchestrator_agent.rb +0 -120
- data/examples/dhanhq/agents/technical_analysis_agent.rb +0 -252
- data/examples/dhanhq/agents/trading_agent.rb +0 -81
- data/examples/dhanhq/analysis/market_structure.rb +0 -138
- data/examples/dhanhq/analysis/pattern_recognizer.rb +0 -192
- data/examples/dhanhq/analysis/trend_analyzer.rb +0 -88
- data/examples/dhanhq/builders/market_context_builder.rb +0 -67
- data/examples/dhanhq/dhanhq_agent.rb +0 -829
- data/examples/dhanhq/indicators/technical_indicators.rb +0 -158
- data/examples/dhanhq/scanners/intraday_options_scanner.rb +0 -492
- data/examples/dhanhq/scanners/swing_scanner.rb +0 -247
- data/examples/dhanhq/schemas/agent_schemas.rb +0 -61
- data/examples/dhanhq/services/base_service.rb +0 -46
- data/examples/dhanhq/services/data_service.rb +0 -118
- data/examples/dhanhq/services/trading_service.rb +0 -59
- data/examples/dhanhq/technical_analysis_agentic_runner.rb +0 -411
- data/examples/dhanhq/technical_analysis_runner.rb +0 -420
- data/examples/dhanhq/test_tool_calling.rb +0 -538
- data/examples/dhanhq/test_tool_calling_verbose.rb +0 -251
- data/examples/dhanhq/utils/instrument_helper.rb +0 -32
- data/examples/dhanhq/utils/parameter_cleaner.rb +0 -28
- data/examples/dhanhq/utils/parameter_normalizer.rb +0 -45
- data/examples/dhanhq/utils/rate_limiter.rb +0 -23
- data/examples/dhanhq/utils/trading_parameter_normalizer.rb +0 -72
- data/examples/dhanhq_agent.rb +0 -964
- data/examples/dhanhq_tools.rb +0 -1663
- data/examples/multi_step_agent_with_external_data.rb +0 -368
- data/examples/structured_outputs_chat.rb +0 -72
- data/examples/structured_tools.rb +0 -89
- data/examples/test_dhanhq_tool_calling.rb +0 -375
- data/examples/test_tool_calling.rb +0 -160
- data/examples/tool_calling_direct.rb +0 -124
- data/examples/tool_calling_pattern.rb +0 -269
- data/exe/dhan_console +0 -4
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
# Complete example showing how to use structured outputs in a real workflow
|
|
5
|
-
# This demonstrates the full cycle: schema definition -> LLM call -> using the result
|
|
6
|
-
|
|
7
|
-
require "json"
|
|
8
|
-
require_relative "../lib/ollama_client"
|
|
9
|
-
|
|
10
|
-
# Example: Task Planning Agent
|
|
11
|
-
# The LLM decides what action to take, and we execute it
|
|
12
|
-
|
|
13
|
-
class TaskPlanner
|
|
14
|
-
def initialize(client:)
|
|
15
|
-
@client = client
|
|
16
|
-
@task_schema = {
|
|
17
|
-
"type" => "object",
|
|
18
|
-
"required" => ["action", "reasoning", "confidence", "next_step"],
|
|
19
|
-
"properties" => {
|
|
20
|
-
"action" => {
|
|
21
|
-
"type" => "string",
|
|
22
|
-
"description" => "The action to take",
|
|
23
|
-
"enum" => ["search", "calculate", "store", "retrieve", "finish"]
|
|
24
|
-
},
|
|
25
|
-
"reasoning" => {
|
|
26
|
-
"type" => "string",
|
|
27
|
-
"description" => "Why this action was chosen"
|
|
28
|
-
},
|
|
29
|
-
"confidence" => {
|
|
30
|
-
"type" => "number",
|
|
31
|
-
"minimum" => 0,
|
|
32
|
-
"maximum" => 1,
|
|
33
|
-
"description" => "Confidence in this decision (0.0 to 1.0, where 1.0 is 100% confident)"
|
|
34
|
-
},
|
|
35
|
-
"next_step" => {
|
|
36
|
-
"type" => "string",
|
|
37
|
-
"description" => "What to do next"
|
|
38
|
-
},
|
|
39
|
-
"parameters" => {
|
|
40
|
-
"type" => "object",
|
|
41
|
-
"description" => "Parameters needed for the action"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def plan(context:)
|
|
48
|
-
puts "🤔 Planning next action..."
|
|
49
|
-
puts "Context: #{context}\n\n"
|
|
50
|
-
|
|
51
|
-
begin
|
|
52
|
-
prompt = "Given this context: #{context}\n\n" \
|
|
53
|
-
"Decide the next action to take.\n\n" \
|
|
54
|
-
"IMPORTANT: Use decimal values for confidence " \
|
|
55
|
-
"(e.g., 0.95 for 95% confident, 0.80 for 80% confident, 1.0 for 100% confident)."
|
|
56
|
-
|
|
57
|
-
result = @client.generate(
|
|
58
|
-
prompt: prompt,
|
|
59
|
-
schema: @task_schema
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
# The result is guaranteed to match our schema
|
|
63
|
-
display_decision(result)
|
|
64
|
-
execute_action(result)
|
|
65
|
-
|
|
66
|
-
result
|
|
67
|
-
rescue Ollama::SchemaViolationError => e
|
|
68
|
-
puts "❌ Invalid response structure: #{e.message}"
|
|
69
|
-
puts " This shouldn't happen with format parameter, but we handle it gracefully"
|
|
70
|
-
nil
|
|
71
|
-
rescue Ollama::Error => e
|
|
72
|
-
puts "❌ Error: #{e.message}"
|
|
73
|
-
nil
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
private
|
|
78
|
-
|
|
79
|
-
def display_decision(result)
|
|
80
|
-
puts "📋 Decision:"
|
|
81
|
-
puts " Action: #{result['action']}"
|
|
82
|
-
puts " Reasoning: #{result['reasoning']}"
|
|
83
|
-
puts " Confidence: #{(result['confidence'] * 100).round}%"
|
|
84
|
-
puts " Next Step: #{result['next_step']}"
|
|
85
|
-
puts " Parameters: #{JSON.pretty_generate(result['parameters'] || {})}\n"
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def execute_action(result)
|
|
89
|
-
case result["action"]
|
|
90
|
-
when "search"
|
|
91
|
-
query = result.dig("parameters", "query") || "default"
|
|
92
|
-
puts "🔍 Executing search: #{query}"
|
|
93
|
-
# In real code, you'd call your search function here
|
|
94
|
-
puts " → Search results would appear here\n"
|
|
95
|
-
|
|
96
|
-
when "calculate"
|
|
97
|
-
operation = result.dig("parameters", "operation") || "unknown"
|
|
98
|
-
puts "🧮 Executing calculation: #{operation}"
|
|
99
|
-
# In real code, you'd call your calculator here
|
|
100
|
-
puts " → Calculation result would appear here\n"
|
|
101
|
-
|
|
102
|
-
when "store"
|
|
103
|
-
key = result.dig("parameters", "key") || "unknown"
|
|
104
|
-
puts "💾 Storing data with key: #{key}"
|
|
105
|
-
# In real code, you'd save to your storage
|
|
106
|
-
puts " → Data stored successfully\n"
|
|
107
|
-
|
|
108
|
-
when "retrieve"
|
|
109
|
-
key = result.dig("parameters", "key") || "unknown"
|
|
110
|
-
puts "📂 Retrieving data with key: #{key}"
|
|
111
|
-
# In real code, you'd fetch from your storage
|
|
112
|
-
puts " → Data retrieved successfully\n"
|
|
113
|
-
|
|
114
|
-
when "finish"
|
|
115
|
-
puts "✅ Task complete!\n"
|
|
116
|
-
|
|
117
|
-
else
|
|
118
|
-
puts "⚠️ Unknown action: #{result['action']}\n"
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# Example: Data Analyzer
|
|
124
|
-
# The LLM analyzes data and returns structured insights
|
|
125
|
-
|
|
126
|
-
class DataAnalyzer
|
|
127
|
-
def initialize(client:)
|
|
128
|
-
@client = client
|
|
129
|
-
@analysis_schema = {
|
|
130
|
-
"type" => "object",
|
|
131
|
-
"required" => ["summary", "confidence", "key_points"],
|
|
132
|
-
"properties" => {
|
|
133
|
-
"summary" => {
|
|
134
|
-
"type" => "string",
|
|
135
|
-
"description" => "Brief summary of the analysis"
|
|
136
|
-
},
|
|
137
|
-
"confidence" => {
|
|
138
|
-
"type" => "number",
|
|
139
|
-
"minimum" => 0,
|
|
140
|
-
"maximum" => 1,
|
|
141
|
-
"description" => "Confidence level (0.0 to 1.0, where 1.0 is 100% confident)"
|
|
142
|
-
},
|
|
143
|
-
"key_points" => {
|
|
144
|
-
"type" => "array",
|
|
145
|
-
"items" => { "type" => "string" },
|
|
146
|
-
"minItems" => 1,
|
|
147
|
-
"maxItems" => 5
|
|
148
|
-
},
|
|
149
|
-
"sentiment" => {
|
|
150
|
-
"type" => "string",
|
|
151
|
-
"enum" => ["positive", "neutral", "negative"]
|
|
152
|
-
},
|
|
153
|
-
"recommendations" => {
|
|
154
|
-
"type" => "array",
|
|
155
|
-
"items" => { "type" => "string" }
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def analyze(data:)
|
|
162
|
-
puts "📊 Analyzing data..."
|
|
163
|
-
puts "Data: #{data}\n\n"
|
|
164
|
-
|
|
165
|
-
begin
|
|
166
|
-
prompt = "Analyze this data and provide insights: #{data}\n\n" \
|
|
167
|
-
"IMPORTANT: Express confidence as a decimal between 0.0 and 1.0 " \
|
|
168
|
-
"(e.g., 0.85 for 85% confidence, not 85)."
|
|
169
|
-
|
|
170
|
-
result = @client.generate(
|
|
171
|
-
prompt: prompt,
|
|
172
|
-
schema: @analysis_schema
|
|
173
|
-
)
|
|
174
|
-
|
|
175
|
-
display_analysis(result)
|
|
176
|
-
make_recommendations(result)
|
|
177
|
-
|
|
178
|
-
result
|
|
179
|
-
rescue Ollama::Error => e
|
|
180
|
-
puts "❌ Error: #{e.message}"
|
|
181
|
-
nil
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
private
|
|
186
|
-
|
|
187
|
-
def display_analysis(result)
|
|
188
|
-
puts "📈 Analysis Results:"
|
|
189
|
-
puts " Summary: #{result['summary']}"
|
|
190
|
-
puts " Confidence: #{(result['confidence'] * 100).round}%"
|
|
191
|
-
puts " Sentiment: #{result['sentiment']}"
|
|
192
|
-
puts "\n Key Points:"
|
|
193
|
-
result["key_points"].each_with_index do |point, i|
|
|
194
|
-
puts " #{i + 1}. #{point}"
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
if result["recommendations"] && !result["recommendations"].empty?
|
|
198
|
-
puts "\n Recommendations:"
|
|
199
|
-
result["recommendations"].each_with_index do |rec, i|
|
|
200
|
-
puts " #{i + 1}. #{rec}"
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
puts
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
def make_recommendations(result)
|
|
207
|
-
if result["confidence"] > 0.8 && result["sentiment"] == "positive"
|
|
208
|
-
puts "✅ High confidence positive analysis - safe to proceed"
|
|
209
|
-
elsif result["confidence"] < 0.5
|
|
210
|
-
puts "⚠️ Low confidence - manual review recommended"
|
|
211
|
-
elsif result["sentiment"] == "negative"
|
|
212
|
-
puts "⚠️ Negative sentiment detected - investigate further"
|
|
213
|
-
end
|
|
214
|
-
puts
|
|
215
|
-
end
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
# Main execution
|
|
219
|
-
if __FILE__ == $PROGRAM_NAME
|
|
220
|
-
client = Ollama::Client.new
|
|
221
|
-
|
|
222
|
-
puts "=" * 60
|
|
223
|
-
puts "Example 1: Task Planning Agent"
|
|
224
|
-
puts "=" * 60
|
|
225
|
-
puts
|
|
226
|
-
|
|
227
|
-
planner = TaskPlanner.new(client: client)
|
|
228
|
-
planner.plan(context: "User wants to know the weather in Paris")
|
|
229
|
-
|
|
230
|
-
puts "\n" + "=" * 60
|
|
231
|
-
puts "Example 2: Data Analysis"
|
|
232
|
-
puts "=" * 60
|
|
233
|
-
puts
|
|
234
|
-
|
|
235
|
-
analyzer = DataAnalyzer.new(client: client)
|
|
236
|
-
analyzer.analyze(
|
|
237
|
-
data: "Sales increased 25% this quarter. Customer satisfaction is at 4.8/5. " \
|
|
238
|
-
"Revenue: $1.2M. New customers: 150."
|
|
239
|
-
)
|
|
240
|
-
|
|
241
|
-
puts "=" * 60
|
|
242
|
-
puts "Examples complete!"
|
|
243
|
-
puts "=" * 60
|
|
244
|
-
end
|
|
245
|
-
|