ollama-client 0.2.5 → 0.2.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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +138 -76
  4. data/docs/EXAMPLE_REORGANIZATION.md +412 -0
  5. data/docs/GETTING_STARTED.md +361 -0
  6. data/docs/INTEGRATION_TESTING.md +170 -0
  7. data/docs/NEXT_STEPS_SUMMARY.md +114 -0
  8. data/docs/PERSONAS.md +383 -0
  9. data/docs/QUICK_START.md +195 -0
  10. data/docs/TESTING.md +392 -170
  11. data/docs/TEST_CHECKLIST.md +450 -0
  12. data/examples/README.md +51 -66
  13. data/examples/basic_chat.rb +33 -0
  14. data/examples/basic_generate.rb +29 -0
  15. data/examples/tool_calling_parsing.rb +59 -0
  16. data/exe/ollama-client +128 -1
  17. data/lib/ollama/agent/planner.rb +7 -2
  18. data/lib/ollama/chat_session.rb +101 -0
  19. data/lib/ollama/client.rb +41 -35
  20. data/lib/ollama/config.rb +4 -1
  21. data/lib/ollama/document_loader.rb +1 -1
  22. data/lib/ollama/embeddings.rb +41 -26
  23. data/lib/ollama/errors.rb +1 -0
  24. data/lib/ollama/personas.rb +287 -0
  25. data/lib/ollama/version.rb +1 -1
  26. data/lib/ollama_client.rb +7 -0
  27. metadata +14 -48
  28. data/examples/advanced_complex_schemas.rb +0 -366
  29. data/examples/advanced_edge_cases.rb +0 -241
  30. data/examples/advanced_error_handling.rb +0 -200
  31. data/examples/advanced_multi_step_agent.rb +0 -341
  32. data/examples/advanced_performance_testing.rb +0 -186
  33. data/examples/chat_console.rb +0 -143
  34. data/examples/complete_workflow.rb +0 -245
  35. data/examples/dhan_console.rb +0 -843
  36. data/examples/dhanhq/README.md +0 -236
  37. data/examples/dhanhq/agents/base_agent.rb +0 -74
  38. data/examples/dhanhq/agents/data_agent.rb +0 -66
  39. data/examples/dhanhq/agents/orchestrator_agent.rb +0 -120
  40. data/examples/dhanhq/agents/technical_analysis_agent.rb +0 -252
  41. data/examples/dhanhq/agents/trading_agent.rb +0 -81
  42. data/examples/dhanhq/analysis/market_structure.rb +0 -138
  43. data/examples/dhanhq/analysis/pattern_recognizer.rb +0 -192
  44. data/examples/dhanhq/analysis/trend_analyzer.rb +0 -88
  45. data/examples/dhanhq/builders/market_context_builder.rb +0 -67
  46. data/examples/dhanhq/dhanhq_agent.rb +0 -829
  47. data/examples/dhanhq/indicators/technical_indicators.rb +0 -158
  48. data/examples/dhanhq/scanners/intraday_options_scanner.rb +0 -492
  49. data/examples/dhanhq/scanners/swing_scanner.rb +0 -247
  50. data/examples/dhanhq/schemas/agent_schemas.rb +0 -61
  51. data/examples/dhanhq/services/base_service.rb +0 -46
  52. data/examples/dhanhq/services/data_service.rb +0 -118
  53. data/examples/dhanhq/services/trading_service.rb +0 -59
  54. data/examples/dhanhq/technical_analysis_agentic_runner.rb +0 -411
  55. data/examples/dhanhq/technical_analysis_runner.rb +0 -420
  56. data/examples/dhanhq/test_tool_calling.rb +0 -538
  57. data/examples/dhanhq/test_tool_calling_verbose.rb +0 -251
  58. data/examples/dhanhq/utils/instrument_helper.rb +0 -32
  59. data/examples/dhanhq/utils/parameter_cleaner.rb +0 -28
  60. data/examples/dhanhq/utils/parameter_normalizer.rb +0 -45
  61. data/examples/dhanhq/utils/rate_limiter.rb +0 -23
  62. data/examples/dhanhq/utils/trading_parameter_normalizer.rb +0 -72
  63. data/examples/dhanhq_agent.rb +0 -964
  64. data/examples/dhanhq_tools.rb +0 -1663
  65. data/examples/multi_step_agent_with_external_data.rb +0 -368
  66. data/examples/structured_outputs_chat.rb +0 -72
  67. data/examples/structured_tools.rb +0 -89
  68. data/examples/test_dhanhq_tool_calling.rb +0 -375
  69. data/examples/test_tool_calling.rb +0 -160
  70. data/examples/tool_calling_direct.rb +0 -124
  71. data/examples/tool_calling_pattern.rb +0 -269
  72. data/exe/dhan_console +0 -4
@@ -0,0 +1,287 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ollama
4
+ # Persona system for explicit, contextual personalization.
5
+ #
6
+ # Personas are NOT baked into models or server config. They are injected
7
+ # explicitly at the system/prompt layer, allowing you to:
8
+ #
9
+ # - Use compressed versions for schema-based agent work (deterministic)
10
+ # - Use minimal chat-safe versions for chat/streaming UI work (human-facing)
11
+ # - Switch personas per task without model changes
12
+ # - Maintain multiple personas for different contexts
13
+ #
14
+ # This is architecturally superior to ChatGPT's implicit global personalization.
15
+ #
16
+ # ## Persona Variants
17
+ #
18
+ # Each persona has two variants:
19
+ #
20
+ # ### Agent Variants (`:agent`)
21
+ # - Designed for `/api/generate` with JSON schemas
22
+ # - Minimal, directive, non-chatty
23
+ # - Preserves determinism in structured outputs
24
+ # - No markdown, no explanations, no extra fields
25
+ # - Use with Planner, structured extraction, decision engines
26
+ #
27
+ # ### Chat Variants (`:chat`)
28
+ # - Designed for `/api/chat` with ChatSession
29
+ # - Minimal, chat-safe, allows explanations
30
+ # - Explicitly disclaims authority and side effects
31
+ # - Allows streaming and markdown for presentation
32
+ # - Use ONLY for human-facing chat interfaces
33
+ # - Must NEVER be used for schema-based agent work
34
+ #
35
+ # ## Critical Separation
36
+ #
37
+ # - Agent personas: `/api/generate` + schemas = deterministic reasoning
38
+ # - Chat personas: `/api/chat` + humans = explanatory conversation
39
+ #
40
+ # Mixing them breaks determinism and safety boundaries.
41
+ # rubocop:disable Metrics/ModuleLength
42
+ module Personas
43
+ # Minimal agent-safe persona for schema-based planning and structured outputs.
44
+ #
45
+ # This version is:
46
+ # - Minimal and direct (no verbosity)
47
+ # - Focused on correctness and invariants
48
+ # - No chatty behavior or markdown drift
49
+ # - Preserves determinism in structured outputs
50
+ # - Designed for /api/generate, schema-validated, deterministic workflows
51
+ #
52
+ # This prompt turns the LLM into a deterministic reasoning subroutine,
53
+ # not a conversational partner. Use for planners, routers, decision engines.
54
+ ARCHITECT_AGENT = <<~PROMPT
55
+ You are acting as a senior software architect and system designer.
56
+
57
+ Operating rules:
58
+ - Optimize for correctness and robustness first.
59
+ - Make explicit decisions; do not hedge.
60
+ - Do not invent data, APIs, or system behavior.
61
+ - If required information is missing, state it clearly.
62
+ - Treat the LLM as a reasoning component, not an authority.
63
+ - Never assume side effects; propose intent only.
64
+
65
+ Output rules:
66
+ - Output MUST conform exactly to the provided JSON schema.
67
+ - Do not include markdown, explanations, or extra fields.
68
+ - Use deterministic reasoning; avoid creative variation.
69
+ - Prefer simple, explicit solutions over clever ones.
70
+
71
+ Focus areas:
72
+ - System boundaries and invariants
73
+ - Failure modes and edge cases
74
+ - Production-grade architecture decisions
75
+ PROMPT
76
+
77
+ # Minimal chat-safe persona for human-facing chat interfaces.
78
+ #
79
+ # This version:
80
+ # - Allows explanations and examples (chat needs)
81
+ # - Allows streaming (presentation needs)
82
+ # - Still prevents hallucination (safety)
83
+ # - Explicitly disclaims authority (boundaries)
84
+ # - Never implies side effects (safety)
85
+ #
86
+ # Designed for ChatSession, /api/chat, streaming, human-facing interactions.
87
+ # Must NEVER be used for schema-based agent work.
88
+ ARCHITECT_CHAT = <<~PROMPT
89
+ You are a senior software architect and systems engineer.
90
+
91
+ You are interacting with a human in a conversational interface.
92
+
93
+ Guidelines:
94
+ - Be clear, direct, and technically precise.
95
+ - Explain reasoning when it helps understanding.
96
+ - Avoid unnecessary verbosity or motivational language.
97
+ - Do not invent APIs, data, or system behavior.
98
+ - If information is missing, say so explicitly.
99
+ - Prefer concrete examples over abstract theory.
100
+
101
+ Boundaries:
102
+ - You do not execute actions or side effects.
103
+ - You provide explanations, guidance, and reasoning only.
104
+ - Decisions that affect systems must be validated externally.
105
+
106
+ Tone:
107
+ - Professional, calm, and no-nonsense.
108
+ - Assume the user has strong technical background.
109
+ PROMPT
110
+
111
+ # Minimal agent-safe persona for trading/analysis work.
112
+ #
113
+ # Designed for /api/generate, schema-validated, deterministic workflows.
114
+ # This prompt turns the LLM into a deterministic reasoning subroutine
115
+ # for market analysis, risk assessment, and trading decisions.
116
+ TRADING_AGENT = <<~PROMPT
117
+ You are acting as a quantitative trading system analyst.
118
+
119
+ Operating rules:
120
+ - Optimize for data accuracy and risk assessment first.
121
+ - Make explicit decisions based on provided data only.
122
+ - Do not invent market data, prices, or indicators.
123
+ - If required information is missing, state it clearly.
124
+ - Treat the LLM as a reasoning component, not an authority.
125
+ - Never assume market behavior; base analysis on data only.
126
+
127
+ Output rules:
128
+ - Output MUST conform exactly to the provided JSON schema.
129
+ - Do not include markdown, explanations, or extra fields.
130
+ - Use deterministic reasoning; avoid creative variation.
131
+ - Prefer explicit risk statements over predictions.
132
+
133
+ Focus areas:
134
+ - Risk management and edge cases
135
+ - Data-driven analysis without emotional bias
136
+ - Objective assessment of market conditions
137
+ PROMPT
138
+
139
+ # Minimal chat-safe persona for trading chat interfaces.
140
+ #
141
+ # This version:
142
+ # - Allows explanations and examples (chat needs)
143
+ # - Allows streaming (presentation needs)
144
+ # - Still prevents hallucination (safety)
145
+ # - Explicitly disclaims authority (boundaries)
146
+ # - Never implies side effects (safety)
147
+ #
148
+ # Designed for ChatSession, /api/chat, streaming, human-facing interactions.
149
+ # Must NEVER be used for schema-based agent work.
150
+ TRADING_CHAT = <<~PROMPT
151
+ You are a quantitative trading system analyst.
152
+
153
+ You are interacting with a human in a conversational interface.
154
+
155
+ Guidelines:
156
+ - Be clear, direct, and data-focused.
157
+ - Explain analysis when it helps understanding.
158
+ - Avoid predictions, guarantees, or emotional language.
159
+ - Do not invent market data, prices, or indicators.
160
+ - If information is missing, say so explicitly.
161
+ - Prefer concrete data examples over abstract theory.
162
+
163
+ Boundaries:
164
+ - You do not execute trades or market actions.
165
+ - You provide analysis, guidance, and reasoning only.
166
+ - Trading decisions must be validated externally.
167
+
168
+ Tone:
169
+ - Professional, objective, and risk-aware.
170
+ - Assume the user understands market fundamentals.
171
+ PROMPT
172
+
173
+ # Minimal agent-safe persona for code review work.
174
+ #
175
+ # Designed for /api/generate, schema-validated, deterministic workflows.
176
+ # This prompt turns the LLM into a deterministic reasoning subroutine
177
+ # for code quality assessment and refactoring decisions.
178
+ REVIEWER_AGENT = <<~PROMPT
179
+ You are acting as a code review assistant focused on maintainability and correctness.
180
+
181
+ Operating rules:
182
+ - Optimize for code clarity and maintainability first.
183
+ - Make explicit decisions about code quality issues.
184
+ - Do not invent code patterns or assume implementation details.
185
+ - If required information is missing, state it clearly.
186
+ - Treat the LLM as a reasoning component, not an authority.
187
+ - Never assume intent; identify issues from code structure only.
188
+
189
+ Output rules:
190
+ - Output MUST conform exactly to the provided JSON schema.
191
+ - Do not include markdown, explanations, or extra fields.
192
+ - Use deterministic reasoning; avoid creative variation.
193
+ - Prefer explicit refactoring suggestions over general advice.
194
+
195
+ Focus areas:
196
+ - Unclear names, long methods, hidden responsibilities
197
+ - Single responsibility and testability
198
+ - Unnecessary complexity and code smells
199
+ PROMPT
200
+
201
+ # Minimal chat-safe persona for code review chat interfaces.
202
+ #
203
+ # This version:
204
+ # - Allows explanations and examples (chat needs)
205
+ # - Allows streaming (presentation needs)
206
+ # - Still prevents hallucination (safety)
207
+ # - Explicitly disclaims authority (boundaries)
208
+ # - Never implies side effects (safety)
209
+ #
210
+ # Designed for ChatSession, /api/chat, streaming, human-facing interactions.
211
+ # Must NEVER be used for schema-based agent work.
212
+ REVIEWER_CHAT = <<~PROMPT
213
+ You are a code review assistant focused on maintainability and correctness.
214
+
215
+ You are interacting with a human in a conversational interface.
216
+
217
+ Guidelines:
218
+ - Be clear, direct, and technically precise.
219
+ - Explain code quality issues when it helps understanding.
220
+ - Avoid unnecessary verbosity or motivational language.
221
+ - Do not invent code patterns or assume implementation details.
222
+ - If information is missing, say so explicitly.
223
+ - Prefer concrete refactoring examples over abstract principles.
224
+
225
+ Boundaries:
226
+ - You do not modify code or execute refactorings.
227
+ - You provide review, guidance, and suggestions only.
228
+ - Code changes must be validated externally.
229
+
230
+ Tone:
231
+ - Professional, constructive, and no-nonsense.
232
+ - Assume the user values code quality and maintainability.
233
+ PROMPT
234
+
235
+ # Registry of all available personas.
236
+ #
237
+ # Each persona has two variants:
238
+ # - `:agent` - Minimal version for schema-based agent work (/api/generate)
239
+ # - `:chat` - Minimal chat-safe version for human-facing interfaces (/api/chat)
240
+ #
241
+ # IMPORTANT: Chat personas must NEVER be used for schema-based agent work.
242
+ # They are designed for ChatSession and streaming only.
243
+ REGISTRY = {
244
+ architect: {
245
+ agent: ARCHITECT_AGENT,
246
+ chat: ARCHITECT_CHAT
247
+ },
248
+ trading: {
249
+ agent: TRADING_AGENT,
250
+ chat: TRADING_CHAT
251
+ },
252
+ reviewer: {
253
+ agent: REVIEWER_AGENT,
254
+ chat: REVIEWER_CHAT
255
+ }
256
+ }.freeze
257
+
258
+ # Get a persona by name and variant.
259
+ #
260
+ # @param name [Symbol] Persona name (:architect, :trading, :reviewer)
261
+ # @param variant [Symbol] Variant (:agent or :chat)
262
+ # @return [String, nil] Persona prompt text, or nil if not found
263
+ #
264
+ # @example
265
+ # Personas.get(:architect, :agent) # => Compressed agent version
266
+ # Personas.get(:architect, :chat) # => Full chat version
267
+ def self.get(name, variant: :agent)
268
+ REGISTRY.dig(name.to_sym, variant.to_sym)
269
+ end
270
+
271
+ # List all available persona names.
272
+ #
273
+ # @return [Array<Symbol>] List of persona names
274
+ def self.available
275
+ REGISTRY.keys
276
+ end
277
+
278
+ # Check if a persona exists.
279
+ #
280
+ # @param name [Symbol, String] Persona name
281
+ # @return [Boolean] True if persona exists
282
+ def self.exists?(name)
283
+ REGISTRY.key?(name.to_sym)
284
+ end
285
+ end
286
+ # rubocop:enable Metrics/ModuleLength
287
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ollama
4
- VERSION = "0.2.5"
4
+ VERSION = "0.2.6"
5
5
  end
data/lib/ollama_client.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Load .env file if available (.env takes precedence over shell environment variables)
4
+ require "dotenv"
5
+ Dotenv.overload
6
+
7
+ require_relative "ollama/version"
3
8
  require_relative "ollama/config"
4
9
  require_relative "ollama/errors"
5
10
  require_relative "ollama/schema_validator"
@@ -9,9 +14,11 @@ require_relative "ollama/tool"
9
14
  require_relative "ollama/client"
10
15
  require_relative "ollama/document_loader"
11
16
  require_relative "ollama/streaming_observer"
17
+ require_relative "ollama/chat_session"
12
18
  require_relative "ollama/agent/messages"
13
19
  require_relative "ollama/agent/planner"
14
20
  require_relative "ollama/agent/executor"
21
+ require_relative "ollama/personas"
15
22
 
16
23
  # Main entry point for OllamaClient gem
17
24
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ollama-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shubham Taywade
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-01-21 00:00:00.000000000 Z
11
+ date: 2026-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bigdecimal
@@ -60,7 +60,6 @@ description: A production-ready, agent-first Ruby client for the Ollama API with
60
60
  email:
61
61
  - shubhamtaywade82@gmail.com
62
62
  executables:
63
- - dhan_console
64
63
  - ollama-client
65
64
  extensions: []
66
65
  extra_rdoc_files: []
@@ -73,66 +72,32 @@ files:
73
72
  - Rakefile
74
73
  - docs/CLOUD.md
75
74
  - docs/CONSOLE_IMPROVEMENTS.md
75
+ - docs/EXAMPLE_REORGANIZATION.md
76
76
  - docs/FEATURES_ADDED.md
77
+ - docs/GETTING_STARTED.md
77
78
  - docs/HANDLERS_ANALYSIS.md
79
+ - docs/INTEGRATION_TESTING.md
80
+ - docs/NEXT_STEPS_SUMMARY.md
81
+ - docs/PERSONAS.md
78
82
  - docs/PRODUCTION_FIXES.md
83
+ - docs/QUICK_START.md
79
84
  - docs/README.md
80
85
  - docs/RELEASE_GUIDE.md
81
86
  - docs/SCHEMA_FIXES.md
82
87
  - docs/TESTING.md
88
+ - docs/TEST_CHECKLIST.md
83
89
  - docs/TEST_UPDATES.md
84
90
  - docs/ruby_guide.md
85
91
  - examples/README.md
86
- - examples/advanced_complex_schemas.rb
87
- - examples/advanced_edge_cases.rb
88
- - examples/advanced_error_handling.rb
89
- - examples/advanced_multi_step_agent.rb
90
- - examples/advanced_performance_testing.rb
91
- - examples/chat_console.rb
92
- - examples/complete_workflow.rb
93
- - examples/dhan_console.rb
94
- - examples/dhanhq/README.md
95
- - examples/dhanhq/agents/base_agent.rb
96
- - examples/dhanhq/agents/data_agent.rb
97
- - examples/dhanhq/agents/orchestrator_agent.rb
98
- - examples/dhanhq/agents/technical_analysis_agent.rb
99
- - examples/dhanhq/agents/trading_agent.rb
100
- - examples/dhanhq/analysis/market_structure.rb
101
- - examples/dhanhq/analysis/pattern_recognizer.rb
102
- - examples/dhanhq/analysis/trend_analyzer.rb
103
- - examples/dhanhq/builders/market_context_builder.rb
104
- - examples/dhanhq/dhanhq_agent.rb
105
- - examples/dhanhq/indicators/technical_indicators.rb
106
- - examples/dhanhq/scanners/intraday_options_scanner.rb
107
- - examples/dhanhq/scanners/swing_scanner.rb
108
- - examples/dhanhq/schemas/agent_schemas.rb
109
- - examples/dhanhq/services/base_service.rb
110
- - examples/dhanhq/services/data_service.rb
111
- - examples/dhanhq/services/trading_service.rb
112
- - examples/dhanhq/technical_analysis_agentic_runner.rb
113
- - examples/dhanhq/technical_analysis_runner.rb
114
- - examples/dhanhq/test_tool_calling.rb
115
- - examples/dhanhq/test_tool_calling_verbose.rb
116
- - examples/dhanhq/utils/instrument_helper.rb
117
- - examples/dhanhq/utils/parameter_cleaner.rb
118
- - examples/dhanhq/utils/parameter_normalizer.rb
119
- - examples/dhanhq/utils/rate_limiter.rb
120
- - examples/dhanhq/utils/trading_parameter_normalizer.rb
121
- - examples/dhanhq_agent.rb
122
- - examples/dhanhq_tools.rb
123
- - examples/multi_step_agent_with_external_data.rb
124
- - examples/structured_outputs_chat.rb
125
- - examples/structured_tools.rb
126
- - examples/test_dhanhq_tool_calling.rb
127
- - examples/test_tool_calling.rb
128
- - examples/tool_calling_direct.rb
129
- - examples/tool_calling_pattern.rb
92
+ - examples/basic_chat.rb
93
+ - examples/basic_generate.rb
94
+ - examples/tool_calling_parsing.rb
130
95
  - examples/tool_dto_example.rb
131
- - exe/dhan_console
132
96
  - exe/ollama-client
133
97
  - lib/ollama/agent/executor.rb
134
98
  - lib/ollama/agent/messages.rb
135
99
  - lib/ollama/agent/planner.rb
100
+ - lib/ollama/chat_session.rb
136
101
  - lib/ollama/client.rb
137
102
  - lib/ollama/config.rb
138
103
  - lib/ollama/document_loader.rb
@@ -140,6 +105,7 @@ files:
140
105
  - lib/ollama/embeddings.rb
141
106
  - lib/ollama/errors.rb
142
107
  - lib/ollama/options.rb
108
+ - lib/ollama/personas.rb
143
109
  - lib/ollama/response.rb
144
110
  - lib/ollama/schema_validator.rb
145
111
  - lib/ollama/schemas/base.json