ollama_chat 0.0.139 โ 0.0.140
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/CHANGES.md +22 -0
- data/lib/ollama_chat/invidious.rb +27 -6
- data/lib/ollama_chat/tool_call_processor.rb +46 -25
- data/lib/ollama_chat/tools/execute_shell.rb +23 -19
- data/lib/ollama_chat/version.rb +1 -1
- data/ollama_chat.gemspec +2 -2
- data/spec/ollama_chat/invidious_spec.rb +22 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c1cff963a5116fbe9c1a4a94fff41df7128c5f31c4daaaf96e2a4334c97d77d5
|
|
4
|
+
data.tar.gz: 97ec4d9f4f90c71b4bc2eee13f2000bb4f8fb7ad6b9fe308c82342734e3d1629
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f1abfdfaab1002d8503a7a72b204ee247f2375df5e6b3de417c483826ad88208ceca28c73921afcdd0b8ec2575e15c4cf9ade009fd7aab99b18a707a9451891f
|
|
7
|
+
data.tar.gz: ddd78c34605c7035c0d24e9ba76e59a28edd8a85f2116478b97474e4233fb47077b297134814a3e829abd4af43d343a6ce5ca191a33cc46e174d46664186dbce
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-11-02 v0.0.140
|
|
4
|
+
|
|
5
|
+
### Improvements
|
|
6
|
+
|
|
7
|
+
- Accept Invidious instance URLs for video transcripts. `fetch_video_info` now
|
|
8
|
+
delegates ID extraction to `extract_video_id`, which supports standard
|
|
9
|
+
YouTube URLs and watch, embed, and shorts paths on the configured Invidious
|
|
10
|
+
instance via `invidious_pattern`.
|
|
11
|
+
- Extract the confirmation gate logic in `ToolCallProcessor` into a private
|
|
12
|
+
`confirm_tool` method, returning a `[confirmed, resolve]` tuple to simplify
|
|
13
|
+
the `handle` method.
|
|
14
|
+
- In `ExecuteShell`, pressing `C-c` at the `๐ Instructions:` prompt now
|
|
15
|
+
re-prompts the user for the y/n/i/a/d choice instead of submitting a blank
|
|
16
|
+
instruction.
|
|
17
|
+
- Updated the instruction prompt in `ExecuteShell` to display a `(C-c โจ
|
|
18
|
+
cancel)` escape hint.
|
|
19
|
+
|
|
20
|
+
### Testing
|
|
21
|
+
|
|
22
|
+
- Added a spec context verifying that an Invidious instance watch URL correctly
|
|
23
|
+
extracts the video ID and produces a transcript.
|
|
24
|
+
|
|
3
25
|
## 2026-10-30 v0.0.139
|
|
4
26
|
|
|
5
27
|
### Features
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
# companion instance.
|
|
3
3
|
#
|
|
4
4
|
# Only activates when OC::OLLAMA::CHAT::INVIDIOUS::URL is set.
|
|
5
|
-
#
|
|
5
|
+
# Accepts standard YouTube URLs and watch URLs on the configured
|
|
6
|
+
# Invidious instance. Unmatched URLs and unconfigured environments
|
|
7
|
+
# return nil.
|
|
6
8
|
#
|
|
7
9
|
# @example Fetching video info for a YouTube watch URL
|
|
8
10
|
# text = OllamaChat::Invidious.fetch_video_info(
|
|
@@ -30,18 +32,18 @@ module OllamaChat
|
|
|
30
32
|
# 3. GET the matched track's baseUrl โ timedtext XML
|
|
31
33
|
# 4. Extract <text> elements via Nokogiri โ plain text
|
|
32
34
|
#
|
|
33
|
-
# @param url [String]
|
|
35
|
+
# @param url [String] a YouTube or Invidious instance watch URL
|
|
34
36
|
# @param chat [OllamaChat::Chat] the chat instance (for HTTP
|
|
35
37
|
# middleware)
|
|
36
38
|
# @return [StringIO, nil] video info + transcript as a text IO,
|
|
37
|
-
# or nil if
|
|
39
|
+
# or nil if URL unmatched, Invidious not configured, or
|
|
38
40
|
# video details unavailable
|
|
39
41
|
def fetch_video_info(url, chat:)
|
|
40
42
|
invidious_url = OC::OLLAMA::CHAT::INVIDIOUS::URL? or return
|
|
41
|
-
|
|
43
|
+
base = invidious_url.to_s
|
|
44
|
+
video_id = extract_video_id(url, base) or return
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
key = OC::OLLAMA::CHAT::INVIDIOUS::COMPANION_KEY
|
|
46
|
+
key = OC::OLLAMA::CHAT::INVIDIOUS::COMPANION_KEY
|
|
45
47
|
|
|
46
48
|
# Step 1: POST /companion/youtubei/v1/player
|
|
47
49
|
player_response = nil
|
|
@@ -157,6 +159,25 @@ module OllamaChat
|
|
|
157
159
|
def format_duration(seconds)
|
|
158
160
|
Tins::Duration.new(seconds).to_s
|
|
159
161
|
end
|
|
162
|
+
|
|
163
|
+
# Extracts the 11-character video ID from a YouTube or Invidious
|
|
164
|
+
# instance watch URL.
|
|
165
|
+
#
|
|
166
|
+
# @param url [String] the source URL
|
|
167
|
+
# @param base [String] the configured Invidious base URL
|
|
168
|
+
# @return [String, nil] the video ID
|
|
169
|
+
def extract_video_id(url, base)
|
|
170
|
+
url[YOUTUBE_URLS, 1] || url[invidious_pattern(base), 1]
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# Builds a regex for watch/embed/shorts paths on the configured
|
|
174
|
+
# Invidious instance.
|
|
175
|
+
#
|
|
176
|
+
# @param base [String] the Invidious instance base URL
|
|
177
|
+
# @return [Regexp]
|
|
178
|
+
def invidious_pattern(base)
|
|
179
|
+
/\A#{Regexp.escape(base)}\/(?:watch\?v=|embed\/|shorts\/)([\w-]{11})/
|
|
180
|
+
end
|
|
160
181
|
end
|
|
161
182
|
end
|
|
162
183
|
end
|
|
@@ -61,33 +61,9 @@ class OllamaChat::ToolCallProcessor
|
|
|
61
61
|
next
|
|
62
62
|
end
|
|
63
63
|
feedback(?\n, output:)
|
|
64
|
-
confirmed = :implicit
|
|
65
|
-
resolve = nil
|
|
66
64
|
function = JSON.pretty_generate(tool_call.function)
|
|
67
65
|
chat.log(:info, "Tool call received", data: { tool: name, function: })
|
|
68
|
-
|
|
69
|
-
feedback(
|
|
70
|
-
("I want to execute tool %s\n%s\n" % [ bold { name }, italic { function }, ]),
|
|
71
|
-
type: :alarm
|
|
72
|
-
)
|
|
73
|
-
prompt = 'โ Allow โ
[y]es / โ๏ธ[n]o / ๐[i]nstruct? '
|
|
74
|
-
answer = chat.confirm?(prompt:)&.to_s&.downcase
|
|
75
|
-
resolve = 'You **MUST** ask the user for instructions on how to proceed!!!'
|
|
76
|
-
case answer
|
|
77
|
-
when 'y'
|
|
78
|
-
confirmed = :explicit
|
|
79
|
-
when 'n'
|
|
80
|
-
confirmed = :denied
|
|
81
|
-
else
|
|
82
|
-
confirmed = :denied
|
|
83
|
-
instr = chat.ask?(prompt: '๐ Instructions: ')&.strip
|
|
84
|
-
resolve = instr.full? || resolve
|
|
85
|
-
end
|
|
86
|
-
else
|
|
87
|
-
feedback(
|
|
88
|
-
"Executing tool %s\n%s" % [ bold { name }, italic { function }, ]
|
|
89
|
-
)
|
|
90
|
-
end
|
|
66
|
+
confirmed, resolve = confirm_tool(name, function)
|
|
91
67
|
start = Time.now
|
|
92
68
|
result = nil
|
|
93
69
|
case confirmed
|
|
@@ -173,4 +149,49 @@ class OllamaChat::ToolCallProcessor
|
|
|
173
149
|
def clear!
|
|
174
150
|
@results.clear
|
|
175
151
|
end
|
|
152
|
+
|
|
153
|
+
private
|
|
154
|
+
|
|
155
|
+
# Prompts the user for confirmation on a tool call that requires it.
|
|
156
|
+
# Returns a `[confirmed, resolve]` tuple where `confirmed` is one of
|
|
157
|
+
# `:implicit`, `:explicit`, `:denied` and `resolve` is an optional
|
|
158
|
+
# instruction string for the LLM.
|
|
159
|
+
#
|
|
160
|
+
# @param name [String] the tool name
|
|
161
|
+
# @param function [String] pretty-printed JSON of the tool call
|
|
162
|
+
# @return [Array(Symbol, String?)]
|
|
163
|
+
def confirm_tool(name, function)
|
|
164
|
+
confirmed = :implicit
|
|
165
|
+
resolve = nil
|
|
166
|
+
|
|
167
|
+
1.times do
|
|
168
|
+
if chat.tool_function(name).require_confirmation?
|
|
169
|
+
feedback(
|
|
170
|
+
("I want to execute tool %s\n%s\n" % [ bold { name }, italic { function }, ]),
|
|
171
|
+
type: :alarm
|
|
172
|
+
)
|
|
173
|
+
prompt = 'โ Allow โ
[y]es / โ๏ธ[n]o / ๐[i]nstruct? '
|
|
174
|
+
answer = chat.confirm?(prompt:)&.to_s&.downcase
|
|
175
|
+
resolve = 'You **MUST** ask the user for instructions on how to proceed!!!'
|
|
176
|
+
case answer
|
|
177
|
+
when 'y'
|
|
178
|
+
confirmed = :explicit
|
|
179
|
+
when 'n'
|
|
180
|
+
confirmed = :denied
|
|
181
|
+
else
|
|
182
|
+
confirmed = :denied
|
|
183
|
+
instr = chat.ask?(prompt: '๐ Instructions (C-c โจ cancel): ')
|
|
184
|
+
instr.nil? and redo
|
|
185
|
+
instr = instr&.strip
|
|
186
|
+
resolve = instr.full? || resolve
|
|
187
|
+
end
|
|
188
|
+
else
|
|
189
|
+
feedback(
|
|
190
|
+
"Executing tool %s\n%s" % [ bold { name }, italic { function }, ]
|
|
191
|
+
)
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
[confirmed, resolve]
|
|
196
|
+
end
|
|
176
197
|
end
|
|
@@ -102,25 +102,29 @@ class OllamaChat::Tools::ExecuteShell
|
|
|
102
102
|
y once ยท n cancel ยท i instruct me ยท a always (pager) ยท d always (direct)
|
|
103
103
|
|
|
104
104
|
EOT
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
105
|
+
1.times do
|
|
106
|
+
answer = chat.confirm?(
|
|
107
|
+
prompt: 'โ Allow โ
[y]es / โ๏ธ[n]o / ๐[i]nstruct / ๐[a]lways / ๐[d]irect? '
|
|
108
|
+
)&.to_s&.downcase
|
|
109
|
+
|
|
110
|
+
case answer
|
|
111
|
+
when 'y'
|
|
112
|
+
# proceed to execution
|
|
113
|
+
when 'a'
|
|
114
|
+
self.class.always_allowed[command] = :always
|
|
115
|
+
when 'd'
|
|
116
|
+
self.class.always_allowed[command] = :direct
|
|
117
|
+
when 'n'
|
|
118
|
+
raise OllamaChat::ToolFunctionArgumentError,
|
|
119
|
+
"Shell command cancelled by user: #{command}"
|
|
120
|
+
else
|
|
121
|
+
instr = chat.ask?(prompt: '๐ Instructions (C-c โจ cancel): ')
|
|
122
|
+
instr.nil? and redo
|
|
123
|
+
instr = instr&.strip
|
|
124
|
+
resolve = instr.full? || 'You **MUST** ask the user for instructions!'
|
|
125
|
+
raise OllamaChat::ToolFunctionArgumentError,
|
|
126
|
+
"User instruct: #{resolve} (command: #{command})"
|
|
127
|
+
end
|
|
124
128
|
end
|
|
125
129
|
end
|
|
126
130
|
end
|
data/lib/ollama_chat/version.rb
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# by hand; it is rewritten on every `rake version` invocation.
|
|
6
6
|
module OllamaChat
|
|
7
7
|
# The current version of the OllamaChat gem as a String.
|
|
8
|
-
VERSION = '0.0.
|
|
8
|
+
VERSION = '0.0.140'
|
|
9
9
|
VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
|
|
10
10
|
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
|
|
11
11
|
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
|
data/ollama_chat.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: ollama_chat 0.0.
|
|
2
|
+
# stub: ollama_chat 0.0.140 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "ollama_chat".freeze
|
|
6
|
-
s.version = "0.0.
|
|
6
|
+
s.version = "0.0.140".freeze
|
|
7
7
|
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
9
9
|
s.require_paths = ["lib".freeze]
|
|
@@ -232,6 +232,28 @@ describe OllamaChat::Invidious do
|
|
|
232
232
|
)
|
|
233
233
|
expect(result).not_to be_nil
|
|
234
234
|
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
context 'with an Invidious instance watch URL' do
|
|
238
|
+
let :tracks do
|
|
239
|
+
[
|
|
240
|
+
track(label: 'English', language_code: 'en',
|
|
241
|
+
base_url: 'https://www.youtube.com/api/timedtext' \
|
|
242
|
+
'?v=MmpZ5Db9JXi&lang=en'),
|
|
243
|
+
]
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
it 'extracts the video ID correctly' do
|
|
247
|
+
stub_player(tracks:)
|
|
248
|
+
expect(chat).to receive(:get_url)
|
|
249
|
+
.with(anything, remember: false)
|
|
250
|
+
.and_yield(StringIO.new(xml_content))
|
|
251
|
+
|
|
252
|
+
result = described_class.fetch_video_info(
|
|
253
|
+
'https://invidious.gate.ping.de/watch?v=MmpZ5Db9JXi', chat:
|
|
254
|
+
)
|
|
255
|
+
expect(result).not_to be_nil
|
|
256
|
+
end
|
|
235
257
|
end
|
|
236
258
|
end
|
|
237
259
|
end
|