ask-core 0.1.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b902c297f6ee3be92f51640bb345262d0aef35d7a258c2213d67b96f42e3c9b5
4
- data.tar.gz: e199a4b003cde310f91f8e42a7f5886c0aa51f5f4801c928f12b27ccbd8d99a9
3
+ metadata.gz: e946277b56e6e4ace450e2da7b1c36f92510b2db77544586773d88ca296c573b
4
+ data.tar.gz: 4422ae36f021a460470437097d06a84c680b76de7c8acbbbc942b477240f598b
5
5
  SHA512:
6
- metadata.gz: 7157603762f1f9c6f7ff2db5a7db7deb81ba8e98866dd44bd04977ba59de9b6cbfe58d6c25b8c391b08b05846585f0f6a2dd90c1162ff151240c4ef3244a39eb
7
- data.tar.gz: 1531d808f7c5f5390a7ff059cfc4b241f3a4a6a8ac3ae2dd9ed075410b7ff6f8791d876b484828f8d8aeeb1567c11b81a5121020f8e8b73e9c722d7f3de18d21
6
+ metadata.gz: 8776604d752f326fbb2ddb063694e364a63f1a2900073b9782eef11722837f161fdbc7ea57fe5902521b52973c6c180429c1cc92b833a475fb8591ab76572f3d
7
+ data.tar.gz: 7efbedddd31c08a2dac6c99a432631950f50cad067c71965f0b8ff72d13666ff069d8902aeba0f4f4aefbfbff1e05c8eeda2c53bdb6e1479947a11353a9df892
@@ -54,14 +54,29 @@ module Ask
54
54
  def tool? = @role == :tool
55
55
 
56
56
  # Convert to a hash suitable for provider wire format serialization.
57
- # Omits nil-valued keys.
57
+ # Omits nil-valued keys. Tool calls are converted from internal Hash format
58
+ # ({id => object with .id, .name, .arguments}) to the provider API Array format
59
+ # ([{id:, type:, function: {name:, arguments:}}]).
58
60
  # @return [Hash]
59
61
  def to_h
60
62
  base = { role: @role }
61
63
  base[:content] = @content if @content
62
64
  base[:name] = @name if @name
63
65
  base[:tool_call_id] = @tool_call_id if @tool_call_id
64
- base[:tool_calls] = @tool_calls if @tool_calls
66
+
67
+ if @tool_calls
68
+ base[:tool_calls] = @tool_calls.is_a?(Array) ? @tool_calls : @tool_calls.map do |id, tc|
69
+ {
70
+ id: tc.respond_to?(:id) ? tc.id : id,
71
+ type: "function",
72
+ function: {
73
+ name: tc.respond_to?(:name) ? tc.name : tc.to_s,
74
+ arguments: tc.respond_to?(:arguments) ? tc.arguments : "{}"
75
+ }
76
+ }
77
+ end
78
+ end
79
+
65
80
  base
66
81
  end
67
82
 
data/lib/ask/models.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
+ require "timeout"
4
5
  require "net/http"
5
6
  require "time"
6
7
 
@@ -421,7 +422,7 @@ module Ask
421
422
  http.read_timeout = timeout
422
423
 
423
424
  request = Net::HTTP::Get.new(uri)
424
- response = http.request(request)
425
+ response = Timeout.timeout(timeout) { http.request(request) }
425
426
 
426
427
  unless response.is_a?(Net::HTTPOK)
427
428
  warn "Failed to fetch models.dev: HTTP #{response.code}. Keeping existing models."
data/lib/ask/stream.rb CHANGED
@@ -19,12 +19,16 @@ module Ask
19
19
  # @return [Hash, nil] raw response data from the provider
20
20
  attr_reader :raw
21
21
 
22
- def initialize(content: nil, tool_calls: nil, finish_reason: nil, usage: nil, raw: nil)
22
+ # @return [String, nil] reasoning/thinking text from the model (e.g. chain-of-thought)
23
+ attr_reader :thinking
24
+
25
+ def initialize(content: nil, tool_calls: nil, finish_reason: nil, usage: nil, raw: nil, thinking: nil)
23
26
  @content = content
24
27
  @tool_calls = tool_calls
25
28
  @finish_reason = finish_reason
26
29
  @usage = usage
27
30
  @raw = raw
31
+ @thinking = thinking
28
32
  end
29
33
 
30
34
  # @return [Boolean] true if this is the final chunk in a stream
@@ -33,6 +37,9 @@ module Ask
33
37
  # @return [Boolean] true if this chunk contains tool calls
34
38
  def tool_call? = @tool_calls&.any? == true
35
39
 
40
+ # @return [Boolean] true if this chunk contains thinking/reasoning content
41
+ def thinking? = @thinking.to_s.length > 0
42
+
36
43
  # @return [String] text content as a plain string
37
44
  def to_s
38
45
  @content.to_s
data/lib/ask/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ask
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto