ticuna 0.1.2 → 0.2.1

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: e437b292297ce9fb31d37e3ad84e7d314f673bd0dab8a511ae8df35b737f17cf
4
- data.tar.gz: 19fd66d1964c4655fc8e7cab7d8a461de5a90fc4e4dd31a0a28bc81c5864f4d9
3
+ metadata.gz: 91f1d0f3d86d36f73ee9127c48209b950a0a9e03d234ec0cf397015794797dda
4
+ data.tar.gz: 3db96fa9f07cc35f3baf5fe3af99da54d8e41e7ed954d3add56ee488f4a15de1
5
5
  SHA512:
6
- metadata.gz: 0ef912de56ab1e96259632020d089808548e9734663a0950eebbb918815c74429a4003b078db2183407bf0be1cdcf9dbfbadd332384c0f3958dbe7af0fe4c92c
7
- data.tar.gz: 8bbac24142de3cb268ac0b5968d2cbabca5adb4dd0357478758a7e3002f4628426a4dc10cda3af21889f4dafcc77a158c97ce31143ea9c55df046f9f98e24cb9
6
+ metadata.gz: e33ed0a919eda4ba474d3fad6993640b01ddf8b09c754cf5a8492673fbd914a4db3cd387db618ff85dc3a04afad70bc9e8d8de4925eb4ac47d43c78d44b392e7
7
+ data.tar.gz: aa329d1ad68be5fa446acbafd41eb3d6b99caf6a3d81f990950243439fbe5e359778ae375ff6f10d3133f9f919983c32d612f3183cdcb4cd34470663582b3b95
data/lib/ticuna/llm.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "ticuna/providers/openai"
4
4
  require "ticuna/config"
5
+ require "ticuna/response"
5
6
 
6
7
  module Ticuna
7
8
  class LLM
@@ -54,7 +55,8 @@ module Ticuna
54
55
  else
55
56
  [{ role: "user", content: message }]
56
57
  end
57
- @provider.ask_with_messages(messages, stream: stream, model: model, &block)
58
+
59
+ Ticuna::Response.new(@provider.ask_with_messages(messages, stream: stream, model: model, &block))
58
60
  end
59
61
 
60
62
  private
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Ticuna
6
+ class Response
7
+ attr_reader :data
8
+
9
+ def initialize(raw)
10
+ parsed =
11
+ case raw
12
+ when String
13
+ begin
14
+ JSON.parse(raw)
15
+ rescue JSON::ParserError
16
+ { content: raw }
17
+ end
18
+ when Hash
19
+ raw
20
+ else
21
+ raise ArgumentError, "Ticuna::Response only accepts Hash or String, received: #{raw.class}"
22
+ end
23
+
24
+ @data = deep_symbolize_keys(parsed)
25
+ end
26
+
27
+ def [](key)
28
+ @data[key.to_sym]
29
+ end
30
+
31
+ def to_h
32
+ @data
33
+ end
34
+
35
+ def to_s
36
+ @data.inspect
37
+ end
38
+
39
+ def method_missing(name, *args, &block)
40
+ value = @data[name]
41
+ return wrap(value) if @data.key?(name)
42
+ super
43
+ end
44
+
45
+ def respond_to_missing?(name, include_private = false)
46
+ @data.key?(name) || super
47
+ end
48
+
49
+ private
50
+
51
+ def deep_symbolize_keys(obj)
52
+ case obj
53
+ when Hash
54
+ obj.each_with_object({}) do |(k, v), h|
55
+ h[k.to_sym] = deep_symbolize_keys(v)
56
+ end
57
+ when Array
58
+ obj.map { |v| deep_symbolize_keys(v) }
59
+ else
60
+ obj
61
+ end
62
+ end
63
+
64
+ def wrap(value)
65
+ case value
66
+ when Hash
67
+ self.class.new(value)
68
+ when Array
69
+ value.map { |v| wrap(v) }
70
+ else
71
+ value
72
+ end
73
+ end
74
+ end
75
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ticuna
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ticuna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chirana
@@ -46,6 +46,7 @@ files:
46
46
  - lib/ticuna/config.rb
47
47
  - lib/ticuna/llm.rb
48
48
  - lib/ticuna/providers/openai.rb
49
+ - lib/ticuna/response.rb
49
50
  - lib/ticuna/tool.rb
50
51
  - lib/ticuna/version.rb
51
52
  - sig/ticuna.rbs