ollama-client 0.2.1 → 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 +220 -12
- data/docs/CLOUD.md +29 -0
- data/docs/CONSOLE_IMPROVEMENTS.md +256 -0
- data/docs/FEATURES_ADDED.md +145 -0
- data/docs/HANDLERS_ANALYSIS.md +190 -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 +13 -7
- data/examples/chat_console.rb +143 -0
- data/examples/complete_workflow.rb +14 -4
- data/examples/dhan_console.rb +843 -0
- data/examples/dhanhq/agents/base_agent.rb +0 -2
- data/examples/dhanhq/agents/orchestrator_agent.rb +1 -2
- data/examples/dhanhq/agents/technical_analysis_agent.rb +67 -49
- data/examples/dhanhq/analysis/market_structure.rb +44 -28
- data/examples/dhanhq/analysis/pattern_recognizer.rb +64 -47
- data/examples/dhanhq/analysis/trend_analyzer.rb +6 -8
- data/examples/dhanhq/dhanhq_agent.rb +296 -99
- data/examples/dhanhq/indicators/technical_indicators.rb +3 -5
- data/examples/dhanhq/scanners/intraday_options_scanner.rb +360 -255
- data/examples/dhanhq/scanners/swing_scanner.rb +118 -84
- data/examples/dhanhq/schemas/agent_schemas.rb +2 -2
- data/examples/dhanhq/services/data_service.rb +5 -7
- data/examples/dhanhq/services/trading_service.rb +0 -3
- data/examples/dhanhq/technical_analysis_agentic_runner.rb +217 -84
- data/examples/dhanhq/technical_analysis_runner.rb +216 -162
- data/examples/dhanhq/test_tool_calling.rb +538 -0
- data/examples/dhanhq/test_tool_calling_verbose.rb +251 -0
- data/examples/dhanhq/utils/trading_parameter_normalizer.rb +12 -17
- data/examples/dhanhq_agent.rb +159 -116
- data/examples/dhanhq_tools.rb +1158 -251
- data/examples/multi_step_agent_with_external_data.rb +368 -0
- data/examples/structured_tools.rb +89 -0
- data/examples/test_dhanhq_tool_calling.rb +375 -0
- data/examples/test_tool_calling.rb +160 -0
- data/examples/tool_calling_direct.rb +124 -0
- data/examples/tool_dto_example.rb +94 -0
- data/exe/dhan_console +4 -0
- data/exe/ollama-client +1 -1
- data/lib/ollama/agent/executor.rb +116 -15
- data/lib/ollama/client.rb +118 -55
- data/lib/ollama/config.rb +36 -0
- data/lib/ollama/dto.rb +187 -0
- data/lib/ollama/embeddings.rb +77 -0
- data/lib/ollama/options.rb +104 -0
- data/lib/ollama/response.rb +121 -0
- data/lib/ollama/tool/function/parameters/property.rb +72 -0
- data/lib/ollama/tool/function/parameters.rb +101 -0
- data/lib/ollama/tool/function.rb +78 -0
- data/lib/ollama/tool.rb +60 -0
- data/lib/ollama/version.rb +1 -1
- data/lib/ollama_client.rb +3 -0
- metadata +31 -3
- /data/{PRODUCTION_FIXES.md → docs/PRODUCTION_FIXES.md} +0 -0
- /data/{TESTING.md → docs/TESTING.md} +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../dto"
|
|
4
|
+
|
|
5
|
+
module Ollama
|
|
6
|
+
# Tool class is defined in tool.rb
|
|
7
|
+
# This file adds Function class to Tool
|
|
8
|
+
class Tool
|
|
9
|
+
# Represents a function definition for tool usage in Ollama API
|
|
10
|
+
#
|
|
11
|
+
# Provides structured, type-safe function definitions for agent tools.
|
|
12
|
+
# Use this when you need explicit control over tool schemas beyond
|
|
13
|
+
# auto-inference from Ruby callable signatures.
|
|
14
|
+
#
|
|
15
|
+
# Example:
|
|
16
|
+
# function = Ollama::Tool::Function.new(
|
|
17
|
+
# name: 'get_current_weather',
|
|
18
|
+
# description: 'Get the current weather for a location',
|
|
19
|
+
# parameters: parameters_spec
|
|
20
|
+
# )
|
|
21
|
+
#
|
|
22
|
+
# # Deserialize from hash
|
|
23
|
+
# function = Ollama::Tool::Function.from_hash({ name: '...', description: '...' })
|
|
24
|
+
class Function
|
|
25
|
+
include DTO
|
|
26
|
+
|
|
27
|
+
attr_reader :name, :description, :parameters
|
|
28
|
+
|
|
29
|
+
def initialize(name:, description:, parameters: nil)
|
|
30
|
+
@name = name.to_s
|
|
31
|
+
@description = description.to_s
|
|
32
|
+
@parameters = parameters || Function::Parameters.new(
|
|
33
|
+
type: "object",
|
|
34
|
+
properties: {},
|
|
35
|
+
required: []
|
|
36
|
+
)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Create instance from hash
|
|
40
|
+
#
|
|
41
|
+
# @param hash [Hash] Hash with name, description, and optional parameters
|
|
42
|
+
# @return [Function] New Function instance
|
|
43
|
+
def self.from_hash(hash)
|
|
44
|
+
normalized = hash.transform_keys(&:to_sym)
|
|
45
|
+
params_hash = normalized[:parameters] || normalized["parameters"]
|
|
46
|
+
|
|
47
|
+
parameters = if params_hash.is_a?(Hash)
|
|
48
|
+
Function::Parameters.from_hash(params_hash)
|
|
49
|
+
elsif params_hash
|
|
50
|
+
params_hash
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
new(
|
|
54
|
+
name: normalized[:name] || normalized["name"],
|
|
55
|
+
description: normalized[:description] || normalized["description"],
|
|
56
|
+
parameters: parameters
|
|
57
|
+
)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def to_h
|
|
61
|
+
hash = {
|
|
62
|
+
name: @name,
|
|
63
|
+
description: @description
|
|
64
|
+
}
|
|
65
|
+
hash[:parameters] = @parameters.to_h if @parameters
|
|
66
|
+
hash
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Override as_json to use explicit attributes instead of tracked ones
|
|
70
|
+
def as_json(*_ignored)
|
|
71
|
+
to_h
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Load Parameters class after Function is defined
|
|
76
|
+
require_relative "function/parameters"
|
|
77
|
+
end
|
|
78
|
+
end
|
data/lib/ollama/tool.rb
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "dto"
|
|
4
|
+
require_relative "tool/function"
|
|
5
|
+
|
|
6
|
+
module Ollama
|
|
7
|
+
# Tool definition for function calling in agents
|
|
8
|
+
#
|
|
9
|
+
# Provides a structured, type-safe way to define tools for agent executors.
|
|
10
|
+
# This is an optional alternative to passing raw callables - use when you
|
|
11
|
+
# need explicit control over tool schemas.
|
|
12
|
+
#
|
|
13
|
+
# Example:
|
|
14
|
+
# tool = Ollama::Tool.new(
|
|
15
|
+
# type: 'function',
|
|
16
|
+
# function: Ollama::Tool::Function.new(
|
|
17
|
+
# name: 'get_weather',
|
|
18
|
+
# description: 'Get current weather',
|
|
19
|
+
# parameters: parameters_spec
|
|
20
|
+
# )
|
|
21
|
+
# )
|
|
22
|
+
#
|
|
23
|
+
# # Deserialize from hash
|
|
24
|
+
# tool = Ollama::Tool.from_hash({ type: 'function', function: {...} })
|
|
25
|
+
class Tool
|
|
26
|
+
include DTO
|
|
27
|
+
|
|
28
|
+
attr_reader :type, :function
|
|
29
|
+
|
|
30
|
+
def initialize(type:, function:)
|
|
31
|
+
@type = type.to_s
|
|
32
|
+
@function = function
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Create instance from hash
|
|
36
|
+
#
|
|
37
|
+
# @param hash [Hash] Hash with type and function keys
|
|
38
|
+
# @return [Tool] New Tool instance
|
|
39
|
+
def self.from_hash(hash)
|
|
40
|
+
normalized = hash.transform_keys(&:to_sym)
|
|
41
|
+
function_hash = normalized[:function] || normalized["function"]
|
|
42
|
+
function = function_hash.is_a?(Hash) ? Function.from_hash(function_hash) : function_hash
|
|
43
|
+
|
|
44
|
+
new(type: normalized[:type] || normalized["type"], function: function)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_h
|
|
48
|
+
{
|
|
49
|
+
type: @type,
|
|
50
|
+
function: @function.to_h
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Override as_json to use explicit attributes instead of tracked ones
|
|
55
|
+
# (since we're using to_h for our specific structure)
|
|
56
|
+
def as_json(*_ignored)
|
|
57
|
+
to_h
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
data/lib/ollama/version.rb
CHANGED
data/lib/ollama_client.rb
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
require_relative "ollama/config"
|
|
4
4
|
require_relative "ollama/errors"
|
|
5
5
|
require_relative "ollama/schema_validator"
|
|
6
|
+
require_relative "ollama/options"
|
|
7
|
+
require_relative "ollama/response"
|
|
8
|
+
require_relative "ollama/tool"
|
|
6
9
|
require_relative "ollama/client"
|
|
7
10
|
require_relative "ollama/streaming_observer"
|
|
8
11
|
require_relative "ollama/agent/messages"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ollama-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shubham Taywade
|
|
@@ -45,6 +45,7 @@ description: A production-ready, agent-first Ruby client for the Ollama API with
|
|
|
45
45
|
email:
|
|
46
46
|
- shubhamtaywade82@gmail.com
|
|
47
47
|
executables:
|
|
48
|
+
- dhan_console
|
|
48
49
|
- ollama-client
|
|
49
50
|
extensions: []
|
|
50
51
|
extra_rdoc_files: []
|
|
@@ -53,16 +54,26 @@ files:
|
|
|
53
54
|
- CODE_OF_CONDUCT.md
|
|
54
55
|
- CONTRIBUTING.md
|
|
55
56
|
- LICENSE.txt
|
|
56
|
-
- PRODUCTION_FIXES.md
|
|
57
57
|
- README.md
|
|
58
58
|
- Rakefile
|
|
59
|
-
-
|
|
59
|
+
- docs/CLOUD.md
|
|
60
|
+
- docs/CONSOLE_IMPROVEMENTS.md
|
|
61
|
+
- docs/FEATURES_ADDED.md
|
|
62
|
+
- docs/HANDLERS_ANALYSIS.md
|
|
63
|
+
- docs/PRODUCTION_FIXES.md
|
|
64
|
+
- docs/README.md
|
|
65
|
+
- docs/SCHEMA_FIXES.md
|
|
66
|
+
- docs/TESTING.md
|
|
67
|
+
- docs/TEST_UPDATES.md
|
|
68
|
+
- examples/README.md
|
|
60
69
|
- examples/advanced_complex_schemas.rb
|
|
61
70
|
- examples/advanced_edge_cases.rb
|
|
62
71
|
- examples/advanced_error_handling.rb
|
|
63
72
|
- examples/advanced_multi_step_agent.rb
|
|
64
73
|
- examples/advanced_performance_testing.rb
|
|
74
|
+
- examples/chat_console.rb
|
|
65
75
|
- examples/complete_workflow.rb
|
|
76
|
+
- examples/dhan_console.rb
|
|
66
77
|
- examples/dhanhq/README.md
|
|
67
78
|
- examples/dhanhq/agents/base_agent.rb
|
|
68
79
|
- examples/dhanhq/agents/data_agent.rb
|
|
@@ -83,6 +94,8 @@ files:
|
|
|
83
94
|
- examples/dhanhq/services/trading_service.rb
|
|
84
95
|
- examples/dhanhq/technical_analysis_agentic_runner.rb
|
|
85
96
|
- examples/dhanhq/technical_analysis_runner.rb
|
|
97
|
+
- examples/dhanhq/test_tool_calling.rb
|
|
98
|
+
- examples/dhanhq/test_tool_calling_verbose.rb
|
|
86
99
|
- examples/dhanhq/utils/instrument_helper.rb
|
|
87
100
|
- examples/dhanhq/utils/parameter_cleaner.rb
|
|
88
101
|
- examples/dhanhq/utils/parameter_normalizer.rb
|
|
@@ -90,18 +103,33 @@ files:
|
|
|
90
103
|
- examples/dhanhq/utils/trading_parameter_normalizer.rb
|
|
91
104
|
- examples/dhanhq_agent.rb
|
|
92
105
|
- examples/dhanhq_tools.rb
|
|
106
|
+
- examples/multi_step_agent_with_external_data.rb
|
|
93
107
|
- examples/structured_outputs_chat.rb
|
|
108
|
+
- examples/structured_tools.rb
|
|
109
|
+
- examples/test_dhanhq_tool_calling.rb
|
|
110
|
+
- examples/test_tool_calling.rb
|
|
111
|
+
- examples/tool_calling_direct.rb
|
|
94
112
|
- examples/tool_calling_pattern.rb
|
|
113
|
+
- examples/tool_dto_example.rb
|
|
114
|
+
- exe/dhan_console
|
|
95
115
|
- exe/ollama-client
|
|
96
116
|
- lib/ollama/agent/executor.rb
|
|
97
117
|
- lib/ollama/agent/messages.rb
|
|
98
118
|
- lib/ollama/agent/planner.rb
|
|
99
119
|
- lib/ollama/client.rb
|
|
100
120
|
- lib/ollama/config.rb
|
|
121
|
+
- lib/ollama/dto.rb
|
|
122
|
+
- lib/ollama/embeddings.rb
|
|
101
123
|
- lib/ollama/errors.rb
|
|
124
|
+
- lib/ollama/options.rb
|
|
125
|
+
- lib/ollama/response.rb
|
|
102
126
|
- lib/ollama/schema_validator.rb
|
|
103
127
|
- lib/ollama/schemas/base.json
|
|
104
128
|
- lib/ollama/streaming_observer.rb
|
|
129
|
+
- lib/ollama/tool.rb
|
|
130
|
+
- lib/ollama/tool/function.rb
|
|
131
|
+
- lib/ollama/tool/function/parameters.rb
|
|
132
|
+
- lib/ollama/tool/function/parameters/property.rb
|
|
105
133
|
- lib/ollama/version.rb
|
|
106
134
|
- lib/ollama_client.rb
|
|
107
135
|
- sig/ollama/client.rbs
|
|
File without changes
|
|
File without changes
|