rasti-ai 1.1.0 → 1.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 +4 -4
- data/.gitignore +2 -1
- data/README.md +151 -3
- data/lib/rasti/ai/mcp/client.rb +68 -0
- data/lib/rasti/ai/mcp/errors.rb +29 -0
- data/lib/rasti/ai/mcp/server.rb +156 -0
- data/lib/rasti/ai/open_ai/assistant.rb +25 -3
- data/lib/rasti/ai/open_ai/client.rb +43 -19
- data/lib/rasti/ai/tool.rb +23 -0
- data/lib/rasti/ai/tool_serializer.rb +112 -0
- data/lib/rasti/ai/version.rb +1 -1
- data/lib/rasti/ai.rb +4 -0
- data/log/.gitkeep +0 -0
- data/rasti-ai.gemspec +2 -0
- data/spec/mcp/client_spec.rb +256 -0
- data/spec/mcp/server_spec.rb +372 -0
- data/spec/minitest_helper.rb +4 -0
- data/spec/open_ai/assistant_spec.rb +9 -2
- data/spec/{open_ai/tool_serializer_spec.rb → tool_serializer_spec.rb} +21 -29
- metadata +42 -5
- data/lib/rasti/ai/open_ai/tool_serializer.rb +0 -111
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
module Rasti
|
|
2
|
-
module AI
|
|
3
|
-
module OpenAI
|
|
4
|
-
class ToolSerializer
|
|
5
|
-
class << self
|
|
6
|
-
|
|
7
|
-
def serialize(tool_class)
|
|
8
|
-
{
|
|
9
|
-
type: 'function',
|
|
10
|
-
function: serialize_function(tool_class)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
rescue => ex
|
|
14
|
-
raise Errors::ToolSerializationError.new(tool_class), cause: ex
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
def serialize_function(tool_class)
|
|
20
|
-
serialization = {
|
|
21
|
-
name: serialize_name(tool_class)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
serialization[:description] = normalize_description(tool_class.description) if tool_class.respond_to? :description
|
|
25
|
-
|
|
26
|
-
serialization[:parameters] = serialize_form(tool_class.form) if tool_class.respond_to? :form
|
|
27
|
-
|
|
28
|
-
serialization
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def serialize_name(tool_class)
|
|
32
|
-
Inflecto.underscore Inflecto.demodulize(tool_class.name)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def serialize_form(form_class)
|
|
36
|
-
serialized_attributes = form_class.attributes.each_with_object({}) do |attribute, hash|
|
|
37
|
-
hash[attribute.name] = serialize_attribute attribute
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
serialization = {
|
|
41
|
-
type: 'object',
|
|
42
|
-
properties: serialized_attributes
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
required_attributes = form_class.attributes.select { |a| a.option(:required) }
|
|
46
|
-
|
|
47
|
-
serialization[:required] = required_attributes.map(&:name) unless required_attributes.empty?
|
|
48
|
-
|
|
49
|
-
serialization
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def serialize_attribute(attribute)
|
|
53
|
-
serialization = {}
|
|
54
|
-
|
|
55
|
-
if attribute.option(:description)
|
|
56
|
-
serialization[:description] = normalize_description attribute.option(:description)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
serialization.merge! serialize_type(attribute.type)
|
|
60
|
-
|
|
61
|
-
serialization
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def serialize_type(type)
|
|
65
|
-
if type == Types::String
|
|
66
|
-
{type: 'string'}
|
|
67
|
-
|
|
68
|
-
elsif type == Types::Integer
|
|
69
|
-
{type: 'integer'}
|
|
70
|
-
|
|
71
|
-
elsif type == Types::Float
|
|
72
|
-
{type: 'number'}
|
|
73
|
-
|
|
74
|
-
elsif type == Types::Boolean
|
|
75
|
-
{type: 'boolean'}
|
|
76
|
-
|
|
77
|
-
elsif type.is_a? Types::Time
|
|
78
|
-
{
|
|
79
|
-
type: 'string',
|
|
80
|
-
format: 'date'
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
elsif type.is_a? Types::Enum
|
|
84
|
-
{
|
|
85
|
-
type: 'string',
|
|
86
|
-
enum: type.values
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
elsif type.is_a? Types::Array
|
|
90
|
-
{
|
|
91
|
-
type: 'array',
|
|
92
|
-
items: serialize_type(type.type)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
elsif type.is_a? Types::Model
|
|
96
|
-
serialize_form(type.model)
|
|
97
|
-
|
|
98
|
-
else
|
|
99
|
-
raise "Type not serializable #{type}"
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def normalize_description(description)
|
|
104
|
-
description.split("\n").map(&:strip).join(' ').strip
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|