riffer 0.1.0 → 0.2.0
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/.standard.yml +1 -2
- data/CHANGELOG.md +7 -0
- data/Rakefile +3 -3
- data/lib/riffer/agent.rb +144 -0
- data/lib/riffer/config.rb +14 -6
- data/lib/riffer/core.rb +19 -11
- data/lib/riffer/{dependency_helper.rb → helpers/dependencies.rb} +1 -2
- data/lib/riffer/helpers/validations.rb +10 -0
- data/lib/riffer/messages/assistant.rb +13 -15
- data/lib/riffer/messages/base.rb +10 -12
- data/lib/riffer/messages/converter.rb +40 -0
- data/lib/riffer/messages/system.rb +3 -5
- data/lib/riffer/messages/tool.rb +12 -14
- data/lib/riffer/messages/user.rb +3 -5
- data/lib/riffer/providers/base.rb +72 -84
- data/lib/riffer/providers/open_ai.rb +70 -73
- data/lib/riffer/providers/test.rb +31 -33
- data/lib/riffer/providers.rb +0 -2
- data/lib/riffer/stream_events/base.rb +7 -9
- data/lib/riffer/stream_events/text_delta.rb +8 -10
- data/lib/riffer/stream_events/text_done.rb +8 -10
- data/lib/riffer/version.rb +1 -1
- data/lib/riffer.rb +29 -4
- metadata +17 -37
- data/.rspec +0 -3
- data/.rubocop_rspec.yml +0 -6
- data/Guardfile +0 -70
- data/lib/riffer/agents/base.rb +0 -95
- data/lib/riffer/agents.rb +0 -6
- data/lib/riffer/storage/base.rb +0 -21
- data/lib/riffer/storage.rb +0 -5
- data/lib/riffer/tools/base.rb +0 -31
- data/lib/riffer/tools.rb +0 -5
data/lib/riffer/agents/base.rb
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Riffer::Agents
|
|
4
|
-
class Base
|
|
5
|
-
class << self
|
|
6
|
-
def model(model_string = nil)
|
|
7
|
-
return @model if model_string.nil?
|
|
8
|
-
|
|
9
|
-
raise ArgumentError, "model must be a String" unless model_string.is_a?(String)
|
|
10
|
-
raise ArgumentError, "model cannot be empty" if model_string.strip.empty?
|
|
11
|
-
|
|
12
|
-
@model = model_string
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def instructions(instructions_text = nil)
|
|
16
|
-
return @instructions if instructions_text.nil?
|
|
17
|
-
|
|
18
|
-
raise ArgumentError, "instructions must be a String" unless instructions_text.is_a?(String)
|
|
19
|
-
raise ArgumentError, "instructions cannot be empty" if instructions_text.strip.empty?
|
|
20
|
-
|
|
21
|
-
@instructions = instructions_text
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
attr_reader :messages
|
|
26
|
-
|
|
27
|
-
def initialize
|
|
28
|
-
@messages = []
|
|
29
|
-
@model_string = self.class.model
|
|
30
|
-
@instructions_text = self.class.instructions
|
|
31
|
-
|
|
32
|
-
provider_name, model_name = @model_string.split("/", 2)
|
|
33
|
-
|
|
34
|
-
raise ArgumentError, "Invalid model string: #{@model_string}" unless [provider_name, model_name].all? { |part| part.is_a?(String) && !part.strip.empty? }
|
|
35
|
-
|
|
36
|
-
@provider_name = provider_name
|
|
37
|
-
@model_name = model_name
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def generate(prompt)
|
|
41
|
-
initialize_messages(prompt)
|
|
42
|
-
|
|
43
|
-
loop do
|
|
44
|
-
response = call_llm
|
|
45
|
-
@messages << response
|
|
46
|
-
|
|
47
|
-
break unless has_tool_calls?(response)
|
|
48
|
-
|
|
49
|
-
execute_tool_calls(response)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
extract_final_response
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
def initialize_messages(prompt)
|
|
58
|
-
@messages = [] # Reset messages for each generation call
|
|
59
|
-
@messages << Riffer::Messages::System.new(@instructions_text) if @instructions_text
|
|
60
|
-
@messages << Riffer::Messages::User.new(prompt)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def call_llm
|
|
64
|
-
provider_instance.generate_text(messages: @messages, model: @model_name)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def provider_instance
|
|
68
|
-
@provider_instance ||= Riffer::Providers::Base.find_provider(@provider_name).new
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def has_tool_calls?(response)
|
|
72
|
-
response.is_a?(Riffer::Messages::Assistant) && !response.tool_calls.empty?
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def execute_tool_calls(response)
|
|
76
|
-
response.tool_calls.each do |tool_call|
|
|
77
|
-
tool_result = execute_tool_call(tool_call)
|
|
78
|
-
@messages << Riffer::Messages::Tool.new(
|
|
79
|
-
tool_result,
|
|
80
|
-
tool_call_id: tool_call[:id],
|
|
81
|
-
name: tool_call[:name]
|
|
82
|
-
)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def execute_tool_call(tool_call)
|
|
87
|
-
"Tool execution not implemented yet"
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def extract_final_response
|
|
91
|
-
last_assistant_message = @messages.reverse.find { |msg| msg.is_a?(Riffer::Messages::Assistant) }
|
|
92
|
-
last_assistant_message&.content || ""
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
data/lib/riffer/agents.rb
DELETED
data/lib/riffer/storage/base.rb
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Riffer::Storage
|
|
4
|
-
class Base
|
|
5
|
-
def initialize(**options)
|
|
6
|
-
@options = options
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def save(key, value)
|
|
10
|
-
raise NotImplementedError, "Subclasses must implement #save"
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def load(key)
|
|
14
|
-
raise NotImplementedError, "Subclasses must implement #load"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def delete(key)
|
|
18
|
-
raise NotImplementedError, "Subclasses must implement #delete"
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
data/lib/riffer/storage.rb
DELETED
data/lib/riffer/tools/base.rb
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Riffer::Tools
|
|
4
|
-
class Base
|
|
5
|
-
attr_reader :name, :description
|
|
6
|
-
|
|
7
|
-
def initialize(name:, description:, **options)
|
|
8
|
-
@name = name
|
|
9
|
-
@description = description
|
|
10
|
-
@options = options
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def call(**params)
|
|
14
|
-
raise NotImplementedError, "Subclasses must implement #call"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def schema
|
|
18
|
-
{
|
|
19
|
-
name: @name,
|
|
20
|
-
description: @description,
|
|
21
|
-
parameters: parameters_schema
|
|
22
|
-
}
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
def parameters_schema
|
|
28
|
-
{}
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|