ollama-client 0.2.2 → 0.2.3
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 +8 -0
- data/README.md +7 -1
- data/docs/CLOUD.md +29 -0
- data/docs/CONSOLE_IMPROVEMENTS.md +256 -0
- data/docs/README.md +37 -0
- data/docs/SCHEMA_FIXES.md +147 -0
- data/docs/TEST_UPDATES.md +107 -0
- data/examples/README.md +92 -0
- data/examples/advanced_complex_schemas.rb +6 -3
- data/examples/advanced_multi_step_agent.rb +2 -1
- data/examples/chat_console.rb +12 -3
- data/examples/complete_workflow.rb +14 -4
- data/examples/dhan_console.rb +103 -8
- data/examples/dhanhq/agents/technical_analysis_agent.rb +6 -1
- data/examples/dhanhq/schemas/agent_schemas.rb +2 -2
- data/examples/dhanhq_agent.rb +23 -13
- data/examples/dhanhq_tools.rb +311 -246
- data/examples/multi_step_agent_with_external_data.rb +368 -0
- data/{test_dhanhq_tool_calling.rb → examples/test_dhanhq_tool_calling.rb} +99 -6
- data/lib/ollama/agent/executor.rb +30 -30
- data/lib/ollama/client.rb +73 -80
- data/lib/ollama/dto.rb +7 -7
- data/lib/ollama/options.rb +17 -9
- data/lib/ollama/response.rb +4 -6
- data/lib/ollama/tool/function/parameters.rb +1 -0
- data/lib/ollama/version.rb +1 -1
- metadata +14 -7
- /data/{FEATURES_ADDED.md → docs/FEATURES_ADDED.md} +0 -0
- /data/{HANDLERS_ANALYSIS.md → docs/HANDLERS_ANALYSIS.md} +0 -0
- /data/{PRODUCTION_FIXES.md → docs/PRODUCTION_FIXES.md} +0 -0
- /data/{TESTING.md → docs/TESTING.md} +0 -0
- /data/{test_tool_calling.rb → examples/test_tool_calling.rb} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 908909c57f4d7067168bcdcecce27471ea2587d6452aecb68aca2c25a8547839
|
|
4
|
+
data.tar.gz: fcbf8ee83cba0f05bcae0892e103ae1201a7db1b045c25848caf0d8a71ca891d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 67800e85b23a59fd9717ec76a2d27a591538d1813846213cb095d853d41547d6da3bbb10b8096a05b500bec66576a2e0f9268a5ad8738a9c0176b8f2051a99eb
|
|
7
|
+
data.tar.gz: 1bb186cb330c6fec601ed909af0fa9ef9bee786827edeb9195955ed25e7d0e8ab1d2eb81c302e47806cf304014ad847c207cc05f7b881392f936413419158714
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
- Add tag-triggered GitHub Actions release workflow for RubyGems publishing.
|
|
4
|
+
|
|
5
|
+
## [0.2.3] - 2026-01-17
|
|
6
|
+
|
|
7
|
+
- Add per-call `model:` override for `Ollama::Client#generate`.
|
|
8
|
+
- Document `generate` model override usage in README.
|
|
9
|
+
- Add spec to cover per-call `model:` in 404 error path.
|
|
10
|
+
|
|
3
11
|
## [0.2.0] - 2026-01-12
|
|
4
12
|
|
|
5
13
|
- Add `Ollama::Agent::Planner` (stateless `/api/generate`)
|
data/README.md
CHANGED
|
@@ -287,6 +287,7 @@ schema = {
|
|
|
287
287
|
# 2. Call the LLM with your schema
|
|
288
288
|
begin
|
|
289
289
|
result = client.generate(
|
|
290
|
+
model: "llama3.1:8b",
|
|
290
291
|
prompt: "Your prompt here",
|
|
291
292
|
schema: schema
|
|
292
293
|
)
|
|
@@ -877,7 +878,12 @@ ruby examples/advanced_multi_step_agent.rb
|
|
|
877
878
|
|
|
878
879
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
879
880
|
|
|
880
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
881
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
882
|
+
|
|
883
|
+
To release a new version, update `lib/ollama/version.rb` and `CHANGELOG.md`, then commit. You can:
|
|
884
|
+
|
|
885
|
+
- Run `bundle exec rake release` locally to create the tag, push commits/tags, and publish to [rubygems.org](https://rubygems.org).
|
|
886
|
+
- Push a tag `vX.Y.Z` to trigger the GitHub Actions release workflow, which builds and publishes the gem using the `RUBYGEMS_API_KEY` secret.
|
|
881
887
|
|
|
882
888
|
## Contributing
|
|
883
889
|
|
data/docs/CLOUD.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Cloud Agent Guide
|
|
2
|
+
|
|
3
|
+
This repository is a Ruby gem. It has no database and does not require
|
|
4
|
+
application secrets for the default test suite.
|
|
5
|
+
|
|
6
|
+
## Required Commands
|
|
7
|
+
- `bundle install`
|
|
8
|
+
- `bundle exec rubocop`
|
|
9
|
+
- `bundle exec rspec`
|
|
10
|
+
|
|
11
|
+
## Agent Prompt Template
|
|
12
|
+
You are operating on a Ruby gem repository.
|
|
13
|
+
Task:
|
|
14
|
+
1. Run `bundle exec rubocop`.
|
|
15
|
+
2. Fix all RuboCop offenses.
|
|
16
|
+
3. Re-run RuboCop until clean.
|
|
17
|
+
4. Run `bundle exec rspec`.
|
|
18
|
+
5. Fix all failing specs.
|
|
19
|
+
6. Re-run RSpec until green.
|
|
20
|
+
|
|
21
|
+
Rules:
|
|
22
|
+
- Do not skip failures.
|
|
23
|
+
- Do not change public APIs without reporting.
|
|
24
|
+
- Do not bump gem version unless explicitly told.
|
|
25
|
+
- Stop if blocked and explain why.
|
|
26
|
+
|
|
27
|
+
## Guardrails
|
|
28
|
+
- Keep API surface stable and backward compatible.
|
|
29
|
+
- Update specs when behavior changes.
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# Console Improvements
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Enhanced the interactive console experiences (`chat_console.rb` and `dhan_console.rb`) to provide better user feedback and cleaner output formatting.
|
|
6
|
+
|
|
7
|
+
## Chat Console (`chat_console.rb`)
|
|
8
|
+
|
|
9
|
+
### Problem
|
|
10
|
+
|
|
11
|
+
When the LLM was processing a response, the `llm>` prompt appeared immediately, making it look like it was waiting for user input. This caused confusion where users would start typing, thinking it was a prompt.
|
|
12
|
+
|
|
13
|
+
### Solution
|
|
14
|
+
|
|
15
|
+
Added a **thinking indicator** that shows while waiting for the API response:
|
|
16
|
+
|
|
17
|
+
**Before:**
|
|
18
|
+
```
|
|
19
|
+
you> Hi
|
|
20
|
+
llm> [cursor blinks here - looks like a prompt!]
|
|
21
|
+
[user types something]
|
|
22
|
+
[then response appears]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**After:**
|
|
26
|
+
```
|
|
27
|
+
you> Hi
|
|
28
|
+
... [thinking indicator in cyan]
|
|
29
|
+
llm> Hey! How can I help you?
|
|
30
|
+
you> [clear prompt for next input]
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Implementation
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
def chat_response(client, messages, config)
|
|
37
|
+
content = +""
|
|
38
|
+
prompt_printed = false
|
|
39
|
+
|
|
40
|
+
# Show thinking indicator
|
|
41
|
+
print "#{COLOR_LLM}...#{COLOR_RESET}"
|
|
42
|
+
$stdout.flush
|
|
43
|
+
|
|
44
|
+
client.chat_raw(...) do |chunk|
|
|
45
|
+
token = chunk.dig("message", "content").to_s
|
|
46
|
+
next if token.empty?
|
|
47
|
+
|
|
48
|
+
# Replace thinking indicator with llm> on first token
|
|
49
|
+
unless prompt_printed
|
|
50
|
+
print "\r#{LLM_PROMPT}"
|
|
51
|
+
prompt_printed = true
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
content << token
|
|
55
|
+
print token
|
|
56
|
+
$stdout.flush
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
puts
|
|
60
|
+
content
|
|
61
|
+
end
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Key Changes:**
|
|
65
|
+
- `\r` (carriage return) replaces `...` with `llm>` when first token arrives
|
|
66
|
+
- `$stdout.flush` ensures immediate visual feedback
|
|
67
|
+
- Clear visual state: thinking → responding → ready for input
|
|
68
|
+
|
|
69
|
+
## DhanHQ Console (`dhan_console.rb`)
|
|
70
|
+
|
|
71
|
+
### Problem
|
|
72
|
+
|
|
73
|
+
Tool results were displayed as raw JSON dumps, making it hard to quickly understand:
|
|
74
|
+
- **Which tool** was called
|
|
75
|
+
- **What data** was retrieved
|
|
76
|
+
- **Key information** from the response
|
|
77
|
+
|
|
78
|
+
**Before:**
|
|
79
|
+
```
|
|
80
|
+
Tool Results:
|
|
81
|
+
- get_live_ltp
|
|
82
|
+
{
|
|
83
|
+
"action": "get_live_ltp",
|
|
84
|
+
"params": {
|
|
85
|
+
"security_id": "13",
|
|
86
|
+
"symbol": "NIFTY",
|
|
87
|
+
"exchange_segment": "IDX_I"
|
|
88
|
+
},
|
|
89
|
+
"result": {
|
|
90
|
+
"security_id": "13",
|
|
91
|
+
"exchange_segment": "IDX_I",
|
|
92
|
+
"ltp": 25694.35,
|
|
93
|
+
"ltp_data": {
|
|
94
|
+
"last_price": 25694.35
|
|
95
|
+
},
|
|
96
|
+
"symbol": "NIFTY"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Solution
|
|
102
|
+
|
|
103
|
+
Implemented **formatted, human-readable tool results** that extract and display key information:
|
|
104
|
+
|
|
105
|
+
**After:**
|
|
106
|
+
```
|
|
107
|
+
🔧 Tool Called: get_live_ltp
|
|
108
|
+
→ NIFTY (IDX_I)
|
|
109
|
+
→ Last Price: ₹25694.35
|
|
110
|
+
|
|
111
|
+
llm> The current price of NIFTY is 25694.35.
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Formatted Output by Tool
|
|
115
|
+
|
|
116
|
+
#### 1. Live LTP (`get_live_ltp`)
|
|
117
|
+
```
|
|
118
|
+
🔧 Tool Called: get_live_ltp
|
|
119
|
+
→ NIFTY (IDX_I)
|
|
120
|
+
→ Last Price: ₹25694.35
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### 2. Market Quote (`get_market_quote`)
|
|
124
|
+
```
|
|
125
|
+
🔧 Tool Called: get_market_quote
|
|
126
|
+
→ RELIANCE
|
|
127
|
+
→ LTP: ₹1457.9
|
|
128
|
+
→ OHLC: O:1458.8 H:1480.0 L:1455.1 C:1457.9
|
|
129
|
+
→ Volume: 17167161
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### 3. Historical Data (`get_historical_data`)
|
|
133
|
+
|
|
134
|
+
**Regular data:**
|
|
135
|
+
```
|
|
136
|
+
🔧 Tool Called: get_historical_data
|
|
137
|
+
→ Historical data: 30 records
|
|
138
|
+
→ Interval: 5
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**With indicators:**
|
|
142
|
+
```
|
|
143
|
+
🔧 Tool Called: get_historical_data
|
|
144
|
+
→ Technical Indicators:
|
|
145
|
+
→ Current Price: ₹25694.35
|
|
146
|
+
→ RSI(14): 56.32
|
|
147
|
+
→ MACD: 12.45
|
|
148
|
+
→ SMA(20): ₹25680.12
|
|
149
|
+
→ SMA(50): ₹25550.45
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### 4. Option Chain (`get_option_chain`)
|
|
153
|
+
```
|
|
154
|
+
🔧 Tool Called: get_option_chain
|
|
155
|
+
→ Spot: ₹25694.35
|
|
156
|
+
→ Strikes: 15
|
|
157
|
+
→ (Filtered: ATM/OTM/ITM with both CE & PE)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### 5. Expiry List (`get_expiry_list`)
|
|
161
|
+
```
|
|
162
|
+
🔧 Tool Called: get_expiry_list
|
|
163
|
+
→ Available expiries: 12
|
|
164
|
+
→ Next expiry: 2026-01-20
|
|
165
|
+
→ Expiries: 2026-01-20, 2026-01-27, 2026-02-03, 2026-02-10, 2026-02-17...
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### 6. Find Instrument (`find_instrument`)
|
|
169
|
+
```
|
|
170
|
+
🔧 Tool Called: find_instrument
|
|
171
|
+
→ Found: NIFTY
|
|
172
|
+
→ Security ID: 13
|
|
173
|
+
→ Exchange: IDX_I
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Implementation
|
|
177
|
+
|
|
178
|
+
```ruby
|
|
179
|
+
def print_formatted_result(tool_name, content)
|
|
180
|
+
result = content.dig("result") || content
|
|
181
|
+
|
|
182
|
+
case tool_name
|
|
183
|
+
when "get_live_ltp"
|
|
184
|
+
print_ltp_result(result)
|
|
185
|
+
when "get_market_quote"
|
|
186
|
+
print_quote_result(result)
|
|
187
|
+
when "get_historical_data"
|
|
188
|
+
print_historical_result(result, content)
|
|
189
|
+
# ... other tool formatters
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Each tool has a dedicated formatter that:
|
|
195
|
+
1. Extracts key information from the result
|
|
196
|
+
2. Formats it in a human-readable way
|
|
197
|
+
3. Uses color coding for better readability
|
|
198
|
+
4. Shows relevant details without overwhelming the user
|
|
199
|
+
|
|
200
|
+
## Benefits
|
|
201
|
+
|
|
202
|
+
### Chat Console
|
|
203
|
+
✅ **Clear visual feedback** - Users know when the LLM is thinking vs responding
|
|
204
|
+
✅ **No confusion** - Thinking indicator prevents accidental typing
|
|
205
|
+
✅ **Better UX** - Immediate response to user input
|
|
206
|
+
|
|
207
|
+
### DhanHQ Console
|
|
208
|
+
✅ **Instant comprehension** - See what tool was called at a glance
|
|
209
|
+
✅ **Key data highlighted** - Important values (price, volume) are prominent
|
|
210
|
+
✅ **Less noise** - No JSON clutter, just the facts
|
|
211
|
+
✅ **Consistent formatting** - Each tool type has predictable output
|
|
212
|
+
✅ **Professional appearance** - Clean, organized display with icons
|
|
213
|
+
|
|
214
|
+
## Configuration
|
|
215
|
+
|
|
216
|
+
Both consoles support environment variables:
|
|
217
|
+
|
|
218
|
+
**Chat Console:**
|
|
219
|
+
```bash
|
|
220
|
+
OLLAMA_BASE_URL=http://localhost:11434
|
|
221
|
+
OLLAMA_MODEL=llama3.1:8b
|
|
222
|
+
OLLAMA_TEMPERATURE=0.7
|
|
223
|
+
OLLAMA_SYSTEM="You are a helpful assistant"
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
**DhanHQ Console:**
|
|
227
|
+
```bash
|
|
228
|
+
# All chat console vars, plus:
|
|
229
|
+
DHANHQ_CLIENT_ID=your_client_id
|
|
230
|
+
DHANHQ_ACCESS_TOKEN=your_token
|
|
231
|
+
SHOW_PLAN=true # Show planning step
|
|
232
|
+
ALLOW_NO_TOOL_OUTPUT=false # Require tool calls
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Testing
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
# Test chat console with thinking indicator
|
|
239
|
+
ruby examples/chat_console.rb
|
|
240
|
+
|
|
241
|
+
# Test DhanHQ console with formatted results
|
|
242
|
+
ruby examples/dhan_console.rb
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Try queries like:
|
|
246
|
+
- "What is NIFTY price?" → See formatted LTP
|
|
247
|
+
- "Get RELIANCE quote" → See formatted quote with OHLC
|
|
248
|
+
- "Show me historical data for NIFTY" → See record count
|
|
249
|
+
- "Get option chain for NIFTY" → See filtered strikes
|
|
250
|
+
|
|
251
|
+
## Related Files
|
|
252
|
+
|
|
253
|
+
- `examples/chat_console.rb` - Simple chat with thinking indicator
|
|
254
|
+
- `examples/dhan_console.rb` - Market data with formatted tool results
|
|
255
|
+
- `examples/dhanhq_tools.rb` - Underlying DhanHQ tool implementations
|
|
256
|
+
- `docs/TESTING.md` - Testing guide
|
data/docs/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Internal Documentation
|
|
2
|
+
|
|
3
|
+
This directory contains internal development documentation for the ollama-client gem.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
### Design Documentation
|
|
8
|
+
- **[HANDLERS_ANALYSIS.md](HANDLERS_ANALYSIS.md)** - Analysis of handler architecture decisions (why we didn't adopt ollama-ruby's handler pattern)
|
|
9
|
+
- **[FEATURES_ADDED.md](FEATURES_ADDED.md)** - Features integrated from ollama-ruby that align with our agent-first philosophy
|
|
10
|
+
- **[PRODUCTION_FIXES.md](PRODUCTION_FIXES.md)** - Production-ready fixes for hybrid agents (JSON parsing, retry policy, etc.)
|
|
11
|
+
- **[SCHEMA_FIXES.md](SCHEMA_FIXES.md)** - Schema validation fixes and best practices for numeric constraints
|
|
12
|
+
- **[CONSOLE_IMPROVEMENTS.md](CONSOLE_IMPROVEMENTS.md)** - Interactive console UX improvements (thinking indicators, formatted tool results)
|
|
13
|
+
|
|
14
|
+
### Testing Documentation
|
|
15
|
+
- **[TESTING.md](TESTING.md)** - Testing guide and examples
|
|
16
|
+
- **[TEST_UPDATES.md](TEST_UPDATES.md)** - Recent test updates for DhanHQ tool calling enhancements
|
|
17
|
+
|
|
18
|
+
### CI/Automation
|
|
19
|
+
- **[CLOUD.md](CLOUD.md)** - Cloud agent guide for automated testing and fixes
|
|
20
|
+
|
|
21
|
+
## For Users
|
|
22
|
+
|
|
23
|
+
If you're looking for user-facing documentation, see:
|
|
24
|
+
- [Main README](../README.md) - Getting started, API reference, examples
|
|
25
|
+
- [CHANGELOG](../CHANGELOG.md) - Version history and changes
|
|
26
|
+
- [CONTRIBUTING](../CONTRIBUTING.md) - How to contribute
|
|
27
|
+
- [Examples](../examples/) - Working code examples
|
|
28
|
+
|
|
29
|
+
## For Contributors
|
|
30
|
+
|
|
31
|
+
These internal docs help maintainers understand:
|
|
32
|
+
- **Why** certain design decisions were made
|
|
33
|
+
- **What** features have been added and why
|
|
34
|
+
- **How** to test and maintain the codebase
|
|
35
|
+
- **Where** production fixes were applied
|
|
36
|
+
|
|
37
|
+
They are not intended for end users and can be safely ignored when using the gem.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Schema Validation Fixes
|
|
2
|
+
|
|
3
|
+
## Problem
|
|
4
|
+
|
|
5
|
+
LLMs were returning confidence values as percentages (e.g., 95, 100) instead of decimals (e.g., 0.95, 1.0), causing schema validation errors:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
The property '#/confidence' did not have a maximum value of 1, inclusively
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Root Cause
|
|
12
|
+
|
|
13
|
+
JSON schemas defined numeric constraints (0-1) but lacked explicit descriptions explaining the expected format. LLMs naturally interpret "confidence" as percentages without guidance.
|
|
14
|
+
|
|
15
|
+
## Solution
|
|
16
|
+
|
|
17
|
+
Added explicit descriptions to all numeric fields with constrained ranges, clarifying the expected format.
|
|
18
|
+
|
|
19
|
+
### Fixed Fields
|
|
20
|
+
|
|
21
|
+
#### Confidence Fields (0.0 to 1.0)
|
|
22
|
+
Updated in 8 locations across the codebase:
|
|
23
|
+
|
|
24
|
+
- `examples/complete_workflow.rb` (2 instances)
|
|
25
|
+
- TaskPlanner schema
|
|
26
|
+
- DataAnalyzer schema
|
|
27
|
+
- `examples/dhanhq_agent.rb` (2 instances)
|
|
28
|
+
- `examples/dhanhq/schemas/agent_schemas.rb` (2 instances)
|
|
29
|
+
- `examples/dhanhq/agents/technical_analysis_agent.rb` (1 instance)
|
|
30
|
+
- `examples/advanced_multi_step_agent.rb` (1 instance)
|
|
31
|
+
|
|
32
|
+
**Before:**
|
|
33
|
+
```ruby
|
|
34
|
+
"confidence" => {
|
|
35
|
+
"type" => "number",
|
|
36
|
+
"minimum" => 0,
|
|
37
|
+
"maximum" => 1
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**After:**
|
|
42
|
+
```ruby
|
|
43
|
+
"confidence" => {
|
|
44
|
+
"type" => "number",
|
|
45
|
+
"minimum" => 0,
|
|
46
|
+
"maximum" => 1,
|
|
47
|
+
"description" => "Confidence in this decision (0.0 to 1.0, where 1.0 is 100% confident)"
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
#### Other Constrained Fields
|
|
52
|
+
|
|
53
|
+
- `reproducibility_score` in `advanced_complex_schemas.rb`
|
|
54
|
+
- Added: "Reproducibility score (0.0 to 1.0, where 1.0 means fully reproducible)"
|
|
55
|
+
|
|
56
|
+
- `profit_margin` in `advanced_complex_schemas.rb`
|
|
57
|
+
- Added: "Profit margin as percentage (0 to 100)"
|
|
58
|
+
|
|
59
|
+
- `overall_score` in `advanced_complex_schemas.rb`
|
|
60
|
+
- Added: "Overall quality score (0 to 100)"
|
|
61
|
+
|
|
62
|
+
## Best Practices
|
|
63
|
+
|
|
64
|
+
### When Defining Schemas
|
|
65
|
+
|
|
66
|
+
1. **Always include descriptions** for numeric fields with constraints
|
|
67
|
+
2. **Be explicit about format**: decimal (0.0-1.0) vs percentage (0-100)
|
|
68
|
+
3. **Provide examples** in descriptions when helpful
|
|
69
|
+
4. **Use clear units**: "as percentage", "as decimal", "where 1.0 is 100%"
|
|
70
|
+
|
|
71
|
+
### When Writing Prompts
|
|
72
|
+
|
|
73
|
+
**Schema descriptions alone may not be enough!** Always reinforce numeric formats in the prompt itself:
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
# ❌ BAD: Relies only on schema description
|
|
77
|
+
result = @client.generate(
|
|
78
|
+
prompt: "Analyze this data: #{data}",
|
|
79
|
+
schema: @schema
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# ✅ GOOD: Explicit examples in prompt
|
|
83
|
+
result = @client.generate(
|
|
84
|
+
prompt: "Analyze this data: #{data}\n\nIMPORTANT: Express confidence as a decimal between 0.0 and 1.0 (e.g., 0.85 for 85% confidence, not 85).",
|
|
85
|
+
schema: @schema
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Why this matters:**
|
|
90
|
+
- LLMs may not always read schema descriptions carefully
|
|
91
|
+
- Concrete examples in prompts are more effective
|
|
92
|
+
- Prevents "100" vs "1.0" confusion
|
|
93
|
+
|
|
94
|
+
### Example Patterns
|
|
95
|
+
|
|
96
|
+
**Decimal confidence (0-1):**
|
|
97
|
+
```ruby
|
|
98
|
+
"confidence" => {
|
|
99
|
+
"type" => "number",
|
|
100
|
+
"minimum" => 0,
|
|
101
|
+
"maximum" => 1,
|
|
102
|
+
"description" => "Confidence level (0.0 to 1.0, where 1.0 is 100% confident)"
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Percentage score (0-100):**
|
|
107
|
+
```ruby
|
|
108
|
+
"score" => {
|
|
109
|
+
"type" => "number",
|
|
110
|
+
"minimum" => 0,
|
|
111
|
+
"maximum" => 100,
|
|
112
|
+
"description" => "Quality score as percentage (0 to 100)"
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Probability (0-1):**
|
|
117
|
+
```ruby
|
|
118
|
+
"probability" => {
|
|
119
|
+
"type" => "number",
|
|
120
|
+
"minimum" => 0,
|
|
121
|
+
"maximum" => 1,
|
|
122
|
+
"description" => "Probability value (0.0 to 1.0)"
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Testing
|
|
127
|
+
|
|
128
|
+
All modified files passed syntax validation:
|
|
129
|
+
```bash
|
|
130
|
+
ruby -c examples/complete_workflow.rb # Syntax OK
|
|
131
|
+
ruby -c examples/dhanhq_agent.rb # Syntax OK
|
|
132
|
+
ruby -c examples/advanced_multi_step_agent.rb # Syntax OK
|
|
133
|
+
ruby -c examples/advanced_complex_schemas.rb # Syntax OK
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Impact
|
|
137
|
+
|
|
138
|
+
- **Examples now run without schema validation errors**
|
|
139
|
+
- **LLMs receive clear guidance** on numeric formats
|
|
140
|
+
- **Consistent patterns** across all example schemas
|
|
141
|
+
- **Better developer experience** with self-documenting schemas
|
|
142
|
+
|
|
143
|
+
## Related Files
|
|
144
|
+
|
|
145
|
+
See also:
|
|
146
|
+
- [Testing Guide](TESTING.md) - How to test structured outputs
|
|
147
|
+
- [Features Added](FEATURES_ADDED.md) - Schema validation features
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Test File Updates
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
Updated test examples to reflect recent enhancements to DhanHQ tool calling, particularly around historical data and technical indicators.
|
|
6
|
+
|
|
7
|
+
## Files Updated
|
|
8
|
+
|
|
9
|
+
### 1. `examples/test_dhanhq_tool_calling.rb`
|
|
10
|
+
|
|
11
|
+
#### Changes Made:
|
|
12
|
+
|
|
13
|
+
1. **Updated `historical_data_tool` definition** (lines 66-101):
|
|
14
|
+
- Changed `interval` enum from `["daily", "weekly", "monthly"]` to `["1", "5", "15", "25", "60"]`
|
|
15
|
+
- Added proper description: "Minute interval for intraday data. Omit for daily data."
|
|
16
|
+
- Added `calculate_indicators` boolean parameter
|
|
17
|
+
- Updated description to mention technical indicators (RSI, MACD, SMA, EMA, Bollinger Bands, ATR)
|
|
18
|
+
- Added `required` fields: `from_date` and `to_date`
|
|
19
|
+
|
|
20
|
+
2. **Added Test 5: Historical Data with Technical Indicators**
|
|
21
|
+
- Tests the new `calculate_indicators` parameter
|
|
22
|
+
- Verifies LLM includes all required parameters including interval
|
|
23
|
+
- Shows how to request intraday data with indicators
|
|
24
|
+
|
|
25
|
+
3. **Added Test 6: Intraday Data with 5-minute intervals**
|
|
26
|
+
- Tests intraday data specifically
|
|
27
|
+
- Uses current date dynamically
|
|
28
|
+
- Validates interval parameter is one of the valid values (1, 5, 15, 25, 60)
|
|
29
|
+
- Shows date range handling
|
|
30
|
+
|
|
31
|
+
4. **Enhanced Summary Section**
|
|
32
|
+
- Added notes about historical data enhancements
|
|
33
|
+
- Documents interval usage for intraday vs daily data
|
|
34
|
+
- Explains `calculate_indicators` feature and its benefits
|
|
35
|
+
|
|
36
|
+
## Key Features Tested
|
|
37
|
+
|
|
38
|
+
### Intraday Data
|
|
39
|
+
- ✅ Interval parameter with values: "1", "5", "15", "25", "60"
|
|
40
|
+
- ✅ Date handling (from_date, to_date)
|
|
41
|
+
- ✅ 5-minute intervals (most commonly used for intraday analysis)
|
|
42
|
+
|
|
43
|
+
### Technical Indicators
|
|
44
|
+
- ✅ `calculate_indicators` parameter
|
|
45
|
+
- ✅ Returns RSI, MACD, SMA, EMA, Bollinger Bands, ATR
|
|
46
|
+
- ✅ Reduces response size vs raw OHLCV data
|
|
47
|
+
|
|
48
|
+
### Tool Calling
|
|
49
|
+
- ✅ chat_raw() method for accessing tool_calls
|
|
50
|
+
- ✅ Structured Tool classes
|
|
51
|
+
- ✅ Parameter validation
|
|
52
|
+
|
|
53
|
+
## Example Usage
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
# Get intraday data with indicators
|
|
57
|
+
historical_data_tool = Ollama::Tool.new(
|
|
58
|
+
type: "function",
|
|
59
|
+
function: Ollama::Tool::Function.new(
|
|
60
|
+
name: "get_historical_data",
|
|
61
|
+
description: "Get historical price data (OHLCV) or technical indicators...",
|
|
62
|
+
parameters: Ollama::Tool::Function::Parameters.new(
|
|
63
|
+
type: "object",
|
|
64
|
+
properties: {
|
|
65
|
+
interval: Ollama::Tool::Function::Parameters::Property.new(
|
|
66
|
+
type: "string",
|
|
67
|
+
description: "Minute interval for intraday data",
|
|
68
|
+
enum: %w[1 5 15 25 60] # Updated from ["daily", "weekly", "monthly"]
|
|
69
|
+
),
|
|
70
|
+
calculate_indicators: Ollama::Tool::Function::Parameters::Property.new(
|
|
71
|
+
type: "boolean",
|
|
72
|
+
description: "If true, returns technical indicators instead of raw data"
|
|
73
|
+
),
|
|
74
|
+
# ... other properties
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# Request with intraday and indicators
|
|
81
|
+
response = client.chat_raw(
|
|
82
|
+
messages: [Ollama::Agent::Messages.user(
|
|
83
|
+
"Get NIFTY intraday data with 5-minute intervals and technical indicators"
|
|
84
|
+
)],
|
|
85
|
+
tools: historical_data_tool
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Testing
|
|
90
|
+
|
|
91
|
+
Run the updated tests:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Tool calling examples
|
|
95
|
+
ruby examples/test_dhanhq_tool_calling.rb
|
|
96
|
+
ruby examples/test_tool_calling.rb
|
|
97
|
+
|
|
98
|
+
# DhanHQ specific tests
|
|
99
|
+
ruby examples/dhanhq/test_tool_calling.rb
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Notes
|
|
103
|
+
|
|
104
|
+
- The `interval` parameter is now correctly defined for intraday minute intervals
|
|
105
|
+
- The old values ("daily", "weekly", "monthly") were incorrect for the DhanHQ API
|
|
106
|
+
- The new `calculate_indicators` parameter provides technical analysis without large response sizes
|
|
107
|
+
- Tests now include date handling examples using `Date.today`
|